--
One Ring to rule them all, One Ring to find them,
One Ring to bring them all and in the Darkness bind them,
In the Land of Mordor where the shadows lie.
George Russell's Quick Linux Reference version 0.3
This is a user reference, not a system administration reference, but in
Linux for a single user, the two are mixed at times.
My email address for corrections etc ;-)
[EMAIL PROTECTED]
Contents
1. Commands - minor subset
1.0 root and normal use
1.1 File commands
1.2 Useful commands
2. Shells - some usage tips
2.0 What is a shell
2.1 Scripting
2.2 Interactive use
2.3 Configuration
3. Applications - useful stuff
4. X11 - The X Windows System
4.0 What is a Window Manager
4.1 What is a Desktop Environment
4.2 How do I change my WM/Desktop
4.3 How do I start X
4.4 How to leave X
5. Further Reading
6. Credits - those who contribute and correct
Commands
1.0 Root and Normal Usage
In DOS and Windows, normal users can do anything with the operating system.
Anyone can use any command, even dangerous ones, like fdisk, and format, and
delete any file, even important ones in c:\windows\system
In Unix and Linux, normal users are restricted in the commands which they can
execute and the access rights which they have to files. Unlimited access is
granted to only to the super-user, root, which is usually the System Administrator.
On a single user linux system, you are your own administrator.
It is unwise to run as the root user all the time - its better to create a
normal user account for yourself. Always using the root account is likely
to bite you when you make a mistake, and its a security risk as well.
Only use root when administering the system, or installing programs, or shutting
the system down. You have been warned.
Commandline switches are preceded by - and not / as in DOS. Usually - precedes
the short version of the switch, and -- precedes the long switch. e.g. -h and
--help have the same result.
1.1 File operations
copy ==> cp from to , where from and to are valid filenames or paths
move ==> mv from to , where from and to are valid filenames or paths
delete, erase ==> rm filename
rename ==> use mv as above ==> mv oldname newname
*** DANGER ***
This is a recursive forced delete. No queries. No mercy. In the root directory,
has aboutthe same effect as formatting c: There will be total data loss. Check
the commandline for typos, and think twice.
deltree ==> rm -rf directory
*** END DANGER ***
cd ==> cd directory (change dir)
dir ==> ls
(useful switches for ls are -a (show hidden) and and --color (colours
the output depending on the type of file ie green for executable, purple
for images) -l (show permissions) Under Unix and Linux, hidden files are
those whose filenames begin with a . character.)
link ==> ln -s realname linkname
and call it a symbolic link (or symlink for short), not just a link
(creates a symbolic link or symlink to a file which acts like that file,
but is not a full copy. I have a file n, which is a link to /opt/netscape/netscape,
so I can start netscape with the command ~/n)
more, type ==> less filename
(less, like more or cat, outputs a files contents to screen. Use only on
text files. Use q to quit)
mount ==> mount mountpoint
Unlike DOS and Windows, Unix has a unified filesystem. What this means is
that each device is treated as a directory, and there is root directory,
from which all other devices, filesystems, and folders are subdirectories.
There are no drive letters, but there are some common points.
A rough equivalence table.
DOS name Linux Device Name Common Mount Point / Linux Directory
a: ==> /dev/fd0 ==> /mnt/floppy, /floppy
d: ==> /dev/cdrom ==> /mnt/cdrom, /cdrom
The table which maps Linux device names to Linux mount points is the
/etc/fstab file. Modifying this is definitely system administration.
Note that you can allow a user to a add / remove devices and filesystems.
Removing a floppy disc, without unmounting the disk, is likely to corrupt
the disc. Its contents may be lost.
This should be all thats needed to access a device. Using a command like
mount -t vfat /dev/hda1 /mnt/dos just shows /etc/fstab is badly setup or
your not using the defaults for once. For the record, mount allows you to
spoecify a device, a mountpoint, a filesystem, and the degree of access e.g.
read / write, read only, and no execution of programs. "man mount" for
further details.
Each of the directories in the root directory has a special purpose.
/bin ==> holds binaries of small system utilities
/boot ==> holds kernel images to boot the system
/dev ==> shows the devices linux makes available
/etc ==> system wide configuration files
/home ==> Where users store their files, each with their own subdirectory
/lib ==> system libraries
/lost+found ==> used by the disk repair tool, fsck
/mnt ==> subdirectories for mounting devices and filesystems
/opt ==> optional. Holds programs which are to be kept seperated.
/proc ==> Gives information on the kernel as files
/root ==> The home directory of the root user
/sbin ==> system utilities, used to maintain the system.
/tmp ==> holds temporary files
/usr ==> where programs are installed
/var ==> for variable data, such as log files.
In Unix and Linux, the directory seperator is / and not, as in DOS \
unmount ==> umount mountpoint (it is umount, not unmount for the command)
change file permissions ==> chmod threedigitnumber filename
(File permissions in unix are awkward to explain. You can set rights
for read access, write access and execution (ie allowiing the file to be
run as a program) for yourself, others in your group (a group is a group
of users with some access rights in common) and world access rights
(those users not you or in your group) 777 is wide open, insecure,
everybody has all access rights. 666 is read / write access for
everyone. 755 is yourself with all rights, everybody else readonly. man
chmod is highly recommended, better still, a user / sysadmin howto)
locate filename ==> finds a file and gives its path, by searching a
database (fast) and not the disk itself, like find, which has a worse
syntax anyway.
updatedb ==> updates the database locate uses. Must be run by root. Is set
to run at midnight automatically, but who runs their machine 24 hours
solid? and totally thrashes the disk while it does. Peformance goes all
to hell when it runs, especially if you have little memory.
tar -xzvf filename(.tar.gz or .tgz)
(tar is a tape archiver. Used like pkzip in dos or stuffit in mac. The
x means extract, the z means uncompress using gzip, v means verbose, f just
precedes the filename)
gzip filename (also bzip2)
(Compress a file. the -d parameter uncompresses, and -9 means tightest,
but slowest, compression. bzip2 compresses better, but is slower.
gunzip also unzips. Its a symlink to gzip . There is also bunzip2, the
equivalent for bzip2)
halt (see also shutdown)
halt serves on a Linux system the role equivalent to the Start-ShutDown
dequence in Windows. It stops (kills, in Linux/Unix terminology) all
programs running in the background; closes open files; makes sure all hard
drives have been updated from temporary, cache storage; and generally makes
the system ready to be turned off.
shutdown allows a delay before it happens
1.2 Useful commands.
ps ==> shows all running tasks on a terminal. Useful switches are -ax
(both, shows all running programs)
pstree ==> shows all processes running, and how they are related.
*** DANGER ***
When Linux is first booted, the kernel loads a program called init. init has
the task of starting all other programs, and is always present in a running
system. What programs are automatically started is dependent upon what
run-level is selected. Run levels are defined in /etc/inittab and are in the
range 0 to 6 .
Run level 0 will halt the machine for shutdown
Run level 1 is single user, for repairing damaged systems
Run level 3 is multi user, console mode with networking
Run level 5 is multi user, X11 graphical mode with networking
Run level 6 will reboot the machine
Editing the inittab and getting it wrong is a good way to prevent your
system from booting. So is setting your system to automatically start
X11 on booting, but having X11 misconfigured or unusable with your video
card.
The programs started in each level varies from system to system, and is
handled by scripts in /etc/rc.d/ which are rather complex.
Its recommended not to change these yourself, but to use a program which
provides a front-end to the files, for example linuxconf which allows you
to choose which run level to boot to.
Killing init (process 1 with pid 1) is likely to crash your system immediately.
*** END DANGER ***
top ==> shows all running processes in a monitor program, updates every
second, allows for sorting by cpu usage , memory usage etc as well as
shoowing uptime, time, and system load. Allows killing of programs.
*** DANGER ***
kill -9 pid
*** END DANGER ***
kill kills running programs. the pid is the processes ID number, which
can be found using top or ps. The -9 parameter means kill now,
completely. Using kill without the parameter can allow for a more
graceful exit.
*** DANGER ***
When using su, treat it as you would logging in as root.
su ==> logs you in as the root user without logging you out first.
When you logout of the root account, it returns you to your own account.
su - ==> logs you in as root, with all the root settings (environment variables,
etc setup, and moves you to roots home directory)
See also sudo (man sudo for details)
*** END DANGER ***
lpr filename ==> sends the file to the printer. If setup right, prints
text, images, postscript and pdf files. If not, random jumble of
characters can get printed.
cdplay ==> does what it says.
grep keyword filename ==> search a file for lines containing keyword
wc filename ==> word count of the file, ie lines, words and letters.
2 Shell Usage
2.0 What is a shell?
A unix shell is the unix is a program which provides the command line
interface. Its equivalent in DOS is command.com, but Unix shells such
as sh, ash, bash, tcsh, zsh, csh (and many more) are more flexible and
powerful, implemented with multitasking in mind.
Its possible to have multiple shells available, by using the alt-(F1-F6)
keys to switch between them, and logging in multiple times.
2.1 Scripting
Simple scripts are simply a text file, set as executable (chmod 755
filename), with the first line stating what shell is to interpret the
script, followed by commands. ie
--- script starts here cut below---
#!/bin/sh
# #'s are comment delimiters, and are not treated as commands
# ! is supposed to be in the 1st line
# sh is the standard scripting shell,
# even if you use bash, zsh, tcsh interactively
echo 'hello world'
echo 'good bye'
--- end of script cut above ---
Anything more complex is programming, and not for this quick reference.
The DOS equivalent is the batch language with the .bat file extension.
Unix shell scripting is more powerful and more complex.
2.2 Interactive use.
command1 ; command2 ; command3 ; <enter>
(This runs the list of commands in sequence.)
command1 && command2 && command3 <enter>
(Runs the commands in sequence, but if one command fails, no further
commands in the list are executed.)
command1 > filename
(Redirects the output of command1 to the file filename)
command1 >> filename
(as above, but adds the output to the end of the file filename, not
overwriting the file)
comand1 | command2
(sends the output of command1 to be the input of command2. For example,
"less filename | patch -p0" sends the contents of a file to the patch
command.)
cd ~
(Go to your home directory. Same as cd on its own.)
pwd
(prints present working directory)
./command
(Run the command in the current directory, not the command in the system
path.)
command &
(Run the command in the background, Useful for Xterms, wher you want to
start a GUI program and keep using the terminal)
Tab Completion. I could for example, in bash, type
cd /ho
and press tab. Bash would complete the path for me to
cd /home
If there are multiple possibilities, bash won't expand it until its
clear which one is meant.
Wildcarding. for example
cd /ho*/grr*/Des*
is a valid path, because bash expands it to
cd /home/grrussel/Desktop
and you can use
rm *xyzzy*
to delete all files with xyzzy in the name
Wildcarding works in a different fashion to that of DOS. Be aware of
this, and cautious in your use of *
Command line history. Press the up cursor key to see the last command.
Use up or down to navigate list. left and right move cursor through the
command, and allow for editing.
To go to the start of a command line
Ctrl-A
and to go to the end
Ctrl-E
These keybindings are likely to be the same as those used in emacs.
2.4 Shell configuration
Unix shells are alomost completely customisable. Customisations are usually
set in the shells rc file in your home directory. You can set keybindings,
the prompt, and alias commands with long parameter lists to more convient
forms. In the below examples, ls is set to actually run ls --color, and which
saves me some typing.
For the bash shell and tcsh shell, insert the line below in .bashrc or
.tcshrc respectively
alias 'ls=ls --color'
You can also set environment variables here, such as the system path, which
is a list of directorys that are search for commands and programs.
3 Applications
mc (see also git (GNU Interactive Tools))
(The midnight commander, a console based file manager. Does ftp,
fileviewing, opens archives for browsing, has an internal editor which
is easy to use. Be sure to select the use of the internal editor in the
configuration menu, otherwise you get vi)
*** DANGER ***
vi (also vim, elvis, gvim)
(The standard unix lightweight editor. What you get in rescue disks.
Press i to insert text. Press the escape key to enter command mode, and
to give commands in command mode, : followed by the command.
For example, the important ones
:w
writes the currently edited file
:q
exits vi. Many newbies just kill vi - they don't know the :q command,
and its so muchmore satisfying (once the file is saved, anyway)
Command mode is dangerous. Think about what your pressing after you've
pressed escape. dd means delete the entire line. x means delete current
character. there are so many commands, that the keyboard probably has no
unused keys. Bad stuff happens if you forget to i before randomly
pecking away at the keyboard)
*** END DANGER ***
emacs (also xemacs)
(The standard heavyweight unix editor.
EightMegabytesAndConstantlySwapping, or just a meaningless five letter
acronym. Not a modal editor, like vi. So no need to switch between
insert mode and command mode.
Save a file.
ctrl-x ctrl-s
Exit
ctrl-x ctrl-c
)
pico
( a very simple and limited editor)
nedit
(a powerul but simple editor for X)
lynx
( a console based web browser. Excellent for html help files or
documentation)
wvdial
(a ppp setup and connection tool. Asks for phone number, username at
isp, and isp passwrd, and the rest is worked out by wvdial.)
man command
(display the help file for the command. man pages are terse, and not
very helpful)
man -k keyword
(also apropos . Searches man pages for pages whose (titles?) contain the
keyword)
info
(The GNU equivalent of man. Early hypertext. Use a GUI info browser in
preference to info itself)
xman
(An X11 front end to the man command)
4. X11 - The X Windows System
4.0 What is a Window Manager
A Window Manager is an application which manages Windows in the X11
environment. Window Managers provide titlebars, buttons to close / maximise /
minimise windows, menus for other operations, and the frame around a window
to allow it to be resized.
They can also provide methods of starting applications such as icon bars,
root window menus, panels, and virtual desktops, as well as setting the
wallpaper on the screen.
Some common Window Managers are
afterstep
Window Maker
Enlightenment
fvwm
kwm
icewm
Blackbox
4.1 What is a Desktop Environment
A Desktop Environment is a suite of programs which attempt to give X11 a
consistant look and feel to the user. They provide applications such as
Window Managers, File Managers, Help Browsers, and productivity software and
are configured from GUI applications.
KDE and GNOME are examples of Desktop Enivronments, so is CDE, which is
commercial. KDE and GNOME are included in most recent Linux distributions.
4.2 How do I change my WM/Desktop
The Window Manager / Desktop is used started by the command in the .xinitrc
file in the home directory.
#!/bin/sh
xterm &
xclock &
startkde
would start KDE up. Replacing the line startkde with gnome-session would
start GNOME instead, and replacing it with twm would use that instead.
Other, commonly used programs like xterm could be placed in this file.
4.3 How do I start X
>From the console
startx
will load X in its default settings.
To use non defaults, or run more than one X session concurrently, you can
give startx some parameters.
startx -- :1
would start an X session on display 1 (0 is the usual display) and you could
switch between display 0 and display 1 with Alt-Ctrl-F7 and Alt-Ctrl-F8
To run X in a different colour depth, use the bits per pixel parameter.
startx -- -bpp 16
Colours depth are either 8 bit (256 colours)
16 bit (64.000 colours)
4/32 bit (millions of colours)
and 15 bit is possible, although not all programs work correctly in it.
To cycle through available resolutions (not colour depths), use
Ctrl-Alt-Plus
(on the numeric keypad)
If you use run level 5, you should login directly to X via xdm
4.4 How do I leave X
Your Window Manager / Desktop should have a logout option, but if X has hung
or your video settings are wrong, to leave X use
Alt-Ctrl-Backspace
setfont ==> resets the terminal font if X messes the display up
5 Further Reading
5.1 Local Help files and HOWTO's
Try in /usr/doc/LDP
The documents in this are the results of the Linux Documentation Project, who
have produced the System Administrators Guide, the Network Administrators
Guide, a Linux Users Guide etc, available in various file formats.
Also in /usr/doc/HOWTO
These are guides for specific tasks, such as setting up hardware, or tips
on using Linux with previous experience of DOS / Windows. See especially
the DOStoLinux howto.
System help
For more detailed help on a command and its switches, try
man command
or
info command
Application help
For detailed help on a specific application, try its directory in
/usr/doc/PACKAGE_NAME
5.2 Non Local Help
Start from
http://www.linuxhq.com/
and
http://www.linux.org/
See also the usenet groups in comp.os.linux.*
Try the linux gazette,
http://www.linuxgazette.com/
(Anyone want to point out how to subscribe to this list and where to find
others?)
6 Contributers
Ray Olszewski
Ralph Gesler
Ralph Stickley
----------------------------
End of Reference.
Please mail any corrections / suggestions to me
[EMAIL PROTECTED]