-
December 14th, 2001, 03:06 AM
#1
*nix Commands: 103 - Where am I???
*nix Commands Basics: 103 - Where Da Heck Am I?
Ok. So thus far we've created some files, checked out their permissions, figured out how to get help and figured out who was on the system but we haven't figured out where we are on the system yet. If you've gotten this far, you have already installed some linux or unix distro. You may understand some things but perhaps not all things. One of the common issues that crops up is the ability for those familar with the Microsoft environment and partitions switch to the Unix environment. Within windows we know of locations like c:/windows (generally a win95/98 system location); c:/winnt (windows NT or 2000 system location); c:/program files (installed programs); c:/temp (location for temporary files), etc.
To help us, I've listed the main folders found in default installations of *nix and Linux (mostly of the System V Release 4 or SVR4 versions).
/bin or /sbin - basic commands needed for minimal system operation. If /sbin is present, then /bin is usually a link to /usr/bin
/dev- devices files for terminals, disks, modems, network cards, etc.
/etc- configuration and startup files; lilo.conf, inetd.conf, rc.d folders, etc.
/lib- C compiler files
/tmp- location for temporary files; will often disappear during reboots (as if you'd ever reboot)
/proc- location of all presenting running processes
/mnt- virtual locations to access cdroms, floppies and other removable media
/usr/bin- executable binary files
/usr/games- some games and other diversions (look for banner and quotes)
/usr/include- C header files
/usr/sbin- System maintenance files
/usr/lib- support files for many standard Unix programs
/usr/man- them manual pages
/usr/share- common files found on multiple systems, often includes man pages
/var/log- a variety of system logs
/var/spool- directories for spooling for printers, UUCP, mail, etc.
/var/tmp- another location for temporary files; will NOT disappear during reboots
/usr/local- programs you install local
/usr/local/bin- local executable binary files
/usr/local/etc- local system command and configuration files
/usr/local/lib- local support files
/usr/local/sbin- local system maintenance commands
/usr/local/src- source code for files found in /usr/local/*
/kernel - for Solaris installs only; files needed to load kernel
/boot - for Linux installs only; files needed to load kernel
In the Microsoft environment we are able to see separation of partitions as identified by drive letters like c:,d:,e:, etc. A and B are reserved often for floppy drive use. In the *nix environment the partitions are not seen as separate entities but rather one environment, all under root /. Much like the Microsoft environment I can have a primary partition with an extended partition with as many divisions as I wish. To see how your *nix system is divided we can use:
df -options: shows the disk usage by the filesystem. It's most common usage or most beneficial usage for most people would be df -h. The -h indicates human usage in percentages and megabytes. For my system I got back:
FilesystemSizeUsedAvailUse% Mounted on
/dev/hdb12.1G702M1.2G36%/
/dev/hda148M3.4M41M8%/boot
This means that I have two drives. The identifier /dev/hdx indicates an IDE drive and which drive, first, 2nd,etc. In this case my 2nd drive, the larger of the two, has root / while the first drive, the smaller of the two, has /boot location. But as you can see from my ls of / shows:
[root@CR236753-B /]# ls
bin boot dev dtk etc home lib log lost+found misc mnt opt proc qmail root sbin service tmp usr var
As far as *nix is concerned, everything is under /. This is where the filesystem begins. Remember, / in *nix is root. This is where navigation begins. / at the beginning of any path is an ABSOLUTE path. (I often tell students that "absolute paths must begin with root"). A RELATIVE path can begin with anything else. If I was in the directory, /usr/local/src and wanted to get to /etc I could simply type cd ../../../../etc if I was using a relative path. If I wanted to get to a directory in my home directory, say exploits, I would only need to type cd ~/exploits. ~, pronounced tilde, represents the home directory. And how do you know where you are?
pwd: shows present working directory. This will show the absolute path of your present location or where you are in the filesystem.
Often, it's a good idea to make a graphic of your filesystem until you get comfortable with navigating through. (you don't need to do all the directories. Root, home directories, etc, bin, var and mnt would be the ones that most people would use). If you aren't sure where you are just get yourself back to root (cd /).
Now, depending on the *nix system and whether you are in gui or text mode you may need to manually mount the cdrom or floppy. In windows this is pretty much done for us when we double-click on a floppy drive or cdrom drive. It sends a signal down the data cable, indicating that the user has requested to see this media.
Since we have no drive letters to indicate cdrom or floppy drives, we need to give them a "mount point" or location under / that we can access them from. To do this we use:
mount device location: check the man page for further details but the more common methods of mounting the cdrom is simply mount /dev/cdrom /mnt/cdrom. The filesystem is picked from the /etc/fstab file (filesystem table). Alternatively, I could also mount a floppy by typing mount /dev/fd0 /mnt/floppy. fd0 stands for floppy drive 0 (primary or A: in windows). The location or mount point is a location that exists in the filesystem. I could simply create a directory under / as /floppy and do mount /dev/fd0 /floppy. When removable media is mounted, it acts as if part of the filesystem, no different. You can also mount your windows partitions (save for NTFS5, which is still in development. You can try it but at your own risk).
Once finished with the media in question I then would use umount /floppy (in the case of the floppy. You should always unmount removable media before removing it.
I had put all this before I introduced the next three commands. I will remind you again that *nix "assumes you know what you are doing". They are powerful commands. Generally, it will never ask you if you are sure you want to do this unless you specify.
cp -options source destination: This is the copy command. It can copy directories and files. To do directories, you will need to use the - r or -R. This option means recursive, which means it will go into the directory and copy the contents as well.
mv -options source destination: This is the move command. It can move directories and files. In addition, the mv is used to rename files by simply giving a new name. For example, mv dumdumfile1 dumdumfile2 would effectively rename my dumdumfile1 to dumdumfile2.
rm -options source destination: This is the remove command. It can delete directories and files. To do directories, you will need to use the - r or -R. This option means recursive, which means it will go into the directory and delete the contents as well.
A small caveat however. Remember that *nix assumes you know what you are doing. Most *nix systems will not ask you if you want to overwrite a file or delete files. This can get some users in trouble. Especially if you are logged in as root. What I am about to tell you is a true story (and no I wasn't the poor fool in this story). An instructor colleague of mine was showing the rm command to students. He deleted a few files and then went on to show rm -r *. Now, * in *nix environment means "0 or more characters". Basically, everything. What this instructor forgot was that he was logged in as root. Yup, that's right boys and girls. He deleted the whole production server in a matter of minutes. Now, Linux got smart and realized that not everyone would be aware as many here. So they put in a default option: the option -i, which means interactive. The command will ask you if you are sure you want to move or copy a file.
I was going to get into the filesystem itself (inodes and superblocks) but have decided to hold that off for now. This information is a lot and it's important to understand where you are in the filesystem before you begin to totally moof around with it. Being comfortable with navigation is important when you do a rm command as you don't want to delete the wrong directory. This is a lot of information and very theorectical. It's harder to transpose this from a classroom environment to a written environment. So if you have questions or something isn't clear, please ask.
-
December 14th, 2001, 04:34 AM
#2
Ah...spreading the *inx information
its a great thing....you looked like you put a lot of time and effort into that post and i just wanted to give you props...hope we can at least convert one winblows user
-
December 14th, 2001, 05:05 AM
#3
directories
My persoal favorite directory is /home but hey, what do I know. That is where all the user accounts are. ie /home/souleman is where my personal information, settings, and files are stored. It is also where you log into the system, unless of course you are root.
Keep up the great work MsMittens. I figured if I look hard enough, I can get your adendum started each time
-
December 14th, 2001, 07:56 AM
#4
Junior Member
-
December 14th, 2001, 08:31 AM
#5
Thanx MsMittens..
These spectacular tutorials will make my holiday goal a lot easier to reach.
hope we can at least convert one winblows user
Can I be the user?!
-Matty_Cross
\"Isn\'t sanity just a one trick pony anyway? I mean, all you get is one trick. Rational Thinking.
But when you\'re good and crazy, hehe, the skies the limit!!\"
-
December 14th, 2001, 03:44 PM
#6
Good tutorial Mittens... Especially for a *nix uber-newbie like me
[shadow]uraloony, Founder of Loony Services[/shadow]
Visit us at
[gloworange]http://www.loonyservices.com/[/gloworange]
-
December 14th, 2001, 06:43 PM
#7
Junior Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|