Date created: 08/30/20 19:34:34. Last modified: 08/30/20 19:35:46

'find' - Notes

Find by size:

# 70MBs and larger
find . -type f -size +70M

du -h -d 1 | sort -hr

 

Find and delete:

# Delete Mac OS .DS_Store and ._.DS_Store files

# Using "\;" calls rm for every file found
find . -name "*.DS_Store" -exec rm {} \;

# Using "+" calls rm once with all file names as arguments to speed up the process
find . -name "*.DS_Store" -exec rm {} +

# If files have spaces in the name/path, find can delete them using the -delete option
find . -name "*.DS_Store" -delet

 

Piping:

# When working with external commands find output can be piped to xargs verbatim...
find . -name "*.DS_Store" | xargs ...

# Or use -print to print each file/path separated by a new line or -print0 to print each file/path separated by a space character
find . -name "*.DS_Store" -print0 | xargs ...

 

Escaping:

# Find files with a backslash in the name and use the -exec argument to launch a bash shell to rename the files
find . -name "*\\\*" -exec bash -c 'x="{}"; y="$(sed "s/\\\/-/g" <<< "$x")" && mv "$x" "$y" ' \;

 


Previous page: 'dig' - Notes
Next page: HTTP Servers