Tip: Using find Command in Linux

2009-12-10 278 words 2 mins read

Ok this I was planning for quite sometime.. but found this <a href="http://www.pinoytux.com/linux/tip-using-find-command-in-linux" target="_blank">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:

  <td>
    <div class="text codecolorer">
      find /home -name *.doc -mtime 1
    </div>
  </td>
</tr>
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!):

  <td>
    <div class="text codecolorer">
      find /home -name *.doc -type f -mtime 1 -exec rm ’{}’ \\;
    </div>
  </td>
</tr>
1

You can also find files owned by a certain UID:

  <td>
    <div class="text codecolorer">
      find /tmp -user johndoe find /tmp -uid 502
    </div>
  </td>
</tr>
1

Or by GID:

  <td>
    <div class="text codecolorer">
      find /home/development -gid 1000
    </div>
  </td>
</tr>
1

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

  <td>
    <div class="text codecolorer">
      &nbsp;find . -perm -777
    </div>
  </td>
</tr>
1

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


Tags: find Linux

author

Authored By Amit Agarwal

Amit Agarwal, Linux and Photography are my hobbies.Creative Commons Attribution 4.0 International License.

We notice you're using an adblocker. If you like our webite please keep us running by whitelisting this site in your ad blocker. We’re serving quality, related ads only. Thank you!

I've whitelisted your website.

Not now
This website uses cookies to ensure you get the best experience on our website. Learn more Got it