Finding files in Linux

File searching with Linux [slightly modified man page]

Name: find –  search for files in a directory hierarchy

Synopsis: find [directory where to search]

Basic finding options:

  • find . – find in current directory
  • find /etc – find in the etc directory
  • find / – find in the root directory

Searching by file name:

  • -name – search for file name
  • -iname – ignore the lower/upper level
  • -not name – not name
  • – find . \! -name “test.txt” – find except “test.txt”
  • -find / –name “*” – find all, example of regex

Finding by file category

  • -type c – finding by type
  • -type f – find all files on the system
  • f: regular file
  • d: directory
  • l: symbolic link
  • c: character devices
  • b: block devices

Example of search combination:

 

 

Alternatives:

  1. Locate – limited flexibility, you need to know the file system name, incl. cases. It is based on a pattern and searches in the Database.  This means that a regular sudo updatedb is needed. Note: note installed by default in most os.
  2. Which – looks in the current user’s path and if the file that is being searched for is there, it will be found.

Leave a Reply

Your email address will not be published.