How To Use "Find" Command
Search a File Using "Find" Command
Video Tutorial For Find Command
Find File By Name
Find a file by name, "file1" is case sensitive:find -name "file1"
Find a file by name but ignore the case:
find -iname "File1"
Find a file not having a particular pattern.
find -not -name "do_not_search_this"
or
find \! -name "do_not_search_this"
Find a file by Type:
A file can have the following type:- f - regular file
- d - directory
- I - symbolic link
- c - character devices
- b - block devices
Find all files with ".conf" at the end:
find / -type f -name "*.conf"
Find all character devices on system:
find / -type c
Find all block devices on system:
find / -type d
Find And Filter Files By Time & Size
Filter By Size
Available size units:- c - bytes
- k - kilobytes
- M - Megabytes
- G - Gigabytes
- b - 512-byte block
Find files which are exactly of size 1G:
find / -size 1G
Find files which are less than 1G in size:
find / -size -1G
Find files which are more than 1G in size:
find / -size +1G
Filter By Time
Available Time:- Access Time - Last time a file was read or written to
- Modification Time - Last time when the content of file was modified
- Change Time - Last time when the file's inode metadata was changed
Find file having modification time of 1 day ago:
find / -mtime 1
Find files that were accessed less then a day ago:
find / -atime -1
Find files whose meta information was changed more than 1 days ago:
find / -cmin +1
Find files that were modified in the last 5 minutes:
find / -mmin -5
Find files that are newer than a file:
find / -newer samplefile
Find Files By Owner & Permissions
Find files owned by "ajeet" user:find / -user ajeet
Find files owned by "ajeet" group:
find / -group ajeet
Find files having specific permission:
find / -perm 400
Find files having at least specified permission:
find / -perm -400
Find Files By Depth
Find number of files with a name:find -name "*.conf" | wc -l
Find files upto two level (current directory and level1 directory):
find -maxdepth 2 -name "*.conf"
Find files only upto a specific directory level:
find -mindepth 5 -name "*.conf"
Find files between specific range of directory levels:
find -mindepth 2 -maxdepth 3 -name "*.conf"
Executing Commands On The Results of Find Command
Syntax:find find_parameters -exec command_parameters {} \;
Find directories with name & specific permission and give them 700 permission:
find . -type d -perm 755 -exec chmod 700 {} \;
0 comments:
Post a Comment