Linux Command Find Useful Examples

December 24, 2022 Reading time: 2

Find all files with 777 permissions:

$ find . -type f -perm 777 -print

Find all files that are older than 14 days and ls:

$ find . -type f -mtime +14 -exec ls -l {} \;

Find all your writable files and list them:

$ find . -perm -0777 -type f -ls

Find files and change their permission to writeable:

$ find . -name “NAME*” -exec chmod 666 {} \;

Find files created in the past 7 days:

$ find . -mtime -7 -type f

Find files modified in the past 7 days:

$ find . -mtime -7 -type f

Find files owned by a particular user:

$ find . -user nfcg

Find files that were modified more than 7 days ago and tar them into an archive (with a date in the name):

$ find . -type f -mtime +7 | xargs tar -cvf `date ‘+%d%m%Y’_archive.tar`

Find files that were modified less than 7 days ago and tar them into an archive (with a date in the name):

$ find . -type f -mtime -7 | xargs tar -cvf `date ‘+%d%m%Y’_archive.tar`

Find how many files are in a path:

$ find . -type f -exec basename {} \; | wc -l

Find the top 50 Biggest Files:

$ find / -type f -not -path “/proc/*” -not -path “/dev/*” -not -path “/sys/*” -not -path “/home/rack/*” -printf “%s %h/%f\n” | sort -rn -k1 | head -n 50 | awk ‘{print $1/1048576 “MB” ” ” $2}’

About

Welcome to my blog. I'm a technology enthusiast. I will use this space to present my projects and post simple tips on computer technology and programming.

Tags