Instructions for using find command in Linux

You can search for files by permission, user, group, file type, date, size, and other possible criteria using the find command.

The find command is available on most Linux distributions by default, so you don't need to install packages for it.

In this guide, Macworld will show you how to find files on Linux using the combination of the various popular search expression in the command line.

Search file by name in current directory

The most obvious way to search for files is by name. To find a file by name in the current directory, run:

find . -name photo.png

Instructions for using find command in Linux Picture 1

If you want to find a file by name that has both upper and lower case letters, run:

find . -iname photo.png

Instructions for using find command in Linux Picture 2

If you want to find a file in the root directory, put the sudo prefix before your search. This will give you all the necessary permissions to do so and also has a '/' icon that allows Linux to search in the root directory. Finally, the -print expression displays the directories in the search results. If you're looking for Gzip, you must type:

sudo find / -name gzip -print

Instructions for using find command in Linux Picture 3

Find files in specific directory

If you want to find files in a specific directory like '/ home' , run:

find /home -name filename.txt

If you want to find files with the '.txt' extension in the '/ home' directory , run:

find /home -name *.txt

To find files named 'test.txt' in multiple directories like '/ home' and '/ opt' run:

find /home /opt -name test.txt

To find files hidden in the '/ home' directory , run:

find /home -name ".*"

To find a single file named 'test.txt' and delete it, run:

find /home -type f -name test.txt -exec rm -f {}

To find all empty files in the '/ opt' directory , run:

find /opt -type f -empty

Find folder by name

If you want to find all folders named 'testdir' in the '/ home' directory run:

find /home -type d -name testdir

To archive all empty directories under '/ home' run:

find /home -type d -empty

Find files with certain permissions

The find command can be used to find files with specific permissions using the perm option .

To find all files with permission as '777' in the '/ home' directory , run:

find /home -type f -perm 0777 -print

To find all files that do not have "777" permission , run:

find . -type f ! -perm 777

To find all read-only files, run:

find /home -perm /u=r

To find all executable files, run:

find /home -perm /a=x

To find all Sticky Bit file sets that have permission to '553' , run:

find /home -perm 1553

To find all SUID file sets, run:

find /home -perm /u=s

To find all files with permissions as '777' and change their permissions to '700' run:

find /home -type f -perm 0777 -print -exec chmod 700 {} ;

Finds files and folders based on date and time

To find all files in '/ opt' that were modified 20 days ago run:

find /opt -mtime 20

To find all files under '/ opt' accessed 20 days ago run:

find /opt -atime 20

To find all files under modified '/ opt' for 30 to 50 days run:

find /opt -mtime +30 -mtime -50

To find all files under '/ opt' changed in the last two hours run:

find /opt -cmin -120

Find files and folders based on size

To find all 10MB files in the '/ home' directory run:

find /home -size 10M

To find all files in '/ home' directory larger than 10MB and less than 50MB, run:

find /home -size +10M -size -50M

To find all the '.mp4' files in the '/ home' directory that are more than 10MB and delete them with a single command, run:

find /home -type f -name *.mp4 -size +10M -exec rm {} ;
5 ★ | 1 Vote

May be interested

  • 18 Interesting Linux Commands in Terminal18 Interesting Linux Commands in Terminal
    terminal is a very powerful tool, but it can be made 'interesting' through a few bash commands that tipsmake.com will introduce to you below. let's follow and learn because some commands are quite useful.
  • How to find, set and change IP addresses on LinuxHow to find, set and change IP addresses on Linux
    ip address is like a computer phone number. computers use it to communicate with other devices and vice versa. here are some simple ways to manage ip addresses on linux.
  • The Cat command in LinuxThe Cat command in Linux
    the cat command (short for 'concatenate') is one of the most frequently used commands in operating systems like linux / unix. the cat command allows users to create one or more files, view file contents, join files, and redirect output in a terminal or file.
  • How to use the last command in LinuxHow to use the last command in Linux
    want to know who, what time and which device to access your linux computer? please read the following article.
  • How to use ss command on LinuxHow to use ss command on Linux
    the ss command is a new alternative to the classic netstat. you can use it on linux to get data about network connections. here's how to work with this helpful tool.
  • Search for files and directories in Linux using the command line interfaceSearch for files and directories in Linux using the command line interface
    you can use the graphical file management utility to find files in linux like nautilus in gnome, dolphin in kde and thunar in xfce. however, there are several ways to use the command line to find files in any linux desktop management utility.
  • 11 uses of ps command in Linux11 uses of ps command in Linux
    for system administrators, ps is a frequently used tool. the ps command is used to list the processes currently running on the system, with many available filtering and display modes via flags and arguments.
  • How to find a specific word in a file on LinuxHow to find a specific word in a file on Linux
    the famous gnu search program, grep can search inside the file with the correct flag. this article will show you how to find specific words in a file on linux
  • How to limit access to su command in LinuxHow to limit access to su command in Linux
    if you have added linux to your data center or are just using a single linux machine for your business, you need to make sure it is as secure as possible.
  • 12 things Linux is easier to do in the command line than graphical software12 things Linux is easier to do in the command line than graphical software
    graphical user interfaces (guis) were invented to make life easier for computer users, so it's very common to use them to perform most everyday tasks.