Skip to content

Instantly share code, notes, and snippets.

@vinsim24
Created September 23, 2017 18:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vinsim24/7c395b913cf33cdd61081abd4c8e7046 to your computer and use it in GitHub Desktop.
Save vinsim24/7c395b913cf33cdd61081abd4c8e7046 to your computer and use it in GitHub Desktop.
Bash Find Examples
#!/bin/bash
#Find all link files
ls -ltr `find . -maxdepth 1 -type l -print`
#Find and remove all files whose modified time is greater than 30 days
find . -type f -mtime +30 -exec rm {} \;
#Find particular word across files in same directory
find . -type f | xargs grep -l "searched_word"
#Files with zero size
find . -size 0 -print > zerosize.txt
#Find files before a particular date:
touch -t 201305010000 timestamp
find . -type f ! -newer timestamp -exec cp -r {} ../tmp_vin \;
#Copy only folder structure
cd source_dir
find . -type d -depth | cpio -dumpl destination_dir
cd destination/dir
find /source/dir -type d -printf "%P\n" | xargs mkdir -p
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment