Tip: Using find Command in Linux

Ok this I was planning for quite sometime.. but found this here. Worth reading for people who want to start off using find command.

Doing command-line stuff in Linux is fun. It may be intimidating for some at first, now that we are in the age where GUI is no longer an option. But with CLI, we can do so many things that can be accomplished faster if we know how to utilize the features of a certain command.

One command that is very flexible is find. With find, you can search not only based on filenames, you can also use other identifiers like GUI and UID, timestamps and file types.

Here are some examples of find commands:

This command will find all files in /home directory with .doc as extension and was modified 24 hours ago:

find /home -name *.doc -mtime 1

This one will find the same files, but not directories, and delete them using -exec option (great for disk usage maintenance, but BACKUP first!):

find /home -name *.doc -type f -mtime 1 -exec rm ’{}’ \\;

You can also find files owned by a certain UID:

find /tmp -user johndoe find /tmp -uid 502

Or by GID:

find /home/development -gid 1000

You can also search for files and directories with certain permissions:

 find . -perm -777

And from those examples, you can build your own command to find what you are looking for.

This site uses Akismet to reduce spam. Learn how your comment data is processed.