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…

Popularity: 1% [?]

PDF Download    Send article as PDF   
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......
  • 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......
Blog Traffic Exchange Related Websites
  • 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......
  • Would You Spend $50 To Gain 1,000+ Subscribers? - Internet Marketing [/caption] There's only one way you can do that in this competitive, yet scammer filled world of Internet Marketing, and that's through PPC. But how does an Internet Marketing person beat the Google Police? Advertising Policies have become so strict at Google that promoting an Internet Marketing product or......
  • How To Create A Custom Notebook Using Microsoft Word 2007 Next is to make the cover page and the back page. I'm going to make a cover page with background image and some texts. If you want to be very artistic you can customize the cover page using Photoshop or other graphic software. To do add background image you......

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