[ previous ] [ Contents ] [ 1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ 6 ] [ 7 ] [ 8 ] [ 9 ] [ 10 ] [ 11 ] [ 12 ] [ 13 ] [ 14 ] [ 15 ] [ A ] [ next ]
This section provides a basic orientation to the Debian world for the real newbie. If you have been using any Unix-like system for a while, you probably know everything I explained here. Please use this as a reality check.
After the installation of the Debian system on your PC, you need to learn few things to make it useful. Let us give you an express training.
Upon rebooting the system, you will be presented either the graphical login screen or the character based login screen depending on your initial selection of packages. For the sake of simplicity, if you are presented with the graphical login screen, press Ctrl-Alt-F1 [3] to gain the character based login screen.
Suppose your hostname is foo, the login prompt looks like:
foo login:
Type root , press the Enter-key and type the password which you selected during the install process. In the Debian system, following the Unix tradition, the password is case sensitive. Then the system starts with the greeting message and presents you with the root command prompt waiting for your input. [4]
foo login: root Password: Last login: Sun Oct 26 19:04:09 2003 on tty3 Linux foo 2.4.22-1-686 #6 Sat Oct 4 14:09:08 EST 2003 i686 GNU/Linux Most of the programs included with the Debian GNU/Linux system are freely redistributable; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. root@foo:root#
You are ready to perform the system administration from this root command prompt. This root account is also called superuser or privileged user. From this account, you can do anything:
read, write, and remove any files on the system irrespective of their file permissions
set file ownership and permission of any files on the system
set the password of any non-privileged users on the system
login to any accounts without their passwords
It is extremely bad idea to share the access to the root account by sharing the
password. Use of program such as sudo(8)
is the good way to share
the administrative privileges.
Please note that it is considered a good Unix habit to login to the
non-privileged user account first even when you plan to perform administrative
activities. Use commands sudo, super, or su
-c to gain the limited root privileged when needed. See Working more safely – sudo
,
Section 9.2.4. [5]
I think learning a computer system is like learning a new foreign language.
Although tutorial books are helpful, you have to practice it with helper tools.
In this context, I think it is a good idea to install few additional packages
such as mc
, vim
, lynx
,
doc-linux-text
, and debian-policy
. [6]
# apt-get update ... # apt-get install mc vim lynx doc-linux-text debian-policy ...
If you already had these packages installed, nothing will be installed.
During the installation, you usually created a non-privileged user account who receives e-mails sent to the root account. [7] Since you do not want to use this special user account for the following training activities either, you should create another new user account.
Suppose you wish this new username to be penguin, type:
root@foo:root# adduser penguin ... answer all the questions
will create it. [8] Before going further, let's learn few things first.
In the default Debian system, there are six independent pseudo-terminals available, i.e., you can use the PC's VGA character console screen as 6 switchable VT-100 terminals. Switch from one to another by pressing the Left-Alt-key and one of the F1–F6 keys simultaneously. Each pseudo-terminal allows independent login to accounts. The multiuser environment is a great Unix feature, and very addictive.
If you accidentally typed Alt-F7 on a system running the X Window System and the console screen displays graphic screen, regain the access to the character console by pressing Ctrl-Alt-F1. Just try to move to different console and come back to the original one to get used to this.
Just like any other modern OSs where the file operation involves caching data in the memory, the Debian system needs the proper shutdown procedure before power can safely be turned off to maintain the integrity of files. Use the following command from the root command prompt to shutdown the system:
# shutdown -h now
This is for the normal multiuser mode. If you are in the single-user mode, use following from the root command prompt:
# poweroff -i -f
Alternatively, you may type Ctrl-Alt-Delete to shutdown. [9]
Wait until the system displays "System halted" then shut off power. If the APM or ACPI function has been turned on by the BIOS and Linux properly, the system will power down by itself. See Large memory and auto power-off, Section 3.8.4 for the detail.
Now you are ready to play with the Debian system without risks as long as you use this non-privileged user account penguin. [10]
Let's login to the penguin. If you are at root shell prompt, type Ctrl-D [11] at the root command prompt to close the root shell activity and return to the login prompt. Enter your newly created username penguin and the corresponding password. [12] You will be presented with the following command prompt.
penguin@foo:penguin$
From here on, the example given will use simplified command prompt for the sake of simplicity. I will use:
# : root shell prompt
$ : non-privileged user shell prompt
We will start learning the Debian system first with the easy way Midnight Commander (MC), Section 4.2 and later with the proper way Unix-like work environment, Section 4.3.
Midnight Commander (MC) is a GNU "Swiss army knife" for the Linux console and other terminal environments. This gives newbie a menu driven console experience which is much easier to learn than standard Unix commands.
Use this command to explore the Debian system. This is the best way to learn. Please explore few key locations just using the cursor keys and Enter key:
/etc
and its subdirectories.
/var/log
and its subdirectories.
/usr/share/doc
and its subdirectories.
/sbin
and /bin
In order to make MC to change working directory upon exit, you need to modify
~/.bashrc
(or /etc/bash.bashrc
, called from
.bashrc
), as detailed in its manual page, mc(1)
,
under the -P option. [13]
$ mc
MC takes care of all file operations through its menu, requiring minimal user effort. Just press F1 to get the help screen. You can play with MC just by pressing cursor-keys and function-keys. [14]
The default is two directory panels containing file lists. Another useful mode
is to set the right window to "information" to see file access
privilege information, etc. Following are some essential keystrokes. With the
gpm
daemon running, one can use a mouse, too. (Make sure to press
the shift-key to obtain the normal behavior of cut and paste in MC.)
F1: Help menu
F3: Internal file viewer
F4: Internal editor
F9: Activate pulldown menu
F10: Exit Midnight Commander
Tab: Move between two windows
Insert: Mark file for a multiple-file operation such as copy
Del: Delete file (be careful—set MC to safe delete mode)
Cursor keys: Self-explanatory
Any cd
command will change the directory shown on the selected
screen.
Ctrl-Enter or Alt-Enter will copy a filename to the command line. Use this
with the cp
or mv
command together with command-line
editing.
Alt-Tab will show shell filename expansion choices.
One can specify the starting directory for both windows as arguments to MC; for example, mc /etc /root.
Esc + numberkey == Fn (i.e., Esc + `1' = F1, etc.; Esc + `0' = F10)
Esc-key == Alt-key (= Meta, M-); i.e., type Esc + `c' for Alt-C.
The internal editor has an interesting cut-and-paste scheme. Pressing F3 marks the start of a selection, a second F3 marks the end of selection and highlights the selection. Then you can move your cursor. If you press F6, the selected area will be moved to the cursor location. If you press F5, the selected area will be copied and inserted at the cursor location. F2 will save the file. F10 will get you out. Most cursor keys work intuitively.
This editor can be directly started on a file:
$ mc -e filename_to_edit $ mcedit filename_to_edit
This is not a multi-window editor, but one can use multiple Linux consoles to achieve the same effect. To copy between windows, use Alt-Fn keys to switch virtual consoles and use "File->Insert file" or "File->Copy to file" to move a portion of a file to another file.
This internal editor can be replaced with any external editor of choice.
Also, many programs use environment variables EDITOR or
VISUAL to decide which editor to use. If you are uncomfortable
with vim
, set these to mcedit by adding these lines
to ~/.bashrc
:
... export EDITOR=mcedit export VISUAL=mcedit ...
I do recommend setting these to vim if possible. Getting used to
vim
commands is the right thing to do, since Vi-editor is always
there in the Linux/Unix world. [15]
Very smart viewer. This is a great tool for searching words in documents. I
always use this for files in the /usr/share/doc
directory. This
is the fastest way to browse through masses of Linux information. This viewer
can be directly started like so:
$ mc -v filename_to_view
Press Enter on a file, and the appropriate program will handle the content of the file. This is a very convenient MC feature.
executable file: Execute command man, html file: Pipe content to viewer software tar.gz, deb file: Browse its contents as if subdirectory
In order to allow these viewer and virtual file features to function, viewable
files should not be set as executable. Change their status using the
chmod
command or via the MC file menu.
MC can be used to access files over the Internet using FTP. Go to the menu by pressing F9, then type `p' to activate the FTP virtual filesystem. Enter a URL in the form username:passwd@hostname.domainname, which will retrieve a remote directory that appears like a local one.
Try http.us.debian.org/debian as URL and browse Debian file archive. See The Debian archives, Section 2.1 for how these are organized.
Although MC enables you to do almost everything, it is very important for you to learn how to use the command line tools invoked from the shell prompt and become familiar with the Unix-like work environment. [16]
In the Unix-like environment, there are few key strokes which have special meanings. [17]
Ctrl-U: Erase line before cursor.
Ctrl-H: Erase a character before cursor.
Ctrl-D: Terminate input. (exit shell if you are using shell)
Ctrl-C: Terminate a running program.
Ctrl-Z: Temporarily stop program. (put it to the background job, see command &, Section 4.3.10.1)
Ctrl-S: Halt output to screen. [18]
Ctrl-Q: Reactivate output to screen.
The default shell, bash
, has history-editing and tab-completion
capabilities to aide the interactive use.
up-arrow: Start command history search.
Ctrl-R: Start incremental command history search.
TAB: Complete input of the filename to the command line.
Ctrl-V TAB: Input TAB without expansion to the command line.
Other important keystrokes to remember:
Ctrl-Alt-Del: Reboot/halt the system, see Install a few more packages after initial install, Section 3.8.1.
Left-click-and-drag mouse: Select and copy to the clipboard.
Click middle mouse button: Paste clipboard at the cursor.
Meta-key (Emacs terminology) is assigned traditionally to Left-Alt-key. Some system may be configured to use Windows-key for Meta-key.
Here, in order to use a mouse in the Linux character console, you need to have
gpm
running as daemon. [19] See Mouse configuration,
Section 3.3.
Let's learn the basic Unix commands. [20] Try all the following commands from the non-privileged user account penguin :
pwd
Display name of current/working directory.
whoami
Display current user name.
file foo
Display a type of file for the file foo.
type -p commandname
Display a file location of command commandname.
which commandname does the same. [21]
type commandname
Display information on command commandname.
apropos key-word
Find commands related to key-word.
man -k key-word does the same.
whatis commandname
Display one line explanation on command commandname.
man -a commandname
Display explanation on command commandname. (Unix style)
info commandname
Display rather long explanation on command commandname. (GNU style)
ls
List contents of directory. (non-dot files and directories) [22]
ls -a
List contents of directory. (all files and directories)
ls -A
List contents of directory. (almost all files and directories, i.e., skip
"..
" and ".
")
ls -la
List all contents of directory with detail information. See The filesystem concept in Debian, Section 4.5.2.
ls -d
List all directories under the current directory.
lsof foo
List open status of file foo.
mkdir foo
Make a new directory foo in the current directory.
rmdir foo
Remove a directory foo in the current directory.
cd foo
Change directory to the directory foo
in the current
directory or in the directory listed in the variable CDPATH. See
cd
command in builtins(7)
.
cd /
Change directory to the root directory.
cd
Change directory to the current user's home directory.
cd /foo
Change directory to the absolute path directory /foo
.
cd ..
Change directory to the parent directory.
cd ~foo
Change directory to the home directory of the user foo.
cd -
Change directory to the previous directory.
</etc/motd pager
Display contents of /etc/motd
using the default pager. See command < foo, Section
4.3.10.9. [23]
touch junkfile
Create a empty file junkfile
.
cp foo bar
Copy a existing file foo
to a new file
bar
.
rm junkfile
Remove a file junkfile
.
mv foo bar
Rename an existing file foo
to a new name
bar
.
mv foo bar/baz
Move an existing file foo
to a new location with a new
name bar/baz
. The directory
bar
must exist.
chmod 600 foo
Make an existing file foo
to be non-readable and
non-writable by the other people. (non-executable for all)
chmod 644 foo
Make an existing file foo
to be readable but
non-writable by the other people. (non-executable for all)
chmod 755 foo
Make an existing file foo
to be readable but
non-writable by the other people. (executable for all)
top
Display process information using full screen. Type "q" to quit.
ps aux | pager
Display information on all the running processes using BSD style output. See command1 | command2, Section 4.3.10.2.
ps -ef | pager
Display information on all the running processes using Unix system-V style output.
ps aux | grep -e "[e]xim4*"
Display all processes running exim
or exim4
. Learn
the regular expression from grep(1)
manual page by typing
man grep. [24]
ps axf | pager
Display information on all the running processes with ASCII art output.
kill 1234
Kill a process identified by the process ID: 1234. See Kill a process, Section 8.5.1.
grep -e "pattern" *.html
Find a "pattern" in all of the files ending with .html in current directory and display them all.
gzip foo
Compress foo
to create foo.gz
using the Lempel-Ziv coding (LZ77).
gunzip foo.gz
Decompress foo.gz
to create
foo
.
bzip2 foo
Compress foo
to create foo.bz2
using the Burrows-Wheeler block sorting text compression algorithm, and Huffman
coding. (Better compression than gzip
)
bunzip2 foo.bz2
Decompress foo.bz2
to create
foo
.
tar -xvvf foo.tar
Extract files from foo.tar
archive.
tar -xvvzf foo.tar.gz
Extract files from gzipped foo.tar.gz
archive.
tar -xvvf --bzip2 foo.tar.bz2
Extract files from foo.tar.bz2
archive. [25]
tar -cvvf foo.tar bar/
Archive contents of folder bar/
in
foo.tar
archive.
tar -cvvzf foo.tar.gz bar/
Archive contents of folder bar/
in compressed
foo.tar.gz
archive.
tar -cvvf --bzip2 foo.tar.bz2 bar/
Archive contents of folder bar/
in
foo.tar.bz2
archive. [26]
zcat README.gz | pager
Display contents of compressed README.gz
using the default pager.
zcat README.gz > foo
Create a file foo
with the decompressed content of
README.gz
.
zcat README.gz >> foo
Append the decompressed content of README.gz
to the end of the
file foo
. (If it does not exist, create it first.)
find . -name pattern
find matching filenames using shell pattern. (slower)
locate -d . pattern
find matching filenames using shell pattern. (quicker using regularly generated database)
Please traverse directories and peek into the system using above commands as a training. If you have questions on any of the console commands, please make sure to read the manual page. For example, these commands are the good start:
$ man man $ man bash $ man ls
Also this is a good timing to start vim
and press F1-key. You
should at least read the first 35 lines. Then do the online training course by
moving cursor to |tutor| and pressing Ctrl-]. See Editors, Chapter 11 to learn more about editors.
Please note that many Unix-like commands including ones from GNU and BSD will display brief help information if you invoke them in one of the following ways (or without any arguments in some cases):
$ commandname --help $ commandname -h
Try also examples in Debian tips, Chapter 8 as your self training.
Now you have some feel on how to use the Debian system. Let's look deep into the mechanism of the command execution in the Debian system. [27]
A simple command is a sequence of
variable assignments (optional)
command name
arguments (optional)
redirections (optional: > , >> , < , << , etc.)
control operator (optional: && , || ; <newline> , ; , & , ( , ) )
For more complex commands with quotations and substitutions, see Command-line processing, Section 13.2.6.
Typical command execution uses a shell line sequence like the following: [28]
$ date Sun Oct 26 08:17:20 CET 2003 $ LC_ALL=fr_FR date dim oct 26 08:17:39 CET 2003
Here, the program date
is executed in the foreground job. The
environment variable LC_ALL is:
unset (system default, same as C) for the first command
set to fr_FR (French locale) for the second command
Most command executions usually do not have preceding environment variable definition. For the above example, you can alternatively execute:
$ LC_ALL=fr_FR $ date dim oct 26 08:17:39 CET 2003
As you can see here, the output of command is affected by the environment variable to produce French output. If you want the environment variable to be inherited to the subprocesses (e.g., when calling shell script), you need to "export" it instead by using:
$ export LC_ALL
When you type a command into the shell, the shell searches the command in the list of directories contained in the PATH environment variable. The value of the PATH environment variable is also called the shell's search path.
In the default Debian installation, the PATH environment variable
of user accounts may not include /sbin/
. So if you want to run
any commands such as ifconfig
from /sbin/
, you must
change the PATH environment variable to include it. The
PATH environment variable is usually set by the initialization
file ~/.bash_profile
, see Bash configuration, Section 3.2.
Some commands take arguments. The arguments starting with - or -- are called options and control the behavior of the command.
$ date Mon Oct 27 23:02:09 CET 2003 $ date -R Mon, 27 Oct 2003 23:02:40 +0100
Here the command-line argument -R changes the date
command behavior to output RFC-2822 compliant date string.
Often you want a command to work with a group of files without typing all of them. The filename expansion pattern using the shell wildcards facilitate this needs.
*
This matches any group of 0 or more characters.
This does not match a filename started with ".".
?
This matches exactly one character.
[...]
This matches exactly one character with any character enclosed in brackets
[a-z]
This matches exactly one character with any character between a and z.
[^...]
This matches exactly one character other than any character enclosed in brackets (excluding "^").
For example, try the following and think yourself:
$ mkdir junk; cd junk; touch 1.txt 2.txt 3.c 4.h .5.txt $ echo *.txt 1.txt 2.txt $ echo * 1.txt 2.txt 3.c 4.h $ echo *.[hc] 3.c 4.h $ echo .* . .. .5.txt $ echo .[^.]* .5.txt $ echo [^1-3]* 4.h $ cd ..; rm -rf junk
Each command returns its exit status as the return value.
return value = 0 if the command executes successfully.
return value = non-zero if the command exits with error.
This return value can be accessed by the $? shell variable immediately after the execution.
$ [ 1 = 1 ] ; echo $? 0 $ [ 1 = 2 ] ; echo $? 1
Please note that, when the return value is used in the logical context for the shell, success is treated as the logical TRUE. This is somewhat non-intuitive since success bears value zero.
See Shell conditionals, Section 13.2.5.
Let's try to remember following shell command idioms. See Shell parameters, Section 13.2.3, Shell redirection, Section 13.2.4, Shell conditionals, Section 13.2.5, and Command-line processing, Section 13.2.6 after reading these idioms.
The command
is executed in the subshell in the
background. Background jobs allow users to run multiple
programs in a single shell.
The management of the background process involves the shell built-ins:
jobs
, fg
, bg
, and kill
.
Please read the sections of the bash(1)
manual page under
"SIGNALS", "JOB CONTROL", and "SHELL BUILTIN
COMMANDS". [29]
The standard output of command1
is fed to the standard input of
command2
. Both commands may be running
concurrently. This is called pipeline.
The command1
and command2
are executed
sequentially.
The command1
is executed. If successful, command2
is
also executed sequentially. Return success if both
command1
and command2
are
successful.
The command1
is executed. If not successful,
command2
is also executed sequentially. Return
success if command1
or command2
are
successful.
Redirect standard output of command
to a file
foo. (overwrite)
Redirect standard output of command
to a file
foo. (append)
Redirect both standard output and standard error of command
to a
file foo.
Redirect standard input of command
to a file
foo. Try:
$ </etc/motd pager ... (the greetings) $ pager </etc/motd ... (the greetings) $ pager /etc/motd ... (the greetings) $ cat /etc/motd | pager ... (the greetings)
Although all 4 syntaxes display the same thing, the last example runs extra
cat
command and wastes resources with no reason.
You can set an alias for the frequently used command. For example:
$ alias la='ls -la'
Now, la
works as a short hand for ls -la which lists
all files in the long listing format.
You can identity exact path or identity of the command using type
command. For example:
$ type ls ls is hashed (/bin/ls) $ type la la is aliased to `ls -la' $ type echo echo is a shell builtin $ type file file is /usr/bin/file
Here ls
was recently searched while file
was not,
thus ls
is "hashed", i.e., the shell has an internal
record for the quick access to the location of the ls
command.
There are few standard text processing tools which are used very often on the Unix-like system.
No regular expression is used:
head
outputs the first part of files.
tail
outputs the last part of files.
sort
sorts lines of text files.
uniq
removes duplicate lines from a sorted file.
tr
translates or deletes characters.
diff
compares files line by line.
Basic regular expression (BRE) is used:
grep
matches text with the pattern.
ed
is a primitive line editor.
sed
is a stream editor.
vi
is a screen editor.
emacs
is a screen editor.
Extended regular expression (ERE) is used:
egrep
matches text with pattern.
awk
does simple text processing. See Awk, Section 13.3.
perl
does every conceivable text processing. See Perl, Section 13.4.
See Regular-expression substitution, Section 8.6.13, Script snippets for piping commands, Section 8.6.18, and Perl short script madness, Section 8.6.20 for some script examples.
Regular expressions are used in many text processing tools. They are analogous to the shell wildcards (see Shell wildcards, Section 4.3.8), but they are both more complicated and more powerful.
The regular expression describes the matching pattern and is made up of text characters and metacharacters. The metacharacter is just a character with a special meaning. There are 2 major styles, BRE and ERE, depending on the text tools as described in Unix-like text processing, Section 4.4.
For the EREs, the metacharacters include "\ . [ ] ^ $ * + ? ( ) { } |". The regular expression means:
c
This matches the non-metacharacter "c".
\c
This matches the literal character "c".
.
This matches any character including newline.
^
This matches the beginning of a string.
$
This matches the end of a string.
\<
This matches the beginning of a word.
\>
This matches the end of a word.
[abc...]
This character list matches any of the characters "abc...".
[^abc...]
This negated character list matches any of the characters except "abc...".
r*
This matches zero or more regular expressions identified by "r".
r+
This matches one or more regular expressions identified by "r".
r?
This matches zero or one regular expressions identified by "r".
r1|r2
This matches one of the regular expressions identified by "r1" or "r2".
(r1|r2)
This matches one of the regular expressions identified by "r1" or "r2" and treats it as a bracketed regular expression.
In BREs the metacharacters "+ ? ( ) { }
|" lose their special meaning; instead use the backslashed versions
"\+ \? \( \) \{ \} \|". Thus the grouping construct
(r1|r2) needs to be quoted as \(r1|r2\) in BREs.
Since emacs
, although being basically BRE, treats "+
?" as the metacharacters. Thus there are no needs
to quote them. See Replacement expressions, Section
4.4.2 for how the grouping construct is used.
For example, grep
can be used to perform the text search using the
regular expression:
$ egrep 'GNU.*LICENSE|Yoyodyne' /usr/share/common-licenses/GPL GNU GENERAL PUBLIC LICENSE GNU GENERAL PUBLIC LICENSE Yoyodyne, Inc., hereby disclaims all copyright interest in the program
For the replacement expression, following characters have special meanings:
&
This represents what the regular expression matched. (use \&
in emacs
)
\n
This represents what the n-th bracketed regular expression matched.
For Perl replacement string, $n is used instead of \n and & has no special meaning.
For example:
$ echo zzz1abc2efg3hij4 | \ sed -e 's/\(1[a-z]*\)[0-9]*\(.*\)$/=&=/' zzz=1abc2efg3hij4= $ echo zzz1abc2efg3hij4 | \ sed -e 's/\(1[a-z]*\)[0-9]*\(.*\)$/\2===\1/' zzzefg3hij4===1abc $ echo zzz1abc2efg3hij4 | \ perl -pe 's/(1[a-z]*)[0-9]*(.*)$/$2===$1/' zzzefg3hij4===1abc $ echo zzz1abc2efg3hij4 | \ perl -pe 's/(1[a-z]*)[0-9]*(.*)$/=&=/' zzz=&=
Here please pay extra attention to the style of the bracketed regular expression and how the matched strings are used in the text replacement process on different tools.
These regular expressions can be used for the cursor movements and the text replacement actions in the editors too.
Please read all the related manual pages to learn these commands.
In the GNU/Linux and other Unix-like OS systems, the files are
organized into directories. [30] All files and directories
are arranged in one big tree, the file hierarchy, rooted at /
.
These files and directories can be spread out over several devices. The
mount(8)
command serves to attach the file system found on some
device to the big file tree. Conversely, the umount(8)
command
will detach it again.
Here are the basics:
Filenames are case sensitive. That is, MYFILE
and
MyFile
are different files.
The root directory is referred to as simply /
. Don't confuse this
"root" with the root user. See Login to a
shell prompt as root, Section 4.1.1.
Every directory has a name which can contain any letters or symbols
except /
. [31] The root directory is an exception; its name is
/
(pronounced "slash" or "the root directory")
and it cannot be renamed.
Each file or directory is designated by a fully-qualified
filename, absolute filename, or
path, giving the sequence of directories which must be passed
through to reach it. The three terms are synonymous. All absolute filenames
begin with the /
directory, and there's a /
between
each directory or file in the filename. The first /
is the name
of a directory, but the others are simply separators to distinguish the parts
of the filename.
The words used here can be confusing. Take the following example:
/usr/share/keytables/us.map.gz
This is a fully-qualified filename; some people call it a
path. However, people will also refer to
us.map.gz
alone as a filename. [32]
The root directory has a number of branches, such as /etc/
and
/usr/
. These subdirectories in turn branch into still more
subdirectories, such as /etc/init.d/
and /usr/local/
.
The whole thing together is called the directory tree.
You can think of an absolute filename as a route from the base of the tree
(/
) to the end of some branch (a file). You'll also hear people
talk about the directory tree as if it were a family tree:
thus subdirectories have parents, and a path shows the
complete ancestry of a file.
There are also relative paths that begin somewhere other than the root
directory. You should remember that the directory ../
refers to
the parent directory.
There's no directory that corresponds to a physical device, such as your hard disk. This differs from CP/M, DOS, and Windows, where all paths begin with a device name such as C:\. See The filesystem concept in Debian, Section 4.5.2.
The detailed best practices for the file hierarchy are described in the
Filesystem
Hierarchy Standard
. You should remember the following facts as the
starter:
/
A simple /
represents the root directory.
/etc/
This is the place for the system wide configuration files.
/var/log/
This is the place for the system log files.
/home/
This is the directory which contains all the home directories for all non-privileged users.
Following the Unix tradition, the Debian system provides the filesystem under which physical data on harddisks and other storage devices, and the interaction with the hardware devices such as console screens and remote serial consoles are represented in an unified manner.
Each file, directory, named pipe, or physical device on a Debian system has a
data structure called an inode which describes its associated
attributes such as the user who owns it (owner), the group that it belongs to,
the time last accessed, etc. See /usr/include/linux/fs.h
for the exact
definition of struct inode in the Debian GNU/Linux system.
This unified representation of physical entities is very powerful since this allows us to use the same command for the same kind of operation on many totally different devices.
All your files could be on one disk --- or you could have 20 disks, some of them connected to a different computer elsewhere on the network. You can't tell just by looking at the directory tree, and nearly all commands work just the same way no matter what physical device(s) your files are really on.
File and directory access permissions are defined separately for the following three categories of affected users:
the user who owns the file (u),
other users in the group which the file belongs to (g), and
all other users (o).
For a file, each corresponding permission allows:
read (r): to examine contents of the file,
write (w): to modify the file, and
execute (x): to run the file as a command.
For a directory, each corresponding permission allows:
read (r): to list contents of the directory,
write (w): to add or remove files in the directory, and
execute (x): to access files in the directory.
Here, execute permission on the directory means not only to allow reading of files in its directory but also to allow viewing their attributes, such as the size and the modification time.
To display permission information (and more) for files and directories,
ls
is used. See ls(1)
. When ls
invoked
with the -l option, it displays the following information in the
order given:
the type of file (first character)
-: normal file
d: directory
l: symlink
c: character device node
b: block device node
p: named pipe
s: socket
the file's access permissions (the next nine characters, consisting of three characters each for user, group, and other in this order)
the number of hard links to the file
the name of the user who owns the file
the name of the group which the file belongs to
the size of the file in characters (bytes)
the date and time of the file (mtime)
the name of the file.
To change the owner of the file, chown
is used from the root
account. To change the group of the file, chgrp
is used from the
file's owner or root account. To change file and directory access permissions,
chmod
is used from the file's owner or root account. Basic syntax
to manipulate foo
file is:
# chown newowner foo # chgrp newgroup foo # chmod [ugoa][+-=][rwx][,...] foo
See chown(1)
, chgrp(1)
, and chmod(1)
for
the detail.
For example, in order to make a directory tree to be owned by a user foo and shared by a group bar, issue the following commands from the root account:
# cd /some/location/ # chown -R foo:bar . # chmod -R ug+rwX,o=rX .
There are three more special permission bits:
set user ID (s or S instead of user's x),
set group ID (s or S instead of group's x), and
sticky bit (t or T instead of other's x).
Here the output of ls -l
for these bits is capitalized if
execution bits hidden by these outputs are unset.
Setting set user ID on an executable file allows a user to execute the executable file with the owner ID of the file (for example root). Similarly, setting set group ID on an executable file allows a user to execute the executable file with the group ID of the file (for example root). Because these settings can cause security risks, enabling them requires extra caution.
Setting set group ID on a directory enables the BSD-like file creation scheme where all files created in the directory belong to the group of the directory.
Setting the sticky bit on a directory prevents a file in the
directory from being removed by a user who is not the owner of the file. In
order to secure the contents of a file in world-writable directories such as
/tmp
or in group-writable directories, one must not only set
write permission off for the file but also set the
sticky bit on the directory. Otherwise, the file can be
removed and a new file can be created with the same name by any user who has
write access to the directory.
Here are a few interesting examples of the file permissions.
$ ls -l /etc/passwd /etc/shadow /dev/ppp /usr/sbin/pppd crw-rw---- 1 root dip 108, 0 Jan 18 13:32 /dev/ppp -rw-r--r-- 1 root root 1051 Jan 26 08:29 /etc/passwd -rw-r----- 1 root shadow 746 Jan 26 08:29 /etc/shadow -rwsr-xr-- 1 root dip 234504 Nov 24 03:58 /usr/sbin/pppd $ ls -ld /tmp /var/tmp /usr/local /var/mail /usr/src drwxrwxrwt 4 root root 4096 Feb 9 16:35 /tmp drwxrwsr-x 10 root staff 4096 Jan 18 13:31 /usr/local drwxrwsr-x 3 root src 4096 Jan 19 08:36 /usr/src drwxrwsr-x 2 root mail 4096 Feb 2 22:19 /var/mail drwxrwxrwt 3 root root 4096 Jan 25 02:48 /var/tmp
There is an alternative numeric mode to describe file permissions in
chmod(1)
commands. This numeric mode uses 3 to 4 digit wide octal
(radix=8) numbers. Each digit corresponds to:
1st optional digit: sum of set user ID (=4), set group ID (=2), and sticky bit (=1)
2nd digit: sum of read (=4), write (=2), and execute (=1) permissions for user
3rd digit: ditto for group
4th digit: ditto for other
This sounds complicated but it is actually quite simple. If you look at the first few (2-10) columns from ls -l command output and read it as a binary (radix=2) representation of file permissions ("-" being "0" and "rwx" being "1"), this numeric mode value should make sense as an octal (radix=8) representation of file permissions to you. [33] For example, try:
$ touch foo bar $ chmod u=rw,go=r foo $ chmod 644 bar $ ls -l foo bar -rw-r--r-- 1 penguin penguin 0 Nov 3 23:30 foo -rw-r--r-- 1 penguin penguin 0 Nov 3 23:30 bar
The default file permission mask can be set by using the umask
shell built-in command. See builtins(7)
.
There are three types of timestamps for a GNU/Linux file:
mtime: the modification time (ls -l),
ctime: the status change time (ls -lc), and
atime: the last access time (ls -lu).
Note that ctime is not file creation time.
Overwriting a file will change all of mtime, ctime, and atime of the file.
Changing permission or owner of a file will change ctime and atime of the file.
Reading a file will change atime of the file.
Note that even simply reading a file on the Debian system will normally cause a
file write operation to update atime information in the
inode. Mounting a filesystem with the noatime
option will let the system skip this operation and will result in faster file
access for the read. See mount(8)
.
Use touch(1)
command to change timestamps of existing files.
There are two methods of associating a file foo with a different filename bar.
a hard link is a duplicate name for an existing file (ln foo bar),
a symbolic link, or "symlink", is a special file that points to another file by name (ln -s foo bar).
See the following example for the changes in link counts and the subtle
differences in the result of the rm
command.
$ echo "Original Content" > foo $ ls -l foo -rw-r--r-- 1 osamu osamu 4 Feb 9 22:26 foo $ ln foo bar # hard link $ ln -s foo baz # symlink $ ls -l foo bar baz -rw-r--r-- 2 osamu osamu 4 Feb 9 22:26 bar lrwxrwxrwx 1 osamu osamu 3 Feb 9 22:28 baz -> foo -rw-r--r-- 2 osamu osamu 4 Feb 9 22:26 foo $ rm foo $ echo "New Content" > foo $ cat bar Original Content $ cat baz New Content
The symlink always has nominal file access permissions of "rwxrwxrwx", as shown in the above example, with the effective access permissions dictated by the permissions of the file that it points to.
The .
directory links to the directory that it appears in, thus
the link count of any new directory starts at 2. The ..
directory
links to the parent directory, thus the link count of the directory increases
with the addition of new subdirectories.
A named pipe is a file that acts like a pipe. You put something into the file, and it comes out the other end. Thus it's called a FIFO, or First-In-First-Out: the first thing you put in the pipe is the first thing to come out the other end.
If you write to a named pipe, the process which is writing to the pipe doesn't terminate until the information being written is read from the pipe. If you read from a named pipe, the reading process waits until there's something to read before terminating. The size of the pipe is always zero --- it doesn't store data, it just links two processes like the shell |. However, since this pipe has a name, the two processes don't have to be on the same command line or even be run by the same user.
You can try it by doing the following:
$ cd; mkfifo mypipe $ echo "hello" >mypipe & # put into background [1] 5952 $ ls -l mypipe prw-r--r-- 1 penguin penguin 0 2003-11-06 23:18 mypipe $ cat mypipe hello [1]+ Done echo hello >mypipe $ ls mypipe prw-r--r-- 1 penguin penguin 0 2003-11-06 23:20 mypipe $ rm mypipe
The socket is similar to the named pipe (FIFO) and allows processes to exchange information. For the socket, those processes do not need to be running at the same time nor need to be the children of the same ancestor process. This is the endpoint for the inter process communication. The exchange of information may occur over the network between different hosts.
Device files refer to physical or virtual devices on your system, such as your hard disk, video card, screen, or keyboard. An example of a virtual device is the console, represented by /dev/console.
There are two types of devices:
character device
This can be accessed one character at a time, that is, the smallest unit of data which can be written to or read from the device is a character (byte).
block device
This must be accessed in larger units called blocks, which contain a number of characters. Your hard disk is a block device.
You can read and write device files, though the file may well contain binary
data which may be an incomprehensible-to-humans gibberish. Writing data
directly to these files is sometimes useful for the troubleshooting of hardware
connections. For example, you can dump a text file to the printer device
/dev/lp0
or send modem commands to the appropriate serial port
/dev/ttyS0
. But, unless this is done carefully, it may cause a
major disaster. So be cautious.
/dev/null
etc.
/dev/null
is a special device file that discards anything you
write to it. If you don't want something, throw it in /dev/null
.
It's essentially a bottomless pit. If you read /dev/null
, you'll
get an end-of-file (EOF) character immediately.
/dev/zero
is similar, only if you read from it you get the
\0 character (not the same as the number zero ASCII). See Dummy files, Section 8.6.34.
The device node number are displayed by executing ls
as:
$ ls -l /dev/hda /dev/ttyS0 /dev/zero brw-rw---- 1 root disk 3, 0 Mar 14 2002 /dev/hda crw-rw---- 1 root dialout 4, 64 Nov 15 09:51 /dev/ttyS0 crw-rw-rw- 1 root root 1, 5 Aug 31 03:03 /dev/zero
Here,
/dev/hda
has the major device number 3 and the minor device number
0. This is read/write accessible by the user who belongs to disk
group,
/dev/ttyS0
has the major device number 4 and the minor device
number 64. This is read/write accessible by the user who belongs to
dialout group, and
/dev/zero
has the major device number 1 and the minor device
number 5. This is read/write accessible by anyone.
In the older system, the installation process creates the device nodes using
/sbin/MAKEDEV
command. See MAKEDEV(8)
.
In the newer system, the filesystem under in the /dev
is
automatically populated by the device filesystem similar to the
/proc
filesystem.
/proc
filesystem
The /proc
filesystem is a pseudo-filesystem and contains
information about the system and running processes.
People frequently panic when they notice one file in particular -
/proc/kcore
- which is generally huge. This is (more or less) a
copy of the contents of your computer's memory. It's used to debug the kernel.
It doesn't actually exist anywhere, so don't worry about its size.
See Tuning the kernel through the proc
filesystem, Section 7.2 and proc(5)
.
See X, Section 9.4.
The X Window System can be started automatically with xdm
-like
graphical login daemon or type following from the console.
$ exec startx
Since X environment can accommodate many window managers, their user interfaces vary quite a bit. Please remember that right-clicking the root window will bring up menu selections. This is always available.
To gain the shell command prompt, start Xterm from menu:
"XShells" --> "XTerm".
For graphical browsing of the web pages, start Mozilla from menu:
"Apps" --> "Net" --> "Mozilla Navigator".
For graphical browsing of the PDF files, start Xpdf from menu:
"Apps" --> "Viewers" --> "Xpdf".
If you do not find menu entry, install the pertinent packages. See Beginning Debian package management, Section 6.2.
Followings are the important keystrokes to remember when running the X Window System.
Ctrl-Alt-F1 through F6: Switch to other pseudo-terminals (from an X window, DOSEMU, etc.)
Alt-F7: Switch back to X window
Ctrl-Alt-minus: Change screen resolution in X window (minus refers to the keys on the numeric keypad)
Ctrl-Alt-plus: Change screen resolution opposite way in X window (plus refers to the keys on the numeric keypad)
Ctrl-Alt-Backspace: Terminate the X Server program
Alt-X, Alt-C, Alt-V: Usual Windows/Mac Cut, Copy, Paste keys combinations with Ctrl- keys are replaced by these Alt- keys in some programs such as Netscape Composer.
At this moment, I recommend you to read the key guide books from The Linux Documentation Project:
Guides
:
"The Linux System Administrators' Guide",
This covers all of the aspects of keeping the system running, handling user accounts, backups, configuration of the system.
package: sysadmin-guide
"The Linux Network Administrator's Guide, Second Edition",
This is a single reference for network administration in a Linux environment.
package: (not available)
file: (not applicable)
"Linux: Rute User's Tutorial and Exposition"
A nice online and hardcover book covering GNU/Linux system administration.
By Paul Sheer
Published by Prentice Hall
Package: rutebook
(from non-free)
File: /usr/share/doc/rutebook/
See Support for Debian, Chapter 15 for more learning resources.
[ previous ] [ Contents ] [ 1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ 6 ] [ 7 ] [ 8 ] [ 9 ] [ 10 ] [ 11 ] [ 12 ] [ 13 ] [ 14 ] [ 15 ] [ A ] [ next ]
Debian Reference
CVS, Thu Jan 18 11:52:15 UTC 2007osamu#at#debian.org