Author : Piyush Gupta
find is a Linux command line tool to search files and directories in the file system. The find command works much fast than any other command. It provides a large number of options for more specific search. It also supports wildcard characters.
Every Linux user must read this article and understand the uses of the find command. This command is very useful in your daily tasks. This article will help you to understand find command and its uses in Linux system.
Syntax: To search a file or directory under specified filesystem.
Explanation:
find => command line tool
/search/in/dir => Directory name where to start search
-name => Switch to specify filename
filename => File or Directory name
Use -name option to find a file with name “hello.txt” under root (/) file system.
And this command will search all files in system which are less than 10MB.
-size: switch are used for searching file on bais of there size. Plus ( + ) is used to greater than size and minus ( – ) sign is used for less than size.
like: +100MB, -50KB, +1GB etc…
Search all files which modification time is more than 30 days.
Search all files which modification time is less than 30 days.
Search all .txt files own by user bob.
Search all .txt files with group ownership of root.
You can combine both to more specific search to files with owner bob and group ownership of the root.
If you want check inode number of a file using below command. The first field of output is an inode number
Other file type options are as below:
find is a Linux command line tool to search files and directories in the file system. The find command works much fast than any other command. It provides a large number of options for more specific search. It also supports wildcard characters.
Every Linux user must read this article and understand the uses of the find command. This command is very useful in your daily tasks. This article will help you to understand find command and its uses in Linux system.
Syntax: To search a file or directory under specified filesystem.
find => command line tool
/search/in/dir => Directory name where to start search
-name => Switch to specify filename
filename => File or Directory name
Find files by Name
Use -name option to find a file with name “hello.txt” under root (/) file system.
Find files by Type
Search for the file (not directory) named “backup.zip” in entire file system. Use -type f to specify search for files and ignore direcories.Search directory only
Search for the directory (not file) named “backup” in entire file system. Use -type d to specify search for directory and ignore files.Find files by Size
Search all files systemwide, which are greater than or equal 10MB with find commandlike: +100MB, -50KB, +1GB etc…
Find files by Time
Search all files which modification time is more than 30 days.
Find files by User/Group
Find command also provides search based on user and group ownership. like:Search all .txt files own by user bob.
Find files by Permissions
Search all files which are having 777 permissions under /var/www directory tree. This can be helpful for the security audit.Find files by Inode Number
This command is used to search files on basis of their inode number. -inum is used for this search.Find Empty files
This command is very useful to search empty files and directories. It is useful to the cleanup system with empty files and directories.Find files by File Types
Search all block special files available under / filesystem.b – block (buffered) special
c – character (unbuffered) special
d – directory
p – named pipe (FIFO)
f – regular file
s – socket
l – symbolic link; this is never true if the -L option or the -follow option is in effect unless the symbolic link is broken. If you want to search for symbolic links when -L is in effect, use -xtype.
No comments:
Post a Comment