Guide to find command

Guide to find command

The find command is a cornerstone of any Linux user's toolkit. It allows you to locate files and directories with pinpoint accuracy based on a variety of criteria. While the basic functionality is straightforward, the power lies in its advanced options.

This blog delves into these advanced features, equipping you to navigate the complex file systems of your Linux machine with ease.

Beyond the Basics:

We've all used find /path/to/search -name "filename" to locate specific files. But what if you need to find files based on size, modification time, or permissions? Here's where the magic begins:

Size Matters:

  • -size +20M: Find files larger than 20 Megabytes.
  • -size -40k: Find files smaller than 40 Kilobytes.
  • -size 60c: Find files exactly 60 bytes in size.

Time Travel with Modification Dates:

  • -mtime -7: Find files modified within the last 7 days.
  • -atime +30: Find files accessed in the past 30 days.
  • -ctime +1w: Find files where the inode (file metadata) changed last week (w stands for weeks).

Permission Precision:

  • -perm 755: Find files with read, write, and execute permissions for owner, read and execute for group, and no permissions for others.
  • -u john -perm 640: Find files owned by user "john" with read/write permissions for the owner only.

Combining the Powerhouse:

The true strength of find lies in combining these options for highly specific searches. For example:

find /var/log -user bijaydas -mtime -2 -name "auth.log*"        

This command searches the /var/log directory for log files (auth.log) owned by the user "bijaydas" that were modified in the last two days.


Delving Deeper

Searching by Time

You can search for files based on when they were last accessed (atime), modified (mtime), or changed (ctime).

  • Files modified in the last 7 days:

find . -mtime -7        


For the full article and more in-depth exploration, visit my blog!

要查看或添加评论,请登录

Bijay Das的更多文章