Sunteți pe pagina 1din 5

thegeekscope.

com

http://w w w .thegeekscope.com/find-files-in-linux-using-findcommand/

Find Files in Linux using Find Command


In Linux, find Command is used to search for specific files and folders. The beauty of the linux find command lies in its ability to perform complex searches. Find command provides plenty of options to specify size, modification date, type, owner, permission while performing a search operation. This article describes some of the most useful options availble with the linux find command with the help of examples.

Find Files Based on Filename Pattern


Syntax: find <SEARCH_PATH> -type [f|d] -name "<PATTERN>" type f indicates that search for files type d indicates that search for directories

Example: Search for files in the /root folder which contains the string monitor in the filename # find /root -type f -name "*monitor*" /root/monitor_script.sh /root/monitor_script.sh.v2 /root/monitor_script.sh.v1 Example: Search for folders in the /root folder which contains the string monitor in the foldername # find /root -type d -name "*monitor*" /root/test/test_monitor123 Example: Search for files/folders in the /root folder which contains the string monitor in the name # find /root -name "*monitor*" /root/test/test_monitor123 /root/monitor_script.sh /root/monitor_script.sh.v2 /root/monitor_script.sh.v1
www.thegeekscope.com

The Geek Scope

Find Files Based on Modification Time in Days


Syntax: find <SEARCH_PATH> -mtime <x> Integer <x> indicates days <x> along with + sign indicates, modified before x days <x> along with - sign indicates, modified within last x days <x> with no sign indicates, modified exactly x days ago Example: Search /etc folder for files/folders modified exactly 7 days ago # find /etc -mtime 7 Example: Search /etc folder for files/folders modified before 7 days # find /etc -mtime +7

The Geek Scope

Example: Search /etc folder for files/folders modified in last 7 days # find /etc -mtime -7 You can use atime in place of mtime to find files and folders based on last access time in days. Example: Search /etc folder for files/folders accessed in last 7 days # find /etc -atime -7

Find Files Based on Modification Time in Mins


Syntax: find <SEARCH_PATH> -mmin <x> Integer <x> indicates minutes
www.thegeekscope.com

<x> along with + sign indicates, modified before x mins <x> along with - sign indicates, modified within last x mins <x> with no sign indicates, modified exactly x mins ago Example: Search /home folder for files/folders modified exactly 60 minutes ago # find /home -mmin 60 Example: Search /home folder for files/folders modified before 60 minutes # find /home -mmin +60 Example: Search /home folder for files/folders modified in last 60 minutes # find /home -mmin -60 You can use amin in place of mmin to find files and folders based on last access time in mins. Example: Search /etc folder for files/folders accessed in last 60 mins # find /etc -amin -60

The Geek Scope

Find Files Based on Size


Syntax: find <SEARCH_PATH> -size <x> Integer <x> indicates size in bytes/kilobytes/megabytes/gigabytes <x> along with + sign indicates size larger than x <x> along with - sign indicates size smaller than x <x> with no sign indicates, size exactly equal to x Example: Search /etc folder for files/folders having size exactly equal to 20015 bytes

www.thegeekscope.com

# find /etc -size 20015c Example: Search /root folder for files/folders having size greater than 2 megabytes # find /etc -size +2M Example: Search /home folder for files/folders having size less than 1 kilobytes # find /etc -size -1k

Find Files Based on Permissions


Syntax: find <SEARCH_PATH> -perm <permission> Example: Search /etc folder for files/folders with permission 755 (read,write,execute for owner and read,execute for group owner and others)

The Geek Scope

# find /etc -type f -perm 664

Find Empty files and Folders


Syntax: find -empty Example: Find all empty files/folders available in a system # find / -empty

Find Files Owned by a Specific User


Syntax: find <SEARCH_PATH> -user <username>
www.thegeekscope.com

Example: Find all files/folders owned by user kam # find / -user kam

Find Files Owned by a Specific Group


Syntax: find <SEARCH_PATH> -group <groupname> Example: Find all files/folders owned by group account projectx # find / -group projectx

Use -and and -or qualifier to join search patterns


Example: Search /root folder for files/folders modified in last 7 days and having size less than 200kB # find /etc -mtime -7 -and -size -200k

The Geek Scope

Example: Search /home folder for files/folders accessed in last 2 hours or having size greater than 10MB # find /etc -amin -120 -or -size +10M Tagged as: Find Command, Find Files, Find files in LInux, Find files in Unix, Linux Find Command, Search Files, Using Find Command

www.thegeekscope.com

S-ar putea să vă placă și