Skip to content
Default image

Linux find command – part 2

May 4, 2022

In the first post about the find command I showed you how to search for files by name, extension, type and size.

Now it’s time to see other great options that the find command has.

Find files by modification date

The find command comes in handy when we need to search for files based on their creation(c) date, modification(m) date or accessed(a) date.

We can also use the and +, like we did for the -size option, in order to specify less than or more than.

find [path] -ctime [number of days] -> files created in the last number of days

find [path] -mtime [number of days] -> files modified in the last number of days

find [path] -atime [number of days] -> files accessed in the last number of days

Now, some examples on how to use this option

In the example below, I wanted to find the files modified more than 5 days ago

I forgot I’ve created this directories more than 10 days ago, how time flies:)

When searching for files based on date, we can also search using minutes instead of days:

find [path] -cmin [number of daysminutes] -> files created in the last number of minutes

find [path] -mmin [number of minutes] -> files modified in the last number of minutes

find [path] -amin [number of minutes] -> files accessed in the last number of minutes

Find files by permissions

Another way to find files is by permission.

You can run into situations where multiple users are working on the same server in the same time.

One of the things that can go wrong is that someone else could be accessing one of your files. In order to prevent this Linux has a file permission feature that specifies the permission level one user has over a certain file or directory (more info on file/directory permission can be found here).

The find command option that we will use is -perm along with the permission value.

find ~ -perm 644

Let’s see how it works

We can use the “” in front of the numeric value of the permission. This will return files that have write and read permission set only for the owner.

Another option is to use “/” and it will find the files with write permission set for the user, group or others.

We can also search for files with the -perm option and the symbolic values.

Using a(ll users), u(ser – owner), g(group), o(thers) and w(rite), x(ecute), r(ead) will return the same finding as in the examples above where we used the numeric value.

Find files by owner

At some point, you will run into a situation where you have to find a file or directory owned by a certain user or group. We do this by using the -user or -group option of the find command.

If you need to find all files and/or directories owned by a particular user, run the following command

Let’s say you need to find a file named test.txt . There are a couple of files with that name in you system but you only need the one created by a certain user.

You will use the -name option along with the -user option of the find command

You can also search for files/directories owned by a group. In the next example I want to find all the files owned by the root group in my current working directory.

This is it for now.

In the next days I will put together a post with more complex examples, maybe you will find it useful.