Shell

File management

cp -R path/source path/target

Copy directories.

find . -name '.DS_Store' -type f -delete

Delete all .DS_Store files recursively.

File management, batching

https://stackoverflow.com/a/24265787

find

Search for files in a directory.

find <dir> <pattern> <action>

For example:

find . -name \*.jpg -type f -print0
find . \( -name \*.jpg -o -name \*.jpeg \) -print0
find . -name "*.jpg" -delete

xargs

Execute commands from standard input. Use | to pipe commands to xargs.

find . -name \*.jpg -print0 | xargs -I{} -0 cp -v -f {} /home/dir

find -exec vs find | xargs

Practical examples

Find all video files in a tree

find . \( -name \*.webm -o -name \*.mkv -o -name \*.flv -o -name \*.vob -o -name \*.ogv -o -name \*.avi -o -name \*.mov -o -name \*.wmv -o -name \*.asf -o -name \*.mp4 -o -name \*.m4p -o -name \*.m4v -o -name \*.mpeg -o -name \*.mpv -o -name \*.mp2 -o -name \*.3gp -o -name \*.swf \) -print0 | xargs -I{} -0 cp -v -f {} /home/dir