It appears that you're running an Ad-Blocker. This site is monetized by Advertising and by User Donations; we ask that if you find this site helpful that you whitelist us in your Ad-Blocker, or make a Donation to help aid in operating costs.

The Power of the Linux Find Command · Video


Unfortunately in Linux, certainly Ubuntu, the default GUI file search is not always useful. With just a small amount of patience you can find files quickly and easily using the command line, and your options for this are really powerful if you want to learn a bit about it.

The easy, quick command is called "locate." To use this command at the terminal you simply type:
Quote
$ locate -i searchstring


This will search for all files and directories with "searchstring" in the name, and -i means the search is not case sensitive (i.e. it will find searchstring, Searchstring, sEaRcHsTrInG, and so on). The results are instantaneous because the system has created a database (also known as an index) to tell you where files are located. The only problem is that newly created or moved files may not be found correctly until the next database update, and you don't have many options to choose from for your search. (forcing locate to update the database/index is done with
Quote
$ sudo updatedb
and it doesn't take a lot of time)

Example:
Quote
$ locate -i kdenlive.desktop


There is a much more powerful command available to you called "find." You can tell "find" where to look, what criteria to use in its search, and what actions to take once you have found what you are looking for. The syntax for "find" is:
Quote
$ find [where to start searching] [search criteria] [actions to take]


If you don't add any parameters, find will default to searching the current working directory (or "."), uses no search criteria (defaults to showing all files), and -print (which, despite its name, displays, or "prints," the results on screen) as the only action to take.

Two examples:
Quote
$ sudo find / -type f -mmin -10


This example will find (starting at the root directory, or /, and recursively search subdirectories) all normal files (-type f means normal files, without this it will find normal files + special files + directories) which were modified less than ten minutes ago (-mmin -10), and then display the results for you. This would be useful if you know you edited a file recently but don't know where you put it, or have to find a log file for a program that crashed. I use sudo here because find does not search files/directories that the current user does not have permissions for, and it will return error messages. However, you should use caution when using sudo.
Quote
$ find ~ -iname "*xxx*" -exec mv -v {} /media/pr0n/ ;


This will find everything in your home directory (~) with a name, case insensitive (-iname), containing xxx ("*xxx*") and execute (-exec) a move (mv) of the results ({}) to /media/pr0n/ ( ; is required by -exec to show the end of the command to be executed). So all your downloaded porn will be moved to the same place. mv -v displays the results of the move command with (-v)erbose messages. Another warning with -exec, though it is powerful, when used without care you can overwrite your whole home directory or whole disk - so be careful!

For those of you who simply can't do without a GUI, you can find the program catfish in the repositories - this enables you to run both locate and find from a graphical front-end, but it is very limited in options. Think of it as an equivalent to Windows Search. If you want the full power of find, you'll need to run it from the command line!

A big thanks to BigWhale for helping me find my footing with the find command.

Note: The "text" tutorial above was reprinted from LinuxHaxor.
Posted By Gremelin Posted on May 31st, 2014
▼ Sponsored Links ▼
▲ Sponsored Links ▲

Comments

( Posted)

Related Products

▼ Sponsored Links ▼
▲ Sponsored Links ▲
Donate Today