|
Basic Linux TrainingLesson 5: Unix Commands and Concepts
Table of Contents
FilesystemIf you are comfortable at the DOS prompt, you should see a lot of similarities in Linux; if most of your experience has been in Windows, the command line may seem a little awkward at first.Remember from an earlier lesson that Linux has an hierarchical, unified filesystem (directories within directories; and files, directories, and device drivers are treated as files), supports 256-character filenames (avoid symbols and punctuation except for the dot (.) and note that you can have more than one nonadjacent dots in the filename - e.g. this.is.okay). All command line entries are case sensitive. Also note that Linux uses the slash (/) rather than the backslash (\) you've been using in DOS. There is extensive online help available on any command on your system called the man pages (or manual pages); type in man CommandInQuestion to get a summary of what the command does and a brief summary of the options. Unfortunately, using the man pages is not an efficient or effective way to learn Unix commands, but is often helpful with syntax. Linux, like all Unix, assumes you know what you're doing and that you do not make typographical errors. Linux, like all Unix, will execute whatever command you give it - all that matters is that it's a valid command. If it's not what you intended, that's your mistake, so don't blame it on the operating system! This operating system allows you to do your work without constantly nagging you. There are four types of file:
PromptIf you login as root, the prompt will be machinename:~# and if you login as user, the prompt will be machinename:~$.The tilde character (~) represents the home directory; appended to the end of a filename, it means a backup of a file that has been edited (the file as it existed before it was last edited, and if your configuration is set up to make backups).
Listing DirectoriesIf you are using bash - the Bourne Again Shell - you can get a listing with dir, or ls (with any shell). The default is to list files in alphabetical order (capitals and numbers first)Some of the most useful options with ls are:
One of the first things you should learn is about navigating through the directories. As in DOS, the current directory is represented by a single dot (.); the parent directory is represented by double dots (..). The command for change directory is cd so let's go to a more interesting directory such as /etc for some examples. cd /etc ls -lThis directory is mostly system administration files, but run ls -l and one of the first things you'll notice is that the listing is very long. (To page back through the listing use Shift+PageUp; to page down use Shift+PageDown.) Near the top of the listing is X11 with a hyphen and greater than symbol (->; sort of like an arrow) and /var/X11R6/lib/ indicating a link to that location; also notice that the permissions begin with an l, while most begin with a hyphen (-) indicating a file, and some permissions begin with a d indicating a directory. cd /bin ls -lAll the files here are binaries and end with an asterisk (*). cd ~There are hidden files beginning with a dot (.); usually your configuration files and files derived from your configuration, e.g. .bash.history
PermissionsFor security reasons, all Unix systems including Linux have file permissions which allow you to control access to directories - who can read, write, or execute a file or command in a directory.In the extreme left is either a d or hyphen (-) indicating whether this is a directory or a file (occasionally you will also see an l indicating a link). Then you see three groups of the same three letters in the same order: r for read, w for write, x for execute, and the hyphen (-) for no permission given in that type. The first group of three letters is for the owner, the second group for the group, and the third the world. Whoever creates the file is the owner, and if more than one person is working on a project or needs access to this file they are given permission as a group, and finally how the file is open to anyone who has access to the system (the world).
chmod, chown, chgrpThe command to change file permissions is chmod (change mode). There are two ways for doing this: the numeric system and the symbolic system.The numeric system uses numbers to track permissions. Using the table below you add together the numeric equivalent for the permissions you want. 400 - owner has read permission 200 - owner has write permission 100 - owner has execute permission 040 - group has read permission 020 - group has write permission 010 - group has execute permission 004 - world has read permission 002 - world has write permission 001 - world has execute permissionThus chmod 764 SomeFile gives the owner permission to read, write, and execute SomeFile; the group has permission to read and write; the world permission to read only. The other method for changing modes is the symbolic method. With this method, you have to know the existing permissions because the commands are added or removed relative to how permissions are currently set. The plus sign (+) adds a permission, the minus sign (-) removes a permission. u - user (owner) g - group o - other (world) a - everyone - user, group, and other r - read permission w - write permission x - execute permission t - sticky bitThus chmod g+x SomeFile gives permission to the group to execute SomeFile. In the past Unix crackers used to get around the permissions by messing around with entire directories. The way to prevent this is to set restrictive permissions for the directory using the sticky bit, which makes the directory accessible only to the owner and root without affecting how the individual file permissions are set. chmod -t TheDirectoryYou can also change the owner with the chown command, and change the group with chgrp.
Linking FilesRather than having multiple copies of a file, Linux uses linking to one file to save disk space and administrative headaches trying to keep multiple copies up to date and synchronized. Linux supports two types of links, hard links and symbolic links.Hard links are set with the command ln FileName /NewDirectoryLocationThe problem with hard links is that Linux treats all hard links equally, and before you can delete the original file, you have to remove all hard links. On the other hand, symbolic links don't need to be physically removed in order to delete the file. (There are some other differences between hard links and symbolic links, but irrelevant to this discussion; consult the man pages.)
WildcardsLinux has three types of wildcards - the question mark (?), which is used to match a single character, the same as in DOS; the asterisk (*), which is much more expansive than anything in DOS because it can be used to return any number of letters at the beginning or end of an expression; and the final wildcard used to return specific characters as defined within brackets ([ ]).
ProcessesA shell acts as the intermediary between the user and the operating system, interpreting your commands into a form the operating system can understand. The shell has the capacity to run multiple commands at one time, and can run commands in the background using the ampersand (&) after the command.Multiple requests to the shell are called processes. As these requests are made, beginning with init during boot, the shell numbers them. These numbers are important if you want to stop a process: use the command ps to to see a list of current processes, then the command kill and the number of the process you want to stop.
AssignmentsBeginning with this lesson, there are reading assignments in the new textbook. If you have Running Linux do the reading assignment for it; if you have A Practical Guide to Linux do the reading assignment for it. I don't expect you to have both textbooks, so don't write asking about it.Textbook: Running Linux
Textbook: A Practical Guide to Linux
Terms and Concepts: Define and add these to your glossary:
Start bringing your glossary up to date; I want to see how you're doing after Lesson 6. I have some addition notes on passing parameters to the kernel, LILO, and some of the most common installation problems which I will upload separately from the lesson on Friday. Online:
http://home1.gte.net/henryw/basic/basic05.html
Copyright © 1997, 1998 Henry White. All Rights Reserved.
|
|||||||||||||||||
With any suggestions or questions please feel free to contact us |