Command-line Knowledge Base

find

Search file names for a specific string
find /path/to/folder/ -type f -iname '*string*'
Recursively search file contents for a specific string
find /path/to/folder/ -exec grep 'string' '{}' /dev/null \; -print
find /path/to/folder/ -exec grep -H 'string' '{}' \; -print
Recursively search content of a specific filetype for a specific string
find /path/to/folder/ -name '*fileType' -type f -exec grep 'string' '{}' /dev/null \; -print
find /path/to/folder/ -name '*fileType' -type f -exec grep -H 'string' '{}' \; -print
Recursively search filenames (including symbolic links) for a specific string
find -L . -print |grep -i string
Recursively search filenames of a specific filetype for a specific string
sudo find . -print | grep -i '.*[.]fileType'
Delete files containing specific string in name
find . -maxdepth 1 -iname "*mp3" -type f -delete
List most recently modified mp3s, including sub-folders
find $1 -type f -name '*mp3' -exec stat --format '%Y :%y %n' {} \; | sort -n | cut -d: -f4- | cut -d " " -f3-
List a folder's symbolic links
find . -type l -ls
List files owned by a specific user
find . -user username -ls
Generate an mp3 playlist
find -type f -iname \*.mp3 > playlist.txt
List detailed file info for file(s) using a search string 1
find -type f -ls |grep -i "$search"
Display the 5 largest file in the current directory and its subdirectory
find . -type f -exec ls -s {} \; | sort -n -r | head -5
NULL