Finding files

Find a file on the file system

find - search for files in a directory hierarch

Warning

NEVER perform a find starting at / on the central storage.

There are lots of criteria to find files.
We will see just a few.
For a more complete expressions list: man find

Find a file or a directory

find . -type f

Find files by name

Don't forget to enclose the pattern in quotes in order to protect it from expansion by the shell.

find . -name '*.fasta'

Find files by date

#find every files which was read at most 3 days ago or
find . -atime 2
#find every files created today
find . -ctime 0

Find files by owner

Find files and execute a command on the result

#find each fasta file in my DataBio directory
#containing the string 'ABCD'
find ~/DataBio -name '*.fasta' -exec grep -H ABCD {} \;

Exercises

  1. on your virtual machine, find all the files created on tuesday in your home directory.
  2. on your virtual machine, find all the files in DataBio or in subtree which contains 'IL2' use -exec.
  3. connect to central-bio and find all the files that are owned by one of your unit members in your unit directory.
  4. in unix_training project dir, find files without any extensions (HINT: ! negates an expression for instance find . ! -type f match all link and dir)

Find files on a file system

Warning

NEVER perform a find starting at / on the central storage.