I have many files in a directory that some of them starts with special characters, spaces , number etc. Now I want to find the files that starts with numbers and put them in a directory. Then find the files that starts with spaces and put them in a different directory, and then the same procedure for files start with capitals.
#!/bin/sh
for nfile in *.png ; do
if [ $nfile=^[0-9]*] ; then
mkdir NUMBERS
cp `echo $nfile` NUMBERS
fi
done
CodePudding user response:
You don't need a loop. Do simply:
mkdir NUMBERS SPACES UPPER
cp [[:digit:]]*.png NUMBERS/
cp [[:space:]]*.png SPACES/
cp [[:upper:]]*.png UPPER/
etc.
CodePudding user response:
Like this:
for space
find . -maxdepth 1 -name ' *' -exec cp {} space_dir \;
for numbers
find . -maxdepth 1 -name '[0-9]*' -exec cp {} number_dir \;
etc...