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......
  • Neat grep intro Linuxgangster.org (??) has a good article up on the powerful grep command. GREP is one of the most useful command line tools in linux (really, there are so many it's hard to choose, but this is one I use more frequently than most others...) grep can stand on it's own......
  • 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......
Blog Traffic Exchange Related Websites
  • New Domain to Google Page Rank 5 in One Month Google said Merry Christmas and Happy New Year to Blog Traffic Exchange with the final toolbar pagerank update of 2008 according to Matt Cutts. This was the first page rank update since launching the domain in late November with this blog. So in one month how much page rank can......
  • Search Engine Robots Or Web Crawlers Most of the common users or visitors use different available search engines to search out the piece of information they required. But how this information is provided by search engines? Where from they have collected these information? Basically most of these search engines maintain their own database of information. These......
  • Smart Landing Page Optimization Strategies You can perform optimization for max conversion rates on anything, and that is what you can also do for your landing pages if your conversions are poor. This is common knowledge among experienced web business owners, but it's the new internet marketer that usually has yet to learn. So, really......
en.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