Perform basic file management: Using find

«« Previous
Next »»

The GNU find command has to be one of the most useful tools ever and I think this is one of those tools that some people just never get to see in its full glory so do spend some time practising on your own systems and in the man pages. In this blog we look at what you need to know for the LPIC-1 exam about using the find command. You will soon learn that find is useful in the exam and real life too and will be a tool to use all the time.

Simple Listings


We can begin with some simple listing. First we list all PDF files in the current directory and below

find -name '*.pdf'

If we were uncertain on the case of the name that we are search for then we can use iname. This performs a case insensitive search

find -iname '*.pdF'

Now we can do the same but this time for the /usr directory and below. If we do not want to default to the current directory we add the directory path to search.

find /usr -name '*.pdf'

The default search will recurse into all the directories. If we do not want to recurse into directories below we can set the maxdepth attribute. So this is the same but only for the /usr directory .

find /usr  -maxdepth 1 -name '*.pdf'

List on Size


There are many attributes of a file we can search upon, not just the name. Here we can also list files greater than a certain size. The dot here is used to represent the current directory,

find . -size +2k -type f

If we want to carry out actions on these files

find . -size +2k -type f -exec ls -lh {} \;

Take a look at my video guiding you through this.


«« Previous
Next »»

0 comments:

Post a Comment