I wanted to move all the files having certain patterns of the current directory to a folder.
Example- I wanted to move all the files starting with nz to foobar directory. I tried it using mv but didn't work out well.
I wanted to move all the files having certain patterns of the current directory to a folder.
Example- I wanted to move all the files starting with nz to foobar directory. I tried it using mv but didn't work out well.
This will do it, though if you have any directories beginning with nz it will move those too.
for files in nz*
do
mv $files foobar
done
Edit: As shown above this totally over the top. However, for more complex pattern matches you might do something like:
for files in `ls | grep [regexp]`
do
mv $files foobar
done
Try to use "mmv", which is installed on most Linux distros.
find . | grep "your_pattern" | xargs mv destination_directory
Does the following: