Created
January 19, 2015 20:36
-
-
Save gartenfeld/4f7c4995faa3ff29ce99 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
find /dir/ -iname "*.mp3" -print | |
# /dir/ - Search directory | |
# -iname - File name search pattern (case insensitive) | |
# -print - Display name of files on screen | |
find / -iname "*.mp3" -exec mv {} /new_dir/mp3 \; | |
# -exec mv {} /mnt/mp3 \; | |
# Execute mv command. | |
# The string '{}' is replaced by the file name. | |
# \; ends /bin/mv command. | |
# To just move .mp3 files and not directories, 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 | |
# To moves all .mp3 files with special characters in its name such as white spaces try: | |
find / -iname "*.mp3" -type f -print0 | xargs -0 -I '{}' /bin/mv "{}" /mnt/mp3/ | |
# Above commands will not maintain sub-directory structure. Try replacing mv with rsync to use the same directory structure on the target directory with the -R option: | |
find / -iname "*.mp3" -type f -print0 | xargs -0 -I '{}' /usr/bin/rsync -avR "{}" /mnt/mp3/ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment