Skip to content

Instantly share code, notes, and snippets.

@ganapathichidambaram
Last active February 10, 2021 12:41
Show Gist options
  • Save ganapathichidambaram/46477f92601687ae82db6b0c0be9be6f to your computer and use it in GitHub Desktop.
Save ganapathichidambaram/46477f92601687ae82db6b0c0be9be6f to your computer and use it in GitHub Desktop.
Some action with Find Utility in Linux

Some Commands using Find utility - Linux

  • To Find the alphanumeric File with special extension
find . -type f -regex ".*[0-9].*\.\(xls\|csv\|php\)"
  • To Find alplahnumeric file under entire folder by excluding some folder
find . -type f -regex ".*[0-9].*\.\(xls\|csv\|php\)" -not -path "./database/*"
  • To find alphanumeric file with special extension by skipping more than one folder
find . -type f -regex ".*[0-9].*\.\(xls\|csv\|php\)" -not -path "./database/*" -not -path "./public/DB/*" 
  • To find alphanumeric file with special extension by skipping folder and file with pattern
find . -type f -regex ".*[0-9].*\.\(xls\|csv\|php\)" -not -path "./database/*" -not -path "./app/Console/Commands/bulkServerUpload_[0-9].php"
  • To Find alphanumeric file with special extension by skipping some files and folder and delete everything with matched pattern.
find . -type f -regex ".*[0-9].*\.\(xls\|csv\|php\|sh\|txt\|js\)" -not -path "./vendor/*" -not -path "./app/lib/*" -not -path "./database/*" -not -path "./public/DB/*" -not -path "./app/Console/Commands/bulkServerUpload_[0-9].php" -not -path "./resources/views/errors/*" -delete
  • To find files starts or end with numeric by skipping some folder as to exclude and delete those files
find . -type f -regex ".*[0-9].*\.\(xls\|csv\|php\|sh\|txt\|js\)" -not -path "./vendor/*" -not -path "./app/lib/*" -not -path "./database/*" -not -path "./public/DB/*" -not -path "./app/Console/Commands/bulkServerUpload_[0-9].php" -not -path "*bulkupload-[0-9].sh" -not -path "./resources/views/errors/*" -not -path "./storage/*" -not -path "./*DB*" -not -path "./public/assets/components/*" -not -path "./public/datatables/*" -not -path "./public/ndlib/*" -delete
  • To Find some Dump file and delete
find . -type f -regex ".*\.\(zip\|tar\.gz\|sql\)" -not -path "./public/*DB/*" -delete
  • To Find all the log file and empty the content
find . -type f -name "*.\(txt\|log\)" -exec tee {} \; </dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment