Tag Archives: command line

The PATH to /home/timmy/grannys_house

Back in the old days, when Timmy wanted to visit granny’s house, all he had to do was have Lassie lead him there. In today’s more complicated computer world, it takes a bit more understanding.

We’re going to learn a bit about a very important subject in Linux. It’s called PATH. The path to a file or whatever on your Linux operating system is something that you need to understand when manipulating files from the command line. Another term we’ll look at briefly is the working directory.

When Timmy, as a regular user, opens his terminal from his GUI or from the post login command line (Run Level 3 – multi-user, no X running), his working directory is in /home/timmy. Whichever directory you are in at the time is known as the working directory. Timmy may navigate to another directory using the cd command. Let’s say he navigates to /usr/bin. At that time, his working directory becomes /usr/bin. See how this works?

Think of the Linux file system as a multi-room house. If you’re in bedroom4 right now, your working directory would be /house/bedroom4. If you walked out of that room and down the hall to bathroom02, then your working directory becomes /house/bathroom02. At that time, you may then use the command micturate. Heh! A little bathroom humor there.

OK, so now we know all about the working directory, right? Moving on…

Let’s say that Timmy wants to copy a .jpg that is in /usr/share/wallpaper over to the /home/timmy/grannys_house directory. He would open his terminal, which would then be sitting there with that blinking cursor waiting for Timmy’s next command:

timmy@lassies_machine~:$ |

Timmy’s working directory at this point is /home/timmy, as designated by the command line shorthand character ~ . If Timmy wants to copy the .jpg without actually going to the directory that it’s in to copy it, he must provide the proper path in his command.

timmy@lassies_machine~:$ cp /usr/share/wallpaper/cabin.jpg /home/timmy/grannys_house

The above command, using absolute path names, directs the shell (command line interpreter) to copy the cabin.jpg image from the /usr/share/wallpaper directory to the /home/timmy/grannys_house directory. If Timmy wanted to just make a duplicate of a file in his /home/timmy directory, then he could leave off the / character when showing the command line the proper path. This can be done because he’s already in the /home/timmy directory. It is his working directory. He can now use a relative path to direct the shell to make the copy.

timmy@lassies_machine~:$ cp cabin.jpg cabin.jpg_backup

In the above example, notice that there is no / being used. Timmy is simply making a backup copy of cabin.jpg. Both files are relative to his working directory, so the shell understands that Timmy just wants to make this duplicate right there in that same directory.

It’s really not rocket science, to use that worn out old cliché. The command line can be pretty simple once you get the hang of it folks. You know what I always say… Don’t fear the command line. I hope you’ve learned something here today. Remember to click the links within the article. You’ll find some more useful information and a few definitions for you there.

Later…

~Eric

Further reading:

Unix Commands @ Wikipedia

LinuxTutorial.info

Linfo.org

Paul Sheer’s Rute Users Tutorial and Exposition

Image credits: Timmy (Jon Provost) and Lassie image owned and copyright by Classic Media

Grep This!

When a problem comes along
You must grep it
Before the cream sets out too long
You must grep it
When something’s goin’ wrong
You must grep it

I say grep it
Grep it good
*

*My apologies to Devo.

This is another in our continuing series of articles where I try to get you to not be so fearful of the command line. Remember, the command line is your friend, like Google. So, what is grep and how do we use it, hmm? Well, grep is one of the most popular Unix/Linux commands of all time. It’s used to search for patterns in files using regular expressions. What’s a regular expression? Well, that’s just words like you see right here… Bill loves ice cream or Mary is a brunette.

When you want to search for something in a file but you can’t quite remember exactly the part your looking for, grep can help. You can search for partial phrases and wildcards too. A wildcard is usually signified by the * (asterisk) character in commands. It works with grep also. Let’s see a couple examples, shall we?

Example 1

In this example, you’re trying to find a paragraph in a large file (your Ph.D thesis on frog flatulence) about bull frogs and their ability to communicate with their flatulence. You’re pretty sure it’s in chapter 13. That’s all you can remember.

$ grep ‘bull frog’ /home/you/thesis/frog-flat/chapter-13

Results:

chapter-13:bull frogs have been known to communicate by modulating

chapter-13:while bull frogs can be muted using Beano supplements in

chapter-13: censoring bull frogs in this way has been known to reduce

As you can see, each line containing the regular expression ‘bull frog’ has been output for you by the grep command.

Of course, grep has the usual panoply of helpful options like:

-h    – if you search more than one file at a time, the results contain the name of the file from which the string was found.

-n    – precedes each line with the line number where it was found

-i    – tells grep to ignore case so that it treats “the” and “The” as the same word

-l    – displays a list of files that contain the string

-w    – restricts the search to whole words only

What if you wanted to exclude some word or phrase from your search of a certain file? Well, the versatile grep command can do that too.

Example 2

In this example, you want to do the opposite of what you did in Example 1. Instead of searching for lines within the file with the phrase ‘bull frog’, you want to exclude them.

$ grep -v ‘bull frog’ /home/you/thesis/frog-flat/chapter-13

The above command would now show you all the lines in the text file except those that have the phase ‘bull frog’ in them.

The first place to start with your grepping adventures would, of course, be its manual page.

$ man grep

Grep is another very useful tool in the command line arsenal, folks. Get out there and grep something. It won’t hurt you none.

Later…

~Eric


Further reading:

Grep Man Page

Grep Tutorial

How to Use the Grep Command

Tips for Linux – Grep

What Is Grep?

Available @ O'Reilly Media, Inc.

Christmas How-To Using the Command Line

Here’s another helpful command line Linux how-to for you folks out there in Linuxland:

Christmas How-To

  • you_linux~:$ su

Password: ***************

  • you_linux~:# locate Christmas

locate: warning: database /var/lib/slocate/slocate.db’ is more than 8 days old

  • you_linux~:# locate update

/var/log/setup/setup.08.gtk-update-icon-cache
/var/log/setup/setup.07.update-desktop-database
/var/log/setup/setup.07.update-mime-database
/sbin/update-usbids.sh
/usr/lib64/qt/bin/lupdate
/usr/lib64/perl5/5.10.0/CPANPLUS/Selfupdate.pm
/usr/lib64/yp/pwupdate
/usr/share/autoconf/autoconf/autoupdate.m4
/usr/share/xml/docbook/xsl-stylesheets-1.75.1/tools/bin/docbook-xsl-update
/usr/share/gtk-doc/html/gtk/gtk-update-icon-cache.html
/usr/share/vim/vim72/ftplugin/updatedb.vim
/usr/share/vim/vim72/syntax/updatedb.vim
/usr/share/ri/1.8/system/RI/HtmlFormatter/update_attributes-i.yaml

  • you_linux~:# locate Christmas

/home/you/heart/Christmas

/home/you/heart/family/Christmas

/home/you/heart/friends/Christmas

  • you_linux~:# make Christmas && make happy && make peace

Christmas successfully created from /home/you/heart/Christmas/source

  • CTRL+D
  • you_linux~:$ ./ Christmas

Have a wonderful Holiday Season, folks!

Later…

~Eric

Image credits: Santa and sleigh courtesy of freeclipartnow.com

Let’s Build a SlackBuild

SlackBuilds are custom written installation scripts used to install non-native applications into your Slackware Linux operating system.

The SlackBuild Project is maintained by a small group of dedicated folks. Your assistance with new script submissions is always welcome.

For today’s little SlackBuild tutorial, I’m going to use a SlackBuild to install PysolFC, a collection of really cool card games and majong-type games that is maintained by my friend Matthew Fillpot. Matt is one of the lead gurus over at the Linux.com Community site. Stop on over for a visit sometime.

One of the first thing I do on any of my Linux installations is to create a hidden directory called .build in my /home directory that I use primarily for manual compiling of applications, or in this case in Slackware, installation of SlackBuild scripts (see Fig 1).

Figure 1 – /home/<user>/.build

OK, let’s get started. The first thing you’ll need to do is navigate to SlackBuilds.org in your favorite browser. In the small search window in the upper right hand corner, type in the application you’re looking for. In this case, that would be PysolFC. Once the search is completed, you’ll be on the pysolfc SlackBuild page (see Fig 2).

Figure 2 – Pysolfc SlackBuild Page

Now, the next thing you’ll need to do is download the source (PySolFC-1.1.tar.bz2) and the SlackBuild (pysolfc.tar.gz) into your .build directory (or wherever you want to build your stuff). Untar the SlackBuild script from the command line using this command:

$ tar -xvf pysolfc.tar.gz

Or you can unpack it using your favorite graphical decompression app like Ark or Xarchiver… use whatever you’re comfortable with.

You’ll now have an uncompressed directory called “pysolfc”. Move the source directory (PySolFC-1.1.tar.bz2) that you downloaded previously into your newly uncompressed pysolfc directory. That’s right. Just grab and drag that source directory right on into the pysolfc directory (see Fig 3).

Figure 3 – Inside the Pysolfc Directory

OK, then… Now for some fun command line stuff. I know you love working in the command line. Don’t be afraid. Just follow my directions. Alrighty…

1. Open your terminal application (Gnome Terminal, Konsole, etc.)

2. Type the following command to make the pysolfc SlackBuild script executable:

$ chmod +x pysolfc.SlackBuild

3. As root (to install globally on your Slackware system so all users can access), type the following command:

# ./pysolfc.SlackBuild

Special NOTE: If you’re running an x86_64 version of Slackware, you’ll need to preface the above command like this:

# ARCH=x86_64 ./pysolfc.SlackBuild

This will let the script know that you’re running a 64 bit system and it will install accordingly.

4. If all went well, the SlackBuild script will have created a .tgz application installer in your /tmp directory. Navigate to the /tmp directory in the terminal:

# cd /tmp

5. Check to see what’s there:

# ls

6. You should see a file called pysolfc-1.1-i486-2_SBo.tgz. That’s the baby! Install it using Slackware’s native pkgtool:

# installpkg pysolfc-1.1-i486-2_SBo.tgz

Voila! That’s it, folks. Easy-peasy. You’ll find an entry for PysolFC in your menu. Click on it and waste a few hours of your life playing some of those funky solitaire card games or that majong stuff.

Have FUN with it…

~Eric

Command Line Editor – Total Geek!

You might be a geek if you know what a command line editor is.

You’re DEFINITELY a geek if you’ve ever used one before.

My command line editor of choice is VIM (Vi Improved). It’s a relatively easy to use, intuitive, clean editor. For all my non-graphical editing chores, this is what I use. There are other alternatives, of course… EMACS, Nano, etc. I started out with VIM and have stuck with it. Pssst! Nano is pretty cool, though.

SecurityBreach, a Moderator over at Scot’s Newsletter Forums – Bruno’s All Things Linux, posted a really neat link for VIM nuts the other day –> 10 Vim Tutorials to Jumpstart Your Editor Skills by Ramesh Natarajan <– Check it out… good stuff!

Anyway… this was just a short one.

Y’all have fun now…

~Eric