Using the command line in linux – part 4



Dealing with text…. we’ve looked at a couple of basics on logging in and starting to use the command line and hopefully not feeling too helpless there… we’ve seen ways to navigate directories and how to find new commands and how to find out more about how to use them. Now it’s time to talk about how to manipulate (work with) text files. Most every important configuration file in linux is text based and editable from the command line. This can be a VERY good thing at times, or very intimidating if you’re not comfortable with a command line environment. It’s worth noting that you CAN edit configuration files with a graphical interface text editor….


So, there are a number of text editors, one that I use quite a bit is pico, but there is also vi and emacs. pico is a nice, easy to use text editor and is highly recommended for beginners. With pico, ctrl-o writes a file and ctrl-x closes, with vi it’s a bit more complicated, esc must be pressed to quit editing and then :wq are typed (and enter) to write, and quit. vi is worth an article or two on it’s own and frankly, I don’t know that it would qualify for “basics”…. Let’s assume we can use pico…

First off, let’s take a look at a text file…
$cat textfile.txt

should give you a stream across the screen of the contents of textfile.txt… nice, but hard to read. OK, try this…
$less textfile.txt
now you can use the up or down arrows to move up or down one line at a time, and page up/page down to go down a page at a time.

$more textfile.txt has the same effect… except “enter” moves you by line and space moves by page…

What if you wanted to find out if there was a certain word in textfile.txt…..

$grep specialword textfile.txt
this line uses specialword which is a keyword that we will later search for

grep allows you to search for a term…. I use it daily….
For instance… (Has the googlebot visited?)

grep googlebot access_log -i
-i tells it to not be case sensitive…

It’s possible too, to chain grep commands: what if I wanted to see if the googlebot had visited pages published in January…. (2006/01 in the path…) Us the | (pipe) to feed output of the first part, to whatever followes the | (the | is usually the “shift” equivalent of )

grep googlebot access_log -i | grep 2006/01

I hope you’ve enjoyed the last few articles which give some ideas for how you might get started with the command line if you’ve never tried it before… Fortunately most operating systems respond to the “help” command and many have features to give further information when you follow a command with -h or –help or /? or /h …….

Dealing with text files at the command line can quickly get very difficult and take us out of “basics” territory into lower-intermediate levels, so I’m going to cut this series here before I get you in too deep…

Related Posts

Blog Traffic Exchange Related Posts
  • Ranking for a Search Phrase in Google I guess by now you've noticed that I'm not keeping up with the 1 post a week rate that I had for a while there. I've been thinking that at this point I'm going to be getting in one a month or so. More if the mood strikes, but from......
  • Mandriva 2006 upgrade on Inspiron 8000 laptop saga Part I I had a chance today to start the upgrade process for Mandriva 2006 on my laptop (Dell Inspiron 8000). Now, let's see.... a bit of background. Mandriva (Mandrive/Mandrake) has been my favorite distro since converting to linux several years back (around Mandrake 8.1 or 8.2) I've had it running on......
  • More google news sitemaps.... What are they trying to prove??? Okay, Google Analytics rolled out (slowly) earlier this week and is just now catching up on reporting data. It looked like one of the rockiest initial Google releases to date. This morning came the news of Google Base a way to submit and search,......
Blog Traffic Exchange Related Websites
  • Tennis Glossary Lawn Tennis - This is the original name used to describe modern tennis, based primarily on the fact that it is played on the grass, which was intended to distinguish it from tennis played on a court. Left Court - Left court and advantage court are the same thing. Let......
  • Google Loves You: 10 Top Tips for a Google-Friendly Website Many small businesses believe good Google listings are beyond them. This simply isn’t true. Find out how to be able to say “Google Loves You” and your website. 1. Domain Name Choose a domain name that contains two or three keywords that are the most important keywords for your......
  • Ten Steps To Become a Linux/Unix Geek Until recently, Linux/Unix was considered OS of the geeks. However, with GUI and more desktop Linux distributions, things have simplified on both Linux and Unix. Still you can geek out with Unix/Linux using its terminal. Just follow the steps below to master the terminal. 1. Never used Linux! Get Ubuntu......
www.pdf24.org    Send article as PDF   

Similar Posts


See what happened this day in history from either BBC Wikipedia
Search:
Keywords:
Amazon Logo

Comments are closed.


Switch to our mobile site