Linux/Unix Commands Tutorial: Part 1: Basic Commands

Ok. Best to start with the basics. When I teach Unix, we often put the help feature commands later but for this I'm gonna put them at the front. I will assume that you have connected to your linux/unix box either via the Console (direct keyboard access) or via telnet (remote keyboard access). In addition, I'm going to use a technique that I do use in class but that many *nix gurus cringe at: comparing it to DOS. This is to help new users to *nix feel more comfortable in the environment.

Before getting into the commands, some clarification needs to be presented. Many of us are children of Microsoft. We get very used to how Microsoft presents its commands and switches. This are slightly different in the Unix/Linux World. Don't get frustrated if you get your commands and options mixed up. Also, note the terminology. That's important part of the culture of *nix (Editor's Note: the term *nix is a bit of slang that refers to the many families of UNIX &#174 (UNIX is trademarked by AT&T) and the many families of Linux. For more info on the history of *nix, check out http://perso.wanadoo.fr/levenez/unix/. The graphic is impressive! ).

In addition, each command or utility are often written by different people. Unlike what is found in the Microsoft world, commands in *nix are their own beasties and do not follow a set of rules. For example, in the Microsoft world I know that ctrl+x means to remove text and that ctrl+v means paste texts. These command sequences are used through a variety of applications. In *nix, the letter options that are present in one command may have different meaning in another. So remember that each command is unique. Do not be surprised if the help seems to be written by another person. It was!

There are a lot of commands. Last check, around 300+. (On my Red Hat 7.1 I was able to count 931 commands). I won't cover all of these but I will cover the more commonly used commands and their benefits to you as a budding *nix guru.

References used/recommended:

For my personal reference I use the books below as well as the man command and yapping with colleagues in the AO irc chat.

-- UNIX in a Nutshell: A Desktop Quick Reference for SVR4 and Solaris 7 (3rd Edition) by Arnold Robbins and Daniel Gilly. ISBN: 1565924274 Publisher: O'Reilly & Associates.(Considered THE *nix reference book -- this is a must have. And no I have no idea what the critter is on the cover)

-- UNIX SYSTEM V: A Practical Guide by Mark G. Sobell. ISBN: 080537566X Publisher: Addison-Wesley Pub Co. (Excellent intro book into *nix)

--UNIX System Administration Handbook by Evi Nemeth, Garth Snyder, Scott Seebass and Trenet R. Hein. ISBN: 0130206016 Publisher: Prentice Hall PTR (While pricey this one covers the major *nix OSes from an administrator's point of view. Good for intermediate users)

Cavaets:

Now, *nix commands are really robust and DOS is truly a striped-down cheap version of *nix in many regards. Many of the commands were ported over to DOS. If you are new to *nix, think of it as "DOS on steriods" or "DOS with an attitude". In addition, while there is help there are no assumptions by the OS. Unlike in DOS, which assumes you are a "dumb user" and thus need reminding as to what you are about to do, *nix does not make those assumptions (except for Linux, which put in safety precautions to prevent accidental deletes of the system -- and yes, it's been done!). The only assumption *nix makes is that "you know what you are doing". Which can be dangerous with me around sometimes.

Commands:

For *nix commands we do need to understand the order in which the command, option and argument, or in DOS terms parameter, appear. When giving commands to the system they generally follow this order:


command -option argument


The command represents what you want to do; the option(s) represent how it is to be done; and finally, the argument represents where or what it will be done to.

man (command): This will show you information about the commands you use a screenful at a time. What you often find at the beginning is how the command is used (syntax) and a list of the options available. To continue through the help, simply hit the space bar. You can navigate to previous pages by hitting w. When you've gotten the information that you need, simple hit q or ctrl+c. Now, the actual help pages or manual pages (hence, the command name) can sometimes be cryptic in nature but there are some tricks.

If you want you can read through each of the pages to learn about the indepthness of the command and its original intent. If, however, you are looking for all the features, hit the space bar a few times until you find a heading OPTIONS. This will list the options available for a command and give some details about the options.

The man pages are divided into 8 sections:

1 - user commands

2 - system calls

3 - C library functions

4 - devices and network interfaces

5 - file formats

6 - games and demos

7 - environments, tables and troff macros

8 - system maintenance

Some commands are located in multiple sections. If you need to see the man page for the command but only from a specific section, you would type in the command as man section number command. For example, the uptime (will be covered in a later tutorial) has references or similar commands in other sections like utmp. If I wanted to get info about utmp, I'd type man 5 utmp.

Now if you are looking for a specific command, using the option -k can be helpful. This allows for a keyword search. Be aware, however, that this searches not only in the names of the commands but the text of the command man pages itself. Another option is the -f, which lists the single line descriptor of what the command is for.

passwd: This command is one that should be used on a regular basis. It allows a user to change their password. By simpling typing the command, you will get asked for the existing password. And then asked for a new password and confirm it. You will notice that no little *** appear as you type in your password. So be careful when typing. In addition, the user root can change anyone else's password without knowing the existing password. NEVER log in as root. I often refer to root as "god of the system". Usually when I'm wearing my www.thinkgeek.com t-shirt that says "Bow before me, for I am root". A command known as sudo or su will be discussed in a later tutorial to help admin without being logged in as root.

exit or ctrl+D: using either the command or keyboard sequence will help you log out of your present session. (Editor's Note: if you were in my classroom and did not log out, your name would be put up on the board under the heading of Wall of Shame. Do it twice and you'd bring in timbits aka donut holes in for the whole class)

clear: clears the screen. All this typing would probably fill the screen, and thus, you'll need to bring your cursor back to row 1, column 1.

date: gives the current date and time. The date and time can only be set by root.

cal month year: shows a simple monthly calendar. Remember that *nix recognized the issue of Y2K long ago. And as such, uses a 4-digit year. Typing cal 3 70 is not the same as cal 3 1970. The calendar goes from 01 to 9999. (If your computer can actually go beyond 9999, that'd be an impressive feat.)

who or w: shows who is on the system. It can also show what their ip address is to connect (if they are a remote user using telnet) and what commands/utilities they are using at the time of the who.

ls -options arguments: gives a listing of directory. For now I will deal with the more common options. I will get into the more detailed ones when I discuss in the next tutorial Absolute and Relative Paths as well as the concept of inodes. This command is akin to the dir command found in DOS. ls by itself gives a wide-listing or name only listing of files and directories.

Adding the -l gives it a long-listing that includes things like ownership of files, date of creation/modification, size, name and permissions (I will cover these when I cover the wonderful command chmod). Option -F identifes what items are directories (denoted by the / after the name), files with the execute permission set (denoted by the * after the name) and simple files (denoted by nothing after the name). Note that in *nix there are no extensions to associate files with programs, like there is in the Microsoft world. The permissions and contents of the files tell the system what to do with it. Some extensions, like .c, .gz, .tar, and .rpm, are associated in more modern systems but do not rely on those. Files and directories can have names that are up to 256 characters in length.

I think I will end Part 1 here. It's late and I'm tired. This should give any budding *nix guru something to start with. I look forward to comments and hopefully will have Part II in a few days.