In this post, we will see about find command in linux.
Find is an important and one of most widely used command in Unix and Linux operating systems. It is used to search and locate list of files and directories based on conditions you specify for files that match the arguments.
Find command lets you search used in variety of conditions like you can search files by permissions, users, groups, file type, date, size and other possible criteria. Searching by Find command is recursive in a sense that it will search subdirectories as well.
all these options following the Find command are optional, let’s see how
If you type $ find and press enter it will display the pathnames of all files in the current directory and all subdirectories. Same will happen if you type $ find . and press enter.
If you want to search for file named arpit in current directory, use this
You can also do this by using
find command by default is case sensitive, if you want to search without case sensitivity
this will search for files that match arpit, ARPIT, Arpit and all other combination in current directory.
Searching for Files and Directories Only
You can also search files or directories only using -type option. To find files with name arpit use
To find directories with name arpit use
This will search for only files with name arpit in current and sub-directories removing case sensitivity filter.
You can also use wild cards with find command. For instance
this will search current and sub-directories for files with .txt extension.
Search based on File Permission
With find command you can also search files based on specific permission. For instance
This will display all files with permission 777 in your current directory.
Search for files that are modified at some specific time/day
If you want to search for files that are modified in last one day using mtime
If you want to search for files that are modified in last one min
if you want to search for files that are modified more then 2 and less than 5 min
Search based on User
If you want to search for files of user arpit in the current and sub-directories, use this
Search based on File size
To find all files of size 10MB , use.
You can also find and delete 50MB files and delete them in one single command
To learn more about Find command, type $ man find on your Linux terminal
That’s all about Find command in linux.
Join Our News Letter – Stay Updated
Subscribe to Awesome Java Content.