Home / Operating System / Using the find command in Linux

Using the find command in Linux

Print Friendly, PDF & Email

Files and folders can be found in many different ways regardless of operating systems. In Linux, it equips the find command to do search for files. Many users use the find command with just the basic parameters. They get the results that they are looking for. Unfortunately, most of the users don’t spend much their time to learn all about the find command in a professional way. I, therefore, want to stick here a few ways to use this excellent tool that make you surprised.

Basic usage

Let’s give an example. We want to find all the file which the names contain the word ‘Klamt’ in the current directory, the syntax of find command looks like:

in which:

  • Dot (.) indicates the current directory
  • -name: given search text is the filename rather than any other attribute of a file
  • ‘*Klamt*’: search text that we have entered. Always enclose the filename in single quotes. Using wildcards to search all possibilities containing the keyword ‘Klamt’.
in which:

  • ~/Downloads: the directory where the files are potentially located.
  • -iname: looking for files based their file name without regarding letter case.

Advanced usages

The 1st command would find within a directory called /Documents, only those pdf files that have a size less than 5000 Kilobytes (< 5MB). The 2nd command would search from the / directory for any file that is larger than 10000k (> 10MB). We could use M for Megabyte instead of k short for Kilobyte.

The best part is that find supports boolean operators to make the search even stronger. For this example, I will use a command that combines my knowledge that the file is less than 5 megabytes in size, and also more than 2. The command is the following.

We also tell the find command to seek the files which have been accessed or modified for minutes, hours.

The first command searches for those files that are present in the directory /home/david and its subdirectories which end in .c and which have been accessed in the last 10 minutes. The second command does the same but searches for those files that have been accessed in the last 10 hours. The third and the fourth commands do the same as the first and second commands but they search for modified files rather than accessed files. Only if the contents of the files have been modified, their names would be returned in the search results.

 

References

  1. http://www.codecoffee.com/tipsforlinux/articles/21.html
  2. http://hacklog.in/find-explained-through-a-screencast/
  3. http://about_linux_command_find.onlinephpfunctions.com/
  4. https://www.linode.com/docs/tools-reference/tools/find-files-in-linux-using-the-command-line/
comments

About Nguyen Vu Ngoc Tung

I love making new professional acquaintances. Don't hesitate to contact me via nguyenvungoctung@gmail.com if you want to talk about information technology, education, and research on complex networks analysis (i.e., metabolic networks analysis), data analysis, and applications of graph theory. Specialties: researching and proposing innovative business approaches to organizations, evaluating and consulting about usability engineering, training and employee development, web technologies, software architecture.