Home | Hardware | Internet News |Web Hosting |IT Management |Network Storage
LinuxPlanet
Search 
  Power Search | Tips 

 Front Door
 Discussion
 LinuxEngine
 Opinions
 Reports
 Reviews
 Tutorials
 News
 Technology Jobs

 Browse by subject.
Free Newsletter

Java/Open Source Daily
Linux Today
More Free Newsletters

Be a Commerce Partner


















internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

Print this article
Email this article

   LinuxPlanet / Tutorials







The Linux CLI for Beginners, or, Fear Not the Linux Command Line!
Finding Files Very Fast

Akkana Peck
Friday, December 12, 2008 11:39:02 AM

Now that you have a terminal open you can start entering commands. First, let's take a look at a really useful Linux command-line utility called locate. It's a very fast way of finding files on your system.

For instance, suppose somebody sent me a funny picture a while back of a squirrel with tiger stripes. I know I saved it, but I can't remember where! But it probably had "squirrel" or "tiger" or maybe both somewhere in the name.

From the desktop I can do simple filename searches, but it's a bit slow and, as you'll see, it's not as flexible. So let's try it from the command line. Type:

$ locate tiger

Don't type the $, that's just to show you that this command can be run as an ordinary user. locate tiger gets quite a few matches (Figure 3). The list is short enough that I could read through them all, but why not get the computer to do that work for me?

So what if I try:

$ locate squirrel
instead?

Eek! I'm not going to tell you how many files that found. Suffice to say that I take way too many pictures of squirrels, and finding one specific file in that mess looks way too hard.

The locate command depends on a database of every filename on your system, and most Linux distributions automatically update this database daily. It doesn't hurt to update it manually just to make sure, using the updatedb command. You need root powers to do this, which on Ubuntu you get with the sudo command:

$ sudo updatedb

It can take a few minutes, so be patient.

Pipes to the rescue

Fortunately, the Linux command line offers a way to combine these two searches. It's called a pipeline, because it uses the ASCII vertical bar character sometimes called a "pipe", which is the uppercase of the back-slash key: |.

Most basic Linux commands are set up so that you can "pipe" the output of one program into the input of another. The simplest version of a pipeline is one that uses the program "less" to display a file in screen-sized chunks. less shows you one page at a time; hitting the spacebar will take you to the next page, while q will quit. Try it for yourself in your terminal window. In case you don't have as many squirrel pictures as I do, try searching for files containing "cat":

$ locate cat | less

I bet you didn't know you had so many cat files on your system! Remember, q will get you out of less and back to the command prompt.

Okay, how do we use a pipeline to help find the tiger-squirrel picture? With the grep command, probably the single most useful command Linux offers.

Next: grep Isn't Something You Do When You're Sick »

Skip Ahead

1 Please Meet the Linux Terminal
2 Finding Files Very Fast
3 grep Isn't Something You Do When You're Sick
Figure 3
Figure 3





Linux is a trademark of Linus Torvalds.


internet.com home | search | help! | about us

Jupiter Online Media

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Web Hosting | Newsletters | Tech Jobs | Shopping | E-mail Offers