Linux has a file system---meaning by that ``the structure of directories and files therein''---very similar to that of DOS. Files have filenames that obey special rules, are stored in directories, some are executable, and among these most have command switches. Moreover, you can use wildcard characters, redirection, and piping. There are only a few minor differences:
NOTENOUG.TXT
. Under Linux we can do better. If you installed Linux
using a filesystem like ext2 or umsdos, you can use longer filenames
(up to 255 characters), and with more than one dot in them: for example,
This_is.a.VERY_long.filename
. Please note that I used both upper
and lower case characters: in fact...
FILENAME.tar.gz
and filename.tar.gz
are
two different files. ls
is a command, LS
is a mistake;
*
' at the end of their name when you issue the ls -F
command.
For example:
$ ls -F
letter_to_Joe cindy.jpg cjpg* I_am_a_dir/ my_1st_script* old~
The files cjpg*
and my_1st_script*
are executable---``programs''.
Under DOS, backup files end in .BAK, while under Linux they end with a
tilde '~
'. Further, a file whose name starts with a dot is
considered as hidden. Example: the file .I.am.a.hidden.file
won't
show up after the ls
command;
/switch
, Linux
switches with -switch
or --switch
. Example: dir /s
becomes ls -R
. Note that many DOS programs, like PKZIP
or
ARJ
, use Unix-style switches.
You can now jump to Section Translating Commands from DOS to Linux, but if I were you I'd read on.
Unix has a type of file that doesn't exist under DOS: the symbolic
link. This can be thought of as a pointer to a file or to a
directory, and can be used instead of the file or directory it
points to; it's similar to Win 95 shortcuts.
Examples of symbolic links are /usr/X11
, which points to
/usr/X11R6
; /dev/modem
, which points to either
/dev/cua0
or /dev/cua1
.
To make a symbolic link:
$ ln -s <file_or_dir> <linkname>
Example:
$ ln -s /usr/doc/g77/DOC g77manual.txt
Now you can refer to g77manual.txt
instead of /usr/doc/g77/DOC
.
DOS files and directories have the following attributes: A (archive), H (hidden), R (read-only), and S (system). Only H and R make sense under Linux: hidden files start with a dot, and for the R attribute, read on.
Under Unix a file has ``permissions'' and an owner, who belongs to a ``group''. Look at this example:
$ ls -l /bin/ls
-rwxr-xr-x 1 root bin 27281 Aug 15 1995 /bin/ls*
The first field contains the permissions of the file /bin/ls
,
which belongs to root, group bin. Leaving the remaining information aside
(Matt's book is there for that purpose), remember that -rwxr-xr-x
means (from left to right):
-
is the file type (- = ordinary file, d = directory, l = link,
etc); rwx
are the permissions for the file owner (read, write,
execute); r-x
are the permissions for the group of the file owner
(read, execute); (I won't cover the concept of group, you can survive
without it as long as you're a beginner ;-) r-x
are the permissions
for all other users (read, execute).
This is why you can't delete the file /bin/ls
unless you are
root: you don't have the write permission to do so. To change a file's
permissions, the command is:
$ chmod <whoXperm> <file>
where who is u
(user, that is owner), g
(group), o
(other),
X is either +
or -
, perm is r
(read), w
(write), or
x
(execute). Examples:
$ chmod u+x file
this sets the execute permission for the file owner. Shortcut:
chmod +x file
.
$ chmod go-wx file
this removes write and execute permission for everyone but the owner.
$ chmod ugo+rwx file
this gives everyone read, write, and execute permission.
# chmod +s file
this makes a so-called ``setuid'' or ``suid'' file---a file that everyone can execute with root privileges.
A shorter way to refer to permissions is with numbers: rwxr-xr-x
can
be expressed as 755 (every letter corresponds to a bit: ---
is 0,
--x
is 1, -w-
is 2, -wx
is 3...). It looks difficult, but
with a bit of practice you'll understand the concept.
root, being the so-called superuser, can change everyone's file permissions. There's more to it---RMP.
On the left, the DOS commands; on the right, their Linux counterpart.
COPY: cp
DEL: rm
MOVE: mv
REN: mv
TYPE: more, less, cat
Redirection and plumbing operators: < > >> |
Wildcards: * ?
nul: /dev/null
prn, lpt1: /dev/lp0 or /dev/lp1; lpr
- EXAMPLES -
DOS Linux
---------------------------------------------------------------------
C:\GUIDO>copy joe.txt joe.doc $ cp joe.txt joe.doc
C:\GUIDO>copy *.* total $ cat * > total
C:\GUIDO>copy fractals.doc prn $ lpr fractals.doc
C:\GUIDO>del temp $ rm temp
C:\GUIDO>del *.bak $ rm *~
C:\GUIDO>move paper.txt tmp\ $ mv paper.txt tmp/
C:\GUIDO>ren paper.txt paper.asc $ mv paper.txt paper.asc
C:\GUIDO>print letter.txt $ lpr letter.txt
C:\GUIDO>type letter.txt $ more letter.txt
C:\GUIDO>type letter.txt $ less letter.txt
C:\GUIDO>type letter.txt > nul $ cat letter.txt > /dev/null
n/a $ more *.txt *.asc
n/a $ cat section*.txt | less
Notes:
more
, press SPACE to read through the file,
`q' or CTRL-C to exit. less
is more inuitive and lets you use the
arrow keys;
UNDELETE
, so think twice before deleting
anything;
< > >>
, Linux has 2>
to redirect error messages (stderr); moreover, 2>&1
redirects
stderr to stdout, while 1>&2
redirects stdout to stderr;
[]
. Use: [abc]*
matches
files starting with a, b, c; *[I-N,1,2,3]
matches files ending with
I, J, K, L, M, N, 1, 2, 3;
RENAME
; that is, mv
*.xxx *.yyy
won't work;
cp -i
and mv -i
to be warned when a file is going to
be overwritten.
To run a program, type its name as you would do under DOS. If
the directory (Section
Directories)
where the program is stored is included in the PATH (Section
System Initialization), the
program will start. Exception: unlike DOS, under Linux a program located
in the current directory won't run unless the directory is included in
the PATH. Escamotage: being prog
your program, type ./prog
.
This is what the typical command line looks like:
$ command -s1 -s2 ... -sn par1 par2 ... parn < input > output
where -s1
, ..., -sn
are the program switches,
par1
, ..., parn
are the program parameters. You can issue
several commands on the command line:
$ command1 ; command2 ; ... ; commandn
That's all about running programs, but it's easy to go a step beyond. One of the main reasons for using Linux is that it is a multitasking os---it can run several programs (from now on, processes) at the same time. You can launch processes in background and continue working straight away. Moreover, Linux lets you have several sessions: it's like having many computers to work on at once!
$ ALT-F1 ... ALT-F6
$ su - <loginname>
Example:
$ su - root
This is useful, for one, when you need to mount a disk
(Section
Floppies):
normally, only root can do that.
$ exit
If there are stopped jobs (see later), you'll be warned.
$ progname [-switches] [parameters] [< input] [> output]
&
'
at the end of the command line:
$ progname [-switches] [parameters] [< input] [> output] &
[1] 123
the shell identifies the process with a job number (e.g. [1]
; see
below), and with a PID (123 in our example).
$ ps -a
This will output a list of currently running processes.
$ kill <PID>
You may need to kill a process when you don't know how to quit it
the right way... ;-). Sometimes, a process will only be killed by
either of the following:
$ kill -15 <PID>
$ kill -9 <PID>
In addition to this, the shell allows you to stop or temporarily
suspend a process, send a process to background, and bring a
process from background to foreground. In this context, processes
are called ``jobs''.
$ jobs
here jobs are identified by their job number, not by their PID.
$ CTRL-C
$ CTRL-Z
$ bg <job>
$ fg <job>
$ kill <%job>
where <job> may be 1, 2, 3, ... Using these commands you can
format a disk, zip a bunch of files, compile a program, and unzip
an archive all at the same time, and still have the prompt at your
disposal. Try this with DOS! And try with Windows, just to see the
difference in performance.
To run a program on a remote machine whose IP address is
remote.bigone.edu
, you do:
$ telnet remote.bigone.edu
After logging in, start your favourite program. Needless to say, you must have an account on the remote machine.
If you have X11, you can even run an X application on a remote
computer, displaying it on your X screen. Let remote.bigone.edu
be
the remote X computer and local.linux.box
be your Linux machine. To
run from local.linux.box
an X program that resides on
remote.bigone.edu
, do the following:
xterm
or equivalent terminal emulator,
then type:
$ xhost +remote.bigone.edu
$ telnet remote.bigone.edu
remote:$ DISPLAY=local.linux.box:0.0
remote:$ progname &
(instead of DISPLAY...
, you may have to write setenv DISPLAY local.linux.box:0.0
. It depends on the remote shell.)Et voila! Now progname
will start on remote.bigone.edu
and
will be displayed on your machine. Don't try this over a ppp line, though.