Results 1 to 8 of 8

Thread: *nix Commands: 101 - Part 1 Tha' Basics

  1. #1
    Just a Virtualized Geek MrLinus's Avatar
    Join Date
    Sep 2001
    Location
    Redondo Beach, CA
    Posts
    7,323

    Post *nix Commands: 101 - Part 1 Tha' Basics

    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.
    Goodbye, Mittens (1992-2008). My pillow will be cold without your purring beside my head
    Extra! Extra! Get your FREE copy of Insight Newsletter||MsMittens' HomePage

  2. #2
    AntiOnline Senior Member souleman's Avatar
    Join Date
    Oct 2001
    Location
    Flint, MI
    Posts
    2,883

    nice

    Wow. Next time I tell someone to rtfm, I can give them a link to teach them how. Very good general start though.

    Don't foget about ls -a. The -a option gives you the ability to list all files, including the hidden ones, in the directory. This can be very useful sometimes. Especially when you mistype something like mkdir .directory And create a hidden directory by accident. For those who don't know, and file/directory that starts with a . (period) is hidden.

    One other thing that might be helpful for you MsMittens. Although many people in here are Windows people, a lot of them still know dos. A quick reference to the equivalent dos command can be very helpful, unless you wanted to do a quick reference tutorial also. ie:
    clear cls Used to clear the screen..........

    I made a quick reference sheet for a class once, and the other students at least clamed that it was helpful.

    It looks like you are off to a good start though MsMittens. Keep it up.

  3. #3
    Old-Fogey:Addicts founder Terr's Avatar
    Join Date
    Aug 2001
    Location
    Seattle, WA
    Posts
    2,007
    I'm speaking as a newbie to *nix who got interested and then forgot about it a while ago because he couldn't get online in it, and tired of rebooting just to look for fixes for things.

    Just to emphasize...

    ALMOST EVERYTHING IN *NIX IS CAPS-SENSITIVE, UNLIKE DOS. This includes filenames, command arguements, etc.

    If something doesn't work, and you could swear it should, check the capitalization of letters.

    Also, don't forget the --color ls arguement. When I started on Caldera OpenLinux 2.2, I found that it was INVALUABLE to help tell me what was what in this strange sometimes extension-less world...

    Yes, folks, in *nix files are often without extensions, in other words, they don't have to follow the 8.3 format of eight digits, a period, and three digits. Figuring out what kind of file is what can sometimes be a bit confusing, but ls --color should help make it clearer.

    Also, most (but not all) commands support the -h arguement, which means, basically 'Help'. If that doesn't work, you can try --help as an arguement. When in doubt, check the manual.

    It might we worth your time to get a quick reference guide to common *nix commands, such as Linux for Dummies: Quick Refernce, which contains many common commands and how to use them.

    The GUI for Linux that many people see is not actually part of the basic system. Just to clear that up! X-windows runs on top of Linux, it itself is not a *nix environment.
    [HvC]Terr: L33T Technical Proficiency

  4. #4
    Senior Member
    Join Date
    Nov 2001
    Posts
    185
    Wow, I get busy for a few weeks and come back to AO and find a very well written post like this one and it makes me wonder what else I have missed.

    MsMittens, that is one damn fine Unix post you have there.

    My .02 if I may... To all the newbies, get to know man -k, it is a lot of fun and it sure makes looking up what you want to know really easy. Kind of like a 1970's version of `Ask Jeeves'

    usage:

    [you@youruberlinuxbox:~]$ man -k samba /*or whatever you feel like looking up */

    Once again MsMittens, I am impressed.
    Know this..., you may not by thyself in pride claim the Mantle of Wizardry; that way lies only Bogosity without End.

    Rather must you Become, and Become, and Become, until Hackers respect thy Power, and other Wizards hail thee as a Brother or Sister in Wisdom, and you wake up and realize that the Mantle hath lain unknown upon thy Shoulders since you knew not when.


  5. #5
    Senior Member
    Join Date
    Oct 2001
    Posts
    689

    Post

    This was an excellent tutorial especially to one as new as I am to linux. I hope that you can list even more commands maybe in a format saying what the linux equivalent to a Dos command is.
    Wine maketh merry: but money answereth all things.
    --Ecclesiastes 10:19

  6. #6
    Senior Member
    Join Date
    Nov 2001
    Posts
    1,255
    Great beginner's tutorial MsMittens!

    Originally posted by Terr
    Also, most (but not all) commands support the -h arguement, which means, basically 'Help'. If that doesn't work, you can try --help as an arguement. When in doubt, check the manual.
    While this is generally true, I've found that anything that displays file sizes etc., treats -h as equal to --human-readable.

    ls is an example of this.

    Here's some sample output:

    [chsh@comp test]$ ls -l
    total 14544
    -rw-rw-r-- 1 chriss chriss 3211264 Dec 11 12:01 file1
    -rw-rw-r-- 1 chriss chriss 11661312 Dec 11 12:01 file2
    [chsh@comp test]$ ls -lh
    total 15M
    -rw-rw-r-- 1 chriss chriss 3.1M Dec 11 12:01 file1
    -rw-rw-r-- 1 chriss chriss 11M Dec 11 12:01 file2


    It's a really handy thing to know if you do general maintenance.

    Originally posted by ThePreacher
    This was an excellent tutorial especially to one as new as I am to linux. I hope that you can list even more commands maybe in a format saying what the linux equivalent to a Dos command is.
    Well, for starters, here's a quick list of the linux commands and their DOS counterparts (note that most of the DOS commands are rather limited, while the linux commands are not):

    Code:
    Linux  =  DOS
    ===============
    cd = cd / chdir
    mkdir = md / mkdir
    echo = echo
    grep = find
    more = more
    clear = cls
    cp = copy
    mv = move
    chmod = attrib
    netstat = netstat
    There's a fair bit more of them, but this is just what I remember off the top of my head. I should probably mention the fact that I remember about a dozen DOS commands, but well over fifty or sixty linux commands. There are simply more of them. For instance, on linux you have the touch command, which is the equivalent of running echo "" > filename on DOS.

    There's simply a tonne more functionality in linux, and I'm glad to see someone post a decent mini-tutorial on the various commands.
    Chris Shepherd
    The Nelson-Shepherd cutoff: The point at which you realise someone is an idiot while trying to help them.
    \"Well as far as the spelling, I speak fluently both your native languages. Do you even can try spell mine ?\" -- Failed Insult
    Is your whole family retarded, or did they just catch it from you?

  7. #7
    AntiOnline Senior Member
    Join Date
    Oct 2001
    Posts
    514
    Good post MsMittens! As normal...

  8. #8
    Senior Member
    Join Date
    Nov 2001
    Posts
    185
    ***************** quote:
    ALMOST EVERYTHING IN *NIX IS CAPS-SENSITIVE, UNLIKE DOS. This includes filenames, command arguements, etc.
    << Essentially Unix is case sensistive because it is written in C, and C is *very* case sensitive. Just remember that in Unix like systems that the files antionline AntiOnline Antionline are all different. You will not be using any caps on the command line unless it is part of a file name or directory name. Also keep in mind that Unix treats a space as an escape character. So if you are on a Windows box for example, and you want to change directory into Prgram Files, you would have to do $cd 'Program Files' or some other quoting to tell the shell that Program and Files are not two different places.

    *************** quote:
    If something doesn't work, and you could swear it should, check the capitalization of letters.
    << no native unix commands should use caps. So yes, DOS users will need to get into the habbit of typing everything exactly the way it is spelled. Also it may not work due to permissions, using ls -l and lsattr (Linux only) you should be able to determine if you have permissions to read - write - or execute the given file.

    ***************quote:
    Also, don't forget the --color ls arguement. When I started on Caldera OpenLinux 2.2, I found that it was INVALUABLE to help tell me what was what in this strange sometimes extension-less world...
    << This is true, but allow me to caution that this is specified in the file /etc/DIR_COLORS and can and often is different from one box to another. Even different distro's use different colors. In addition to using color use ls -F to see what something is. And executeable will have an * after it, a directory will have a / after it and so on, plain text has no marker. Combined with -a (all files) -l (long listing) -F suffix type (ls -alF) you have a pretty handy tool. Check out man ls for more neat stuff you can do.


    Check out man -k. It is your 'Linux in a Nutshell' already installed on your system.
    Know this..., you may not by thyself in pride claim the Mantle of Wizardry; that way lies only Bogosity without End.

    Rather must you Become, and Become, and Become, until Hackers respect thy Power, and other Wizards hail thee as a Brother or Sister in Wisdom, and you wake up and realize that the Mantle hath lain unknown upon thy Shoulders since you knew not when.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •