Online Documentation Server
 ПОИСК
ods.com.ua Web
 КАТЕГОРИИ
Home
Programming
Net technology
Unixes
Security
RFC, HOWTO
Web technology
Data bases
Other docs

 


 ПОДПИСКА

 О КОПИРАЙТАХ
Вся предоставленная на этом сервере информация собрана нами из разных источников. Если Вам кажется, что публикация каких-то документов нарушает чьи-либо авторские права, сообщите нам об этом.




Basic Linux Training

Lesson 5: Unix Commands and Concepts


Table of Contents


Filesystem

If 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:

  • ordinary files - text files (plain vanilla ASCII), data files (contain special characters not contained in the ASCII set you are familiar with), command text files (shell scripts), and executable files (binaries);
  • directories;
  • links (we'll get into this below);
  • special device files (physical hardware)
The main subdirectories (and contents) are:
  • /bin - binary files;
  • /boot - information need to boot the system;
  • /cdrom - your CD-ROM drive;
  • (/dos) - your DOS partition;
  • /dev - device drivers;
  • /etc - miscellaneous files (mostly system administration);
  • /home - home directories for users;
  • /lib - programming libraries;
  • /tmp - temporary files;
  • /usr - commands;
  • /var - files that define the system.
(There may be some slight differences between distributions.)


Prompt

If 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 Directories

If 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:

  • -a - lists all files, including hidden files;
  • -A - lists all files, except the current and parent directory;
  • -c - sorts file by time (oldest first);
  • -d - lists only the name of a directory, not its contents;
  • -l - lists in long format (showing permissions and other details);
  • -r - lists in reverse order;
  • -t - sorts files by time (newest first);
  • -x - lists all files across the page instead of in columns.
Reading from the far right you have the links, filename, date and time the file was last modified, the file size (in bytes), the name of the group and owner. The number to the immediate left of the owner is the number of links to the file. (Links will be discussed below, so for the time being think of it as a way for one copy of a file to appear to be in several locations.) The long group of letters and hyphens on the left are the permissions.

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 -l
This 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 -l
All the files here are binaries and end with an asterisk (*).
        cd ~
ls -a
There are hidden files beginning with a dot (.); usually your configuration files and files derived from your configuration, e.g. .bash.history


Permissions

For 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, chgrp

The 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 permission
Thus 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 bit
Thus 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 TheDirectory
You can also change the owner with the chown command, and change the group with chgrp.


Linking Files

Rather 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 /NewDirectoryLocation
The 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.)


Wildcards

Linux 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 ([ ]).


Processes

A 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.


Assignments

Beginning 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

  • Chapter 4: Unix Commands and Concepts, p.85-115

Textbook: A Practical Guide to Linux
(Do the review exercises at the end of each chapter, but do not submit it to me unless I ask for it in the lesson assignments.)

  • Chapter 2: Getting Started
  • Chapter 4: The Linux Filesystem

Terms and Concepts:

Define and add these to your glossary:

  • .dir_colors or .DIR_COLORS
  • awk
  • cat
  • cd
  • chdir
  • chgrp
  • chmod
  • chown
  • echo
  • ed
  • export
  • fg
  • forking
  • fs
  • kill
  • ls
  • MANPATH
  • more
  • PATH
  • ps
  • pwd
  • rm
  • rmdir
  • sed
  • set
  • setenv
  • sort
  • tr
  • vi
  • virtual console
  • virtual desktop

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:


Go to Basic Linux Index


http://home1.gte.net/henryw/basic/basic05.html

Date last revised: 25 May 1998


Copyright © 1997, 1998 Henry White. All Rights Reserved.
Reproduction or redistribution without prior written consent is prohibited.
Address reprint requests and other inquiries to henryw@gte.net.



With any suggestions or questions please feel free to contact us