Find is a fundamental and extremely
powerful tool for working with the files on your Linux system. It can be used
on its own to locate files, or in conjunction with other programs to perform
operations on those files
The Find Command:
find [path] [expression]
Recursively
finds files in path that match expression
If
no arguments are supplied it find all files in the current directory
find . - For find in current directory
-name pattern - Find file and directories that match patterns
-iname pattern - Like - name but ignore case(lower or upper)
-ls - Performs an ls on each of the found items
-mtime days(like-1, 2, 3) - Find files that are days old
-size num(like- +iM, -1M) - Find file that are of size number
-newer file - Find file that are newer than file
-exec command {} \; - Run command against all the files that are found
Lets see Find command in action:
find . -name file.txt
Find files
named file.txt
find . -iname file.txt
Find files
named file.txt ignoring case
find . -iname file.txt -ls
Performs an
ls on each of the found items.
find . -mtime 4
Find files 4
days old
find . -mtime +4 -mtime -9
Find files
that are older than 4 days but not older than 9 days. i.e. - 5, 6, 7, 8 days
find /root/Desktop/ -size +1M
Find files
larger than 1 MB
find . -newer cat.txt
Find files
that are newly than cat.txt
find /root/Desktop/ -exec file
{} \;
Execute file
command against all the files that are found
Find Files or Directory in Linux
Reviewed by vijay pratap singh
on
March 28, 2017
Rating:
No comments: