Created
September 23, 2017 18:50
-
-
Save vinsim24/7c395b913cf33cdd61081abd4c8e7046 to your computer and use it in GitHub Desktop.
Bash Find Examples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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