Linux Command Line

  Home > Tips & Tweaks > Linux > Linux Command Line > Linux Command Line 1
 
 

More Linux Commands

You've a file residing in some dark corner of one of your partitions; where did you last see it? You just can't remember where you saved that pesky, little file. One of my most used tools for file searching is the �locate� command. It's a quick little number when it comes to sniffing out a file because it doesn't traverse your entire file system when searching, which can be painfully slow: it parses a file database to get what you're looking for (my file database is configured to update itself at 4:40 every morning; �man updatedb� for more information). Perhaps you're curious about every file or directory that contains the text �python� somewhere inside of it.

 

liquidbinary@arrakis:~$ locate python

 

Running the above command outputs a myriad of search results. In fact, there are so many that the massive amount of output scrolls by without giving me a chance to review it; my eyes glaze over, trying to keep up. To rectify this, let's do something called �piping�, which is taking the output from one program and sending it to another program to process.

 

liquidbinary@arrakis:~$ locate python | less

 

Cool, huh? The above command chain takes the output from �locate python� and pipes the output to the �less� command using the vertical bar symbol �|�. The less command takes its input and displays it one screen at a time, allowing you to scroll through the output at your leisure, so you can actually see the output without it racing by at breakneck speed.

 

�Piping� output from program to program gives you an extraordinary amount of control and flexibility, and makes the shell a very powerful command line environment. For example, suppose I run �ls�:

 

   liquidbinary@arrakis:/tmp$ ls

 

 

The above fires up the �ls� command inside the �/tmp� directory; this outputs all the file names within the �/tmp� directory. What if I only wanted to output tarball files (files that end with a �.tar.gz� suffix)? I'll need some way to filter out all files that don't contain �.tar.gz�. �Grep� is a nifty little tool that searches for patterns, and, if found, will output the match. Piping the output from the �ls� to �grep� will do the trick. Watch this:

 

liquidbinary@arrakis:/tmp$ ls | grep .tar.gz

 

The output from �ls� is �piped� into �grep�. �Grep� then takes the input that it got from �ls� and searches for the pattern �.tar.gz�, and, if found, displays the match. The output is filtered and only tarball files are displayed at the shell.

 

The shell is a very formidable beast that awaits your every command.



More On Linux

-SuSe Linux

-Partition Your Hard Drive For Linux

-Make A Start Up Disk For Linux

-Touring the Linux File System

-Emacs - A User's Best Friend

Back To Tips Homepage

 


Google
 

Popular Articles:

How To Build A PC | Different Types of Keyboards | Help with Hard Drive Installation | Computer Networking Basics | Introduction of Motherboard Functions | Computer CPU Processor Speed | Upgrade from Windows 95 to Windows 98 | Computer Monitor Troubleshoot | Partition Hard Drive | Installing New CPU Processor | Types of Network Cables

 
Popular Topics
Home
Building A PC
How To Guide
Software
Hardware
Tips & Tweaks
Freeware
   

 

 

1999-2010 All rights reserved © waterwheel.com