| Introduction to Unix - Lesson 1 |
| Written by Luke MacNeil | ||||||||||
| Friday, 14 September 2007 20:14 | ||||||||||
|
The following is the first in a series of documents that I am drafting as an Introduction to UNIX for my coworkers. I will frequently post short lessons that build upon each other, until this becomes a giant collection and a complete unix tutorial.
Introduction to UNIX. Lesson 1 The first thing about UNIX that is necessary to understand is that it is a file based operating system. Every single setting is controlled by a flat file…. including the physical devices are attached to the machine. These files can be added, deleted, and edited, which makes it critically important to observe file permissions. The user "root" is also referred to as "Super User", because the root user has full access to modify any file on the OS. While this is necessary in some cases, for the novice, it is also extremely dangerous. Always be very careful when running as the root user, because a mistake that would be impossible in windows, is very possible in UNIX. I will talk more about user accounts later, but for now, always remember: "To heir is human, to really f*** up requires root". All *nix machines (AIX, HP-UX, Solaris, Linux.. etc) are command driven operating systems. Although they do have optional graphical interfaces, the command line interface or CLI, is the primary method of interacting with the machine. There are an infinant number of commands, and it is impossible to memorize them all, so before we go any further I will explain the most important command of all. This is the "man" (manual) command. "man" will give a concise description of each command along with a list of all possible switches and flags, and generally a few practical examples of the command in action. Issuing the command "man man" will give you the manual page of the man command. Next, to get to some practical working knowledge of how to navigate the UNIX command prompt. To those that are familiar with DOS, this will prove to be very similar. Learning UNIX now will give you a considerable advantage over those that don't within the next few years, when Microsoft releases Microsoft Windows Server 2008... One of their main selling points is that they are revamping their CLI interface. A file system consists of files, and directories. Directories contain files, and may also contain other directories. This can be thought of as a regular file cabinet. Inside the cabinet there are folders, inside those folders, other folders. All UNIX systems have the same basic directory structure. This is very important to know. / - root /home - home directory for user files /var - logs /tmp - temporary files /opt - optional third party software /usr - user files (user installed programs... much like the "Program Files" in Win) /bin - essential binary programs (critical executable commands) /sbin - system binary programs (executable commands for system maintenance) /etc - system configuration files /boot - kernel images and conf files /lib - kernel modules and libraries /mnt - mounted filesystems (extra hard drives, usb stuff, cdroms, floppies) /root - root's home directory. /proc - This is a special directory that holds information about the hardware of the machine. This will differ slightly between different machines, but it is the basic frame of the UNIX directory structure. By default, when each user logs onto the machine, he will start out in his home directory. For the root account, you would begin in /root.... for user accounts, you would start in /home/username. The main filesystem commands are "cd" and "ls" cd = "Change Directory" cd /home Change the current working directory to /home. The '/' indicates relative to root, and no matter what directory you are in when you execute this command, the directory will be changed to "/home".
cd httpd Change the current working directory to httpd, relative to the current location which is "/home". The full path of the new working directory is "/home/httpd".
cd .. Move to the parent directory of the current directory. This command will make the current working directory "/home.
cd ~ Move to the user's home directory which is "/home/username". The '~' indicates the users home directory. If at any time you forget where you are in the file system, you can use the "pwd" command to "Print Working Directory" This "cd" command will move you all throughout the filesystem. To see what’s inside a folder, we use the "ls" (list) command. (dir in dos) "man ls" will give you all the switches that work with ls, the combinations therein will allow you to sort the files in any way you can imagine. Generally the way that I sort my files is "ls -ltr" which will give the listing in long format, so I can see the permissions, sort by the modification time, in reverse.... this allows me to see the newest files last. Here is the output: luke@cambridge:/home$ ls -ltr total 32 drwx------ 2 luke users 16384 2006-07-03 17:09 lost+found drwxr-xr-x 22 luke users 4096 2007-06-14 00:01 tcpsyn drwxr-xr-x 2 1002 1002 4096 2007-06-23 09:39 mjamil drwxr-xr-x 3 mythtv mythtv 4096 2007-07-15 22:53 mythtv drwxr-xr-x 100 luke users 4096 2007-09-13 16:05 luke luke@cambridge:/home$ There are many ways to sort files, so play around with ls.... It's one command that you will use every day. Practice using ls and cd to navigate in and out of directories. Poke around. These two commands are not harmful and will not affect performance. Whenever you get lost, use “cd ~” to travel back to your home directory. If you forget where you are type “pwd” Explore, use the man command to formulate different variations of the “ls” command and use what works for you. Everyone does things a little differently, and there is no right or wrong way. There is more than one way to do everything… and the goal is to know as many of them as possible.
Powered by !JoomlaComment 3.20
3.20 Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved."
|
||||||||||

