Milinda Pathirage’s Blog

Computers are fascinating machines, but they’re mostly a reflection of the people using them

Using ‘find’ command in Linux

May 21st, 2008 · No Comments · linux tips

The find command allows the Linux users to process a set of files and/or directories in a file subtree.Users can specify where to search, what type of file to search for (-type: directories, data files, links), how to process the files (-exec: run a process against a selected file), the name of the file(s) (-name) and perform logical operations on selections (-o and -a). Here are some examples:
  • Search for file with a specific name in a set of files:
    find . -name "soap_fault_text.c" -print
    This command will search in the current directory and all sub directories for a file named soap_fault_text.c.
  • Applying a Linux command to a set of file (-exec):
    find . -name "soap_fault_text.c" -exec chmod o+r '{}' \;
    This command will search in the current directory and all sub directories. All files named soap_fault_text.c will be processed by the chmod -o+r command. The argument '{}' inserts each found file into the chmod command line. The \; argument indicates the exec command line has ended.
  • Search for a string in a selection of files (-exec grep ...):
    find . -exec grep "www.athabasca" '{}' \; -print
    This command will search in the current directory and all sub directories. All files that contain the string will have their path printed to standard output.
For more information: Sphere: Related Content

→ No CommentsTags:

 Page 14 of 14  « First  ... « 10  11  12  13  14