Linux Find Command With Examples

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/linux-find-command-with-examples/
PINTEREST
PINTEREST
INSTAGRAM

Linux provides a lot of important tools to make administrator’s life easy. find command is one of the most important command in Linux world. Find command provides search according to file owner, file size, file change date, file name etc. Now we can start with simple examples and then go to the more complex examples.

Syntax

Find command syntax is like below. first the path we want to search is given and then different options are provided.

Find Files Using Name

The easy and fast method to find files is using their names. We search current directory with file named tmux. We will use -name option of the  find command. . means we want to search current working directory.

Find Files Using Name

Find Files Using Name

Find Files Under Home Directory

To search and find files under home directory of all normal users following find command can be issued.

Find Files Under Home Directory

Find Files Under Home Directory

Find Files Ignoring Case or Case Insensitive

By default find command search provided text case sensitive. To make search ignoring case sensitivity prefix -iname parameter with it like below. In this example we will search bash as case insensitively in the whole file system.

Find Files Ignoring Case or Case Insensitive

Find Files Ignoring Case or Case Insensitive

Search For Only Directories

Searching only directories can be done by specifying file type like below. We will use -type option and d to specify file type as directory.

LEARN MORE  Linux Version Command

Find Python Files

Searching python files with their extension can be done like below. The extension py can be changed anything we want.

Find Python Files

Find Python Files

Find Files with 777 Permission

777 permission can be a security problem if the files owned by root or high privileged user. We can search files according to their permissions. We will use -perm option and the permission value.

Find Files with 777 Permission

Find Files with 777 Permission

Find SUID Set Files

We can search files and directories according to their suid values. We will use -perm and /u=s to specify user suid flag.

Find SUID Set Files

Find SUID Set Files

Find Read Only Files

Searching read only files can be done below. We will use /u=r which means user is readonly.

Find Files with Permission 777 and change to 664

Searching files with 777 permission and making them more secure with 664 can be done with following command. We can execute command in found files with -exec option. {} is used to specify file name in -exec part.

Find Files with Permission 777 and change to 664

Find Files with Permission 777 and change to 664

  • -exec gives the ability to execute command on the found file.
  • {} is used to specify founded files to run chmod on these files
LEARN MORE  How To Get Mac Addresses Of Hosts With Nmap?

Find and Remove Files

There is simple shortcut to find files and remove them. In this example we will remove files with .py extension by using rm command.

Find Empty Files

Find can found empty files. We only need to specify the -empty option to the find command like below.

Find Empty Files

Find Empty Files

Find All Hidden Files

Hidden files generally used by operating system or applications for configuration issues. We can use . as hidden file syntax because we know that hidden files in Linux starts with . point.

Find All Hidden Files

Find All Hidden Files

Find Files For a User

Search files according to ownership. We will use -user option to specify the user name. In this example we want to find root user files with .txt extension.

Find Files For a User

Find Files For a User

Find Files For a Group

Search files according to group ownership. If the group do not exists find give an message like `find: ‘developer’ is not the name of an existing group

Find Files For a Group

Find Files For a Group

Find Files Modified Last 5 Days

Search files  according to their modification date. We will use -mtime options which means modification time to find files those have modified last 5 days.

Find Files Modified Last 5 Days

Find Files Modified Last 5 Days

Find Files Access Last 5 Days

Search files those accessed last 5 days. We will use -atime as option for access time.

LEARN MORE  How To Disable or Enable Selinux?

Find Files Access Last 5 Days

Find Files Access Last 5 Days

Find Files Modified Between Last 50 and 100 Days

Search for files modified last 50 and last 100 days

Find Files Modified Between Last 50 and 100 Days

Find Files Modified Between Last 50 and 100 Days

Find Files Changed Last 2 Hours

Search for files those changed last 2 hours

Find Files Changed Last 2 Hours

Find Files Changed Last 2 Hours

Find Files Sized 10MB

We can find files according to their size. We will use -size option for this. In this example we will find those size is 10MB. We can use - o + to specify  than lesser or bigger than the given size

Find Files Sized 10MB

Find Files Sized 10MB

Find Files According to Size and Delete

Search files those bigger than 100MB and delete them.

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/linux-find-command-with-examples/
PINTEREST
PINTEREST
INSTAGRAM

You may also like...

Leave a Reply

Your email address will not be published.

Enjoy this blog? Please spread the word :)