Skip to content

Instantly share code, notes, and snippets.

@hendryfoe
Created February 12, 2023 06:23
Show Gist options
  • Save hendryfoe/7637b09ed93f9265e789c4953c3b4762 to your computer and use it in GitHub Desktop.
Save hendryfoe/7637b09ed93f9265e789c4953c3b4762 to your computer and use it in GitHub Desktop.
"find" command in linux
# https://www.freecodecamp.org/news/how-to-search-files-in-the-linux-terminal/
find -name <file_name>
# find file by "case-insensitive"
find -iname <file_name>
# find file by "regex / pattern"
find /path/to/search -name "*.txt"
# find file by "directory"
find /path/to/search -type d
# find file by "size of file"
# K represents "KB"
# M represents "MB"
# G represents "GB"
# b represents "bytes"
# c represents "blocks"
find /path/to/search -size <size_of_the_file>
find /path/to/search -size +50M -size -100M
# find file by "time modified"
find /path/to/search -mtime <-number_of_days_ago>
find /path/to/search -mtime +7
# execute command on filtered file
find /path/to/search -name -exec <COMMAND_HERE_1> {} <COMMAND_HERE_2> \;
find ./5minslearn -name "*.zip" -exec mv {} ./5minslearn/zip \;
# execute command on filtered file "with prompt / confirmation"
# add "-ok"
find /path/to/search -name "*.txt" -ok mv {} /path/to/destination \;
# find and remove files
find . -name "*.<extension>" -delete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment