ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel
  • »
  • Technology»
  • Computers & Software»
  • Operating Systems

How to not suck at unix

Updated on July 7, 2010

In the beginning...

 This quick guide is intended for the beginning Unix or Linux user.  This is typicaly a Computer Operator at a business or maybe a student. 

This isn't a tutorial, you should probably have a book if you find yourself in this situation.

This is to show some of the common pitfalls I see and what to do.

Training? Yeah ok...

If you are a beginning UNIX user and you now have to use it for your job, you will benefit from bugging a knowledgeable user quickly. This may be someone who has your position, a Systems Administrator, a Developer. Keep in mind not all of these people may know much, you have to figure this out as you go, don't just go by job title.

We will assume you know how to login and have access to a prompt for the next section. You should have some familiarity with basic commands and using an editor to edit files ( on the system.

Alias rm!

Most of the UNIX snobs will not give this advice, but as a beginning operations person who isn't using a menu, this is advised so you don't trash files you didn't mean to.  Identify your shell if you don't know it, "echo $SHELL".  This should be bash, tcsh, ksh.  If it's sh then you may need to ask your System Administrator for a better option.

Each of these can be configured with a file in your home directory, a hidden file (this is a file that starts with a dot (.), you don't see the file when you do a normal listing.  The filename for the tcsh shell is .tcshrc (.cshrc works too), and the other shells follow the same format, shell name and rc (this stands for run command).

In this file, you want to alias "rm" to "rm -i".  You should already have a couple of alias setup anyway, so just copy the format, or you may need to search online for example for your shell.  It's assumed you know how to edit a file, if not, get a friend to help you use the vi editor.

You then want to alias RM to rm -f, this will let you remove files without prompting, if you are really sure.

Understand clobber!

Deleting a file isn't the only thing you can do, it's really easy to overwrite an existing file by using redirect.

Turn on the noclobber option particular to your shell, however it's best to just understand the difference between > and >>.

I've seen time and time again, someone wants to add some data:

cat > important.file.txt

and then the important file is suddenly much smaller.  Please remember to add anything just use >>, best yet don't even mess with > and use the "touch" command to create a file, then add using editor (cut/paste) or cat >> file.

Alias ls!

 You will probably get into the habit of listing files in directories quite often, a good default is

ls -trl

Or you can key ls -ltr, it doesn't matter what order the flags are in.

This will list in long format, and newest files at the bottom.

You may want to alias this to ll.

Use less!

 If you use text files at all, you will want to use a pager.  The typical option is:

more example.file

which will show file page by page, along with other options.

But an even better tool is less, I would alias more to less if you are used to keying more.

Please just don't do this:

cat example.file |more

you are just wasting keystrokes, but don't worry even expert users are caught keying this when it's busy.

Understand dot files!

 Make sure you experiment with using . and ..

Go deep into a directory tree,such as /usr/local/test/bla/test and key

cd ../../ and see what directory you are in "pwd".

Create a new directory in your home directory, /home/user/copy and then go to /tmp and find a small file to copy.  In your home directory /home/user/copy key cp /tmp/smallfile . and see what happens "ls -ltr".

Many users use the .. alias but not so many are using the .


Understand PATH!!

 I added an extra ! since this subject is something that will piss off any knowledgeable UNIX user who has to work with users.

Although this subject may be ahead of beginners stage, it's still explained right away in most UNIX books, but is glossed over.  Get into the habit of keying "which <command>" to see how this command is being found.

You will probably see "shell built in" if you key "which echo".  This means that this is integrated into the shell you are using (the shell itself is a program in a path).

For example you will most likely see "/usr/bin/ls" if you key "which ls".

This means when you key "ls" it is really running "/usr/bin/ls".  How does this happen?  You have this setup in your run command file in the home directory, the PATH variable is assigned some directories typically by default. Key "echo $PATH" and see what is displayed.

If you have a special directory that containes utilities you often have to use, and you spend a lot of time changing to that directory, you may consider adding this directory to PATH to save time.

Some hardcore people may even suggest that a beginner not even run any command unless it's using absolute path, so everything you run will start with root directory /.

So instead of running "echo test", you would run "/usr/bin/echo test".  This is a curious example as echo is a built in shell command, but there is also another version in /usr/bin/ typically.  Which one do you think would be more portable to use?

The stuff in the UNIX books about PATH and absolute and relative paths may be a little dry, but this is essential to visualizing things and really understanding how the programs work later on. 


 There is plenty more, but this should cover a few things I've seen over the years.

The one last thing, learn how to use man.  Key "man man".

If man pages are not installed, find a system in which they are, or complain to your System Administrator.  Most man pages are online now anyway.


    0 of 8192 characters used
    Post Comment

    No comments yet.