Hi all,
I have a bunch of files that are named like 12543, 467249877, etc all over some directories.These files are named only with numbers, they dont have any letters or special characters in their file names. Could you please help me out and give me some command/script to remove only those files?
I really appreciate it.
Thanks,
Praveen
Praveen,
See if this works for you:
for mFName in `ls -1 [0-9]*`
do
mNoNbrs=`echo $mFName | sed 's/[0-9]//g'`
if [ "${mNoNbrs}" = "" ]; then
echo "ONLY NUMBERS"
fi
done
With ksh and bash (option extglob set) you can list and remove the files with the command :
$ ls +([0-9])
$ rm +([0-9])
Jean-Pierre.
ls [0-9]* | awk '/^[0-9]+$/{print}' |xargs rm
guys,
thats really awesome..I got so many responses so fast.But I need to do this recursively in directories and subdirectories.. so i was hoping to use a find command..like find . -name blah* . Please let me know if you have anything handy to find/remove these files. For example, i have files like ~/12345 and ~/sub/3256434, ~/sub2/sun3/98345, etc.
Praveen
Praveen,
As you can see, there are several ways to skin a cat.
Using my solution:
for mFName in `find . -type f -name '[0-9]*'`
do
mNoNbrs=`basename $mFName | sed 's/[0-9]//g'`
if [ "${mNoNbrs}" = "" ]; then
echo "ONLY NUMBERS"
fi
done
That was really fast! You rock man!
Thanks,
Praveen