Linux and shell scripting – practical examples of find command

Here are some of the find command examples which I use very often used on Linux in a variety of shell scripts, mostly to delete some old logs, to detect files with low permissions, archiving and copying files changed in a certain level of time and similar actions

Search for a file „httpd.conf“ everywhere in computer
find – command for searching
/ – to search where? (in this case on root of all folders).
type – file type (f – regular file, d – folder, l – symlink)
name – word or part of word (use wildcard) which you looking for
2> /dev/null – all errors (2>) generated while search (mostly because you don’t have permissions on files) send to black hole (/dev/null)


Find me on /tmp but not on his subfolders, all files with word „fraza“ newer than 25.11.2015 17:00 – and everything what you find – move to /home/draza
maxdepth – in how much levels in folder (subfolders) to search (1 mean current folder only)
newermt – file is (newer) and….changed (m) in period from (t)
exec – execute command over find result {}


Find me on folder /tmp and all subfolders all files with .log extension which begin with „program“ – and it is not case sensitive, where there was not any modification in more than 3 days – and everything what you find – delete.
iname – same as name but not case sensitive
mtime – modification time (+3 more than 3 days, -3 less than 3 days, 3 – exactly 3 days)


Find me all files in /tmp accessed (by vi, grep, cat….) in the last 10 days
atime – access time (-10 mean less than 10 days)


Archive me all files changed today from /tmp
ctime – file is changed in X*24 hours (chmod, chown… included)
daystart – but from today date


Find me all files in /tmp who are not


Find me all files in /tmp which are newer than file „draza.txt“ in home directory


Find me all files in current folder who have full permission for all (chmod 777)


Find me all file under /tmp with 777 permissions, and change them permission to 644


Find me all files in /tmp which owner is draza


Find me all files in /tmp who are modified in last 2 hours
mmin – modification time in…… -120 in last 120 minutes, +120 before 120 minutes


Give me all files from /tmp who are bigger than 5GB and smaller than 10GB
Možda ti može biti interesantno ↓↓↓