Finding files

Find a file on the file system

find - search for files in a directory hierarchy

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 {} \;

Find a program in the PATH

want to know the location of a program on the PATH.

depending on the shell you use.

which command type command

will show you the location of command

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)
  5. tell us where is located the program grep

Find files on a file system

Warning

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