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
  • Crossroads At this point, I doubt anyone is seeing this as the wordpress test install is not live to the public yet, but... I'm opening this one up for comments. On the old site, I had accumulated a bit of content along the lines of windows/linux tips, software recommendations and tech......
  • Mail command missing in ubuntu by default Not really, news, but I was reminded again this evening that mail is not available at the command line in recent default installs of Ubuntu (or kubuntu /xubuntu). If you're like me and make use of this for scripting notifications.... you'll need to sudo apt-get install mailx (and a MTA......
  • 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
  • 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......
  • 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......
  • Create Autorun for your CD's and DVD's The compact disk drive auto play feature, common to most operating systems, is a good way to simplify user experience. Auto play is controlled by a simple text-only file called autorun.inf. While there are dozens of software utilities available that will help you create the file, all you really need......
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