Little Girl's Mostly Linux Blog

FindEverything

Find everything

This page was last updated on December 10, 2009.

Find Man Pages

  • Find all man pages on foo:
  • zgrep -lw foo /usr/share/man/man1/*

Find Files By Age

  • To find all files in a specific directory and any of its subdirectories that are older than 5 days:
  • find /path/to/directory -mtime +5

  • To find all files in a specific directory and any of its subdirectories that are younger than 5 days:
  • find /path/to/directory -mtime -5

  • Find all files in the current directory that were changed in the last one minute:
  • find . -mmin -1

  • Find all files in a specific directory that have been created or added to subdirectories within the last 30 days and output the result to a text file:
  • find /path/to/directory -type f -mtime -30 -exec ls {} \; > filename.txt

Find Files By Name

  • Find a file named foo:
  • locate foo
    • The locate database is updated daily, but you can manually update it to catch recent changes with this command:
    • sudo updatedb
  • Find all files named foo in a specific directory:
  • find /path/to/directory -name foo

  • Find all files named foo in the current directory or any subdirectory tree:
  • find . -name foo

  • Find all files named foo anywhere on the system:
  • find / -name foo

  • Find all files whose names contain foo in a specific directory or any of its subdirectories:
  • find /path/to/directory -name "*foo*"

  • Find all files that start with “foo” in a specific directory and all its subdirectories:
  • find /path/to/directory -iname foo*

Find Text Inside Files

  • Find foo inside a specific file:
  • grep foo /path/to/file

    Or:

    cat /path/to/file | grep foo

  • Find foo inside files in the current directory:
  • grep foo *

  • Find foo inside files in the current directory and all subdirectories:
  • grep -r foo *

  • Find foo inside files in the current directory and all subdirectories and display 15 lines of each result:
  • grep -rA 15 foo *

  • Find foo inside files in the current directory, ignoring case and displaying the file name and line number of each result:
  • grep -in 'foo' *

  • Find foo inside files in the current directory and all subdirectories, ignoring case and displaying only the names of the files that contain the search term:
  • grep -lir "foo" *


Obligatory Happy Ending

And they all lived happily ever after. The end.

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Comment:

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: