'find' is a very important command in linux. The following are a few usage examples:
Find in the current directory
find . -maxdepth 1 -mindepth 1 -type f -name "*.java "
Find and out files with fullpath
find $PWD/dir -name "*.sh"
- find /tmp -name core -type f -print | xargs /bin/rm -f
Find files named core in or below the directory /tmp and delete them.
Note that this will work incorrectly if there are any filenames containing newlines or spaces.
- find /tmp -name core -type f -print0 | xargs -0 /bin/rm -f
Find files named core in or below the directory /tmp and delete them,
processing filenames in such a way that file or directory names containing spaces or newlines are correctly handled.|
Tip: You just need to move .mp3 files and not directory, use:
# find / -iname "*.mp3" -type f -exec /bin/mv {} /mnt/mp3 \;
Find all directories having name mp3 and move:
# find / -iname "*.mp3" -type d -exec /bin/mv {} /mnt/mp3 \;
For performance you may need to consider using xargs command:
find / -iname "*.mp3" -type f | xargs -I '{}' mv {} /mnt/mp3