Linux Newbie Guide IX - Linux Commands
Linux Shortcuts and Commands

Intro. This is a practical selection of the commands we use most often, find useful, and which came on our Linux distribution CDs (RedHat or Mandrake). Press <Tab> on the empty command line to see the listing of all available commands (on your PATH). On my small home system, it says there are 3786 executables on my PATH.  Many of these "commands" can be accessed from your favourite GUI front-end (probably KDE or Gnome) by clicking on the right menu or button. They can all be run from the command line (unless you didn't install the package, but they all came on our CDs).  Programs that require GUI have to be run from under the GUI, for example from a terminal opened in kde or gnome (e.g., xterm). Some more advanced (less useful for a newbie?) tools are described in the Part Learning with Linux of this Guide.

Notes for the UNIX Clueless:
1. LINUX IS CASE-SENSITIVE. For example: Netscape, NETSCAPE and nEtscape would be three different commands (but of the three, only netscape is avialable on my system). Also my_filE, my_file, and my_FILE are three different files. Your user login name and password are also case sensitive. (This goes with the tradition of UNIX and the "c" programming language being case sensitive.)
2. Filenames can be up to 256 characters long and can contain letters, numbers, "." (dot), "_" (underscore), "-" (dash), plus some other non-recommended characters.
3. Files with names starting with "." are normally not shown by the ls (list) or dir command. Think of these "dot" files as "hidden". Use ls -a  (list with the option "all") to see these files.
4. "/" is an equivalent to DOS "" (root directory, meaning the parent of all other directories, or a separator between a directory name and a subdirectory or filename). For example, try cd /usr/doc
5. Under Linux, all directories appear under a single directory tree (there are no DOS-style drive letters).  This means directories and files from all physical devices are merged into this single file system.
6. In a configuration file, a line starting with # is a comment.  When changing a configuration file, don't delete old settings--comment out the original lines. Always insert a short comment describing what you have done.
7. Linux is inherently multi-user. Your personal settings are in your home directory which is /home/your_user_login_name. Many settings are kept in files with names starting with a dot "."so as to keep them out of your way (see point 3 above).
8. System-wide settings are kept in the directory /etc .
9. Under Linux, as in any multiuser operating system, directories and files have an owner and set of permissions. You will be typically allowed to write only to your home directory which is /home/your_user_login_name. Learn to use the file permissions else you will be constantly annoyed with Linux.
10. Command options are introduced by a dash, "-", followed by a single letter (or -- when the option is more than one letter). Thus "-" is an equivalent of DOS's switch "/". For example, try rm --help.
11. Type command& (the command name followed by an  &) to start a command in the background. This is usually the preferred way of starting a program from the X-window terminal.

Linux essential keyboard shortcuts and sanity commands

<Ctrl><Alt><F1>
Switch to the first text terminal. Under Linux you can have several (6 in standard setup) terminals opened at the same time. This is a keyboard shortcut, which means: "press the control key and the alt key, hold them. Now press <F1>. Release all keys."

<Ctrl><Alt><Fn> (n=1..6)
Switch to the nth text terminal. (The same could be accomplished with the rarely used command chvt n.  "chvt" stands for "change virtual terminal").

tty
Print the name of the terminal in which you are typing this command.  The number of the active terminal can be printed using the command fgconsole.

<Ctrl><Alt><F7>
Switch to the first GUI terminal (if X-windows is running on this terminal).

 <Ctrl><Alt><Fn> (n=7..12)
Switch to the nth GUI terminal (if a GUI terminal is running on screen n-1). On default, nothing is running on terminals # 8 to 12, but you can run another server there.

 <Tab>
(In a text terminal) Autocomplete the command  if there is only one option, or else show all the available options. THIS SHORTCUT IS GREAT! It even works at LILO prompt!

 <ArrowUp>
(In a text terminal) Scroll and edit the command history. Press <Enter> to execute.

 <Shift><PgUp>
Scroll terminal output up. Work also at the login prompt, so you can scroll through your bootup messages.

 <Shift><PgDown>
Scroll terminal output down.

 <Ctrl><Alt><+>
(in X-windows) Change to the next X-server resolution (if you set up the X-server to more than one resolution). For multiple resolutions on my standard SVGA card/monitor, I have the following line in the file /etc/X11/XF86Config (the first resolution starts on default, the largest resolution determines the size of the "virtual screen"):
Modes "1024x768" "800x600" "640x480" "512x384" "480x300" "400x300" "1152x864"Z
Of course, first I had to configure the X server, either by using Xconfigurator, xf86config, or manually by edition the file /etc/X11/XF86Config, so that it supports the above resolutions (mostly the matter of uncommenting the line that defines my video chipset, and specifying the synchronization frequencies my monitor supports).  XFdrake (Mandrake configuration utility) can do it from GUI. See also the commands xvidtune and xvidgen.

<Ctrl><Alt><->
(in X-windows) Change to the previous X-server resolution.

<Ctrl><Alt><Esc>
(in X-windows, KDE) Kill the window I am going to click with my mouse pointer (the pointer changes to something like a death symbol). Similar result can be obtained with the command xkill (typed in X-terminal).  Useful when an X-window program does not want to close (hangs?).

<Ctrl><Alt><BkSpc>
(in X-windows) Kill the current X-windows server. Use if the X-windows server cannot be exited normally.

<Ctrl><Alt><Del>
Shut down the system and reboot. This is the normal shutdown command for a user at the text-mode console. Don't just press the "reset" button for shutdown!

<Ctrl>c
Kill the current process (works mostly a small text-mode applications).

<Ctrl>d
(pressed at the beginning of an empty line) Log out from the current terminal.  See also the next command.

<Ctrl>d
Send [End-of-File] to the current process. Don't press it twice else you also log out (see the previous command).

<Ctrl>s
Stop the transfer to the terminal.

<Ctrl>q
Resume the transfer to the terminal. Try if your terminal mysteriously stops responding.

<Ctrl>z
Send the current process to the background.

exit
Logout. I can also use logout for the same effect.  (If you have started a second shell, e.g., using bash, the second shell will be exited and you will be back in the first shell, not logged out.)

reset
Restore a screwed-up terminal (a terminal showing funny characters) to default setting. Use if you tried to "cat" a binary file. You may not be able to see the command as you type it.

<MiddleMouseButton>
Paste the text which is currently highlighted somewhere else. This is the normal "copy-paste" operation in Linux.  (It doesn't work with Netscape and WordPerfect which use the MS Windows-style "copy-paste". It does work in the text terminal if you enabled "gpm" service using "setup".) Best used with a Linux-ready 3-button mouse (Logitech or similar) or else set "3-mouse button emulation").

~
(tilde) My home directory (normally the directory /home/my_login_name). For example, the command cd ~/my_dir will change my working  directory to the subdirectory "my_dir" under my home directory.  Typing just "cd" alone is an equivalent of the command "cd ~".

.
(dot) Current directory. For example, ./my_program will attempt to execute the file "my_program" located in your current working directory.

..
(two dots) Directory parent to the current one. For example, the command cd .. will change my current working directory one one level up.

<Alt><SysRq><command_key>
(Non-essential.) This is a group of key combinations is implemented at the Linux kernel level (low level). It means, chances are these key combinations will work most of the time. The combinations are meant for debugging purposes and in an emergency; you should try other, safer solutions first. The key <SysRq> is also knows on PC as <PrintScreen>. The combinations can be enabled/disabled by setting the relevant kernel variable to "1" or "0", e.g. : echo "1" > /proc/sys/kernel/sysrq
<Alt><SysRq><k>  Kill all processes (including X) which are running on the currently active virtual console.  This key combination is know as "secure access key" (SAK).
<Alt><SysRq><e>  Send the TERM signal to all running processes except init, asking them to exit.
<Alt><SysRq><i>  Send the KILL signal to all running processes except init. This may be more successful in killing runaway processes than the previous key combination, but it may cause some of them to exit abnormally.
<Alt><SysRq><l> Send the KILL signal to all processes, including init. The system will not be functional.
<Alt><SysRq><s>  Run an emergency sync (cache write) on all mounted filesystems. This can prevent data loss.
<Alt><SysRq><u>  Remount all mounted filesystems as read-only. This has the same effect as the sync combination above, but with one important benefit: if the operation is successful, fsck won't have to check all filesystems after a computer hardware reset.
<Alt><SysRq><r>  Turn off keyboard raw mode. This can be useful when your X session hangs. After issueing this command you may be able to use <CTRL><ALT><DEL>.
<Alt><SysRq><b>  Reboot immediately without syncing or unmounting your disks.
<Alt><SysRq><o>   Shut the system off (if configured and supported).
<Alt><SysRq><p>   Dump the current registers and flags to your console.
<Alt><SysRq><t>   Dump a list of current tasks and their information to your console.
<Alt><SysRq><m>   Dump memory info to your console.
<Alt>SysRq><digit>   The digit is '0' to '9'. Set the console log level, controlling which kernel messages will be printed to your console. For example, '0' will cause only emergency messages like PANICs or OOPSes displayed on your console.
<Alt><SysRq><h>    Display help. Also, any other unsupported <Alt><SysRq><key> combination will display the same help.

Help commands

any_command --help |more
Display a brief help on a command (works with most commands).  For example, try cp --help |more. "--help" works similar to DOS "/h" switch. The "more" pipe is needed when the output is longer than one screen.

man topic
Display the contents of the system manual pages (help) on the topic. Press "q" to quit the viewer. Try man man if you need any advanced options.  The command info topic works similar to man topic, yet it may contain more up-to-date information. Manual pages can be hard to read--they were written for UNIX programmers. Try any_command --help for a brief, easier to digest help on a command. Some programs also come with README or other info files--have a look to the directory /usr/share/doc. To display manual page from a specific section, I may use something like: man 3 exit (this displays an info on the command exit from section 3 of the manual pages) or man -a exit (this displays man pages for exit from all sections).  The man sections are:  Section 1-User Commands, Section 2-System Calls, Section 3-Subroutines, Section 4-Devices, Section 5-File Formats, Section 6-Games, Section 7-Miscellaneous, Section 8-System Administration, Section 9, Section n-New.  To print a manual page, I use:  man topic | col -b | lpr  (the option col -b removes any backspace or other characters that could make the printed manpage difficult to read).

info topic
Display the contents of the info on a particular command. info is a replacement for man pages so it contains the most recent updates to the system documentation. Use <Space> and <BkSpace> to move around or you may get confused. Press "q" to quit.  A replacement for the somewhat confusing info browsing system might be pinfo - try if you like it any better.

apropos topic
Give me the list of the commands that have something to do with my topic.

whatis topic
Give me a short list of commands matching my topic. whatis is similar to apropos (see the command above)--they both use the same database. But whatis searches keywords, while apropos also searches the descriptions of the keywords.

help command
Display brief info on a bash (shell) built-in command. Using help with no command prints the list of all bash built-in commands. The shortest list of bash built-in commands would probably include: alias, bg, cd, echo, exit, export, fg, help, history, jobs, kill, logout, pwd, set, source, ulimit, umask, unalias, unset.

kdehelp
(in X-terminal). Browse the whole system help using the graphical KDE help navigator. Normally, KDE help is invoked by pressing the appropriate icon on the KDE control panel.  Use gnome-help-browser for the GNOME equivalent.

System info

pwd
Print working directory, i.e., display the name of my current directory on the screen.

hostname
Print the name of the local host (the machine on which I am working). Use netconf (as root) to change the name of the machine.

whoami
Print my login name.

id username
Print user id (uid) and his/her group id (gid), effective id (if different than the real id) and the supplementary groups.

date
Print or change the operating system date and time. E.g., I could change the date and time to 2000-12-31 23:57 using this command:
date 123123572000
To set the hardware (BIOS) clock from the system (Linux) clock, use the command (as root) setclock

time
Determine the amount of time that it takes for a process to complete + other info. Don't confuse it with the date command (see previous entry). E.g. I can find out how long it takes to display a directory content using:
time ls

who
Determine the users logged on the machine.

w
Determine who is logged on the system, find out what they are doing, their processor ussage, etc. Handy security command.

rwho -a
(=remote who) Determine users logged on other computers on your network. The rwho service must be enabled for this command to run. If it isn't, run setup (RedHat specific) as root to enable "rwho".

finger user_name
System info about a user. Try: finger root . One can use finger with any networked computer that exposes the finger service to the world, e.g., I can do (try): finger @finger.kernel.org.

last
Show listing of users last logged-in on your system.  Really good idea to check it from time to time as a security measure on your system.

lastb
("=last bad") Show the last bad (unsuccessful) login attempts on my system. It did not work on my system, so got it started with:
touch /var/log/btmp

"There's a good reason why /var/log/btmp isn't available on any sane set-up - it's a world-readable file containing login mistakes. Since one of the most common login mistakes is to type the password instead of the username, /var/log/btmp is a gift to crackers." (Thanks to Bruce Richardson).  It appears the problem can be solved by changing the file permissions so only root can use "lastb":
chmod  o-r /var/log/btmp
history | more
Show the last (1000 or so) commands executed from the command line on the current account. The "| more" causes the display to stop after each screenful.  To see what another user was doing on your system, login as "root" and inspect his/her "history".  The history is kept in the file .bash_history in the user home directory (so yes, it can be modified or erased).

uptime
Show the amount of time since the last reboot.

ps
(="print status" or "process status") List the processes currently run by the current user.

ps axu | more
List all the processes currently running, even those without the controlling terminal, together with the name of the user that owns each process.

top
Keep listing the currently running processes on my computer, sorted by cpu usage (top processes first). Press <Ctrl>c when done.

PID = process identification.
USER=name of the user who owns (started?) the process.
PRI=priority of the process (the higher the number, the lower the priority, normal 0, highest priority is -20, lowest 20.
NI=niceness level (i.e., if the process tries to be nice by adjusting the priority by the number given).
SIZE=kilobytes of code+data+stack taken by the process in memory.
RSS=kilobytes of physical (silicon) memory taken.
SHARE=kilobytes of memory shared with other processes.
STAT=state of the process: S-sleeping, R-running, T-stopped or traced, D-uniterruptable sleep, Z=zombie.
%CPU=share of the CPU usage (since last screen update).
%MEM=share of physical memory.
TIME=total CPU time used by the process (since it was started).
COMMAND=command line used to start the task (careful with passwords, etc., on command line, all permitted to run "top" may see them!
gtop
ktop
(in X terminal) Two GUI choices for top. My favourite is gtop (comes with gnome). In KDE, ktop is also available from the "K"menu under "System"-"Task Manager".

uname -a
(= "Unix name" with option "all") Info on your (local) server. I can also use guname (in X-window terminal) to display the info more nicely.

cat /etc/issue
Check what distribution you are using. You can put your own message in this text file--it's displayed on login. It is more common to put your site-specific login message to the file /etc/motd ("motd"="message of the day").

free
Memory info (in kilobytes).  "Shared" memory is the memory that can be shared between processes (e.g., executable code is "shared"). "Buffered" and "cashed" memory is the part that keeps parts of recently accessed files--it can be shrunk if more memory is needed by processes.

df -h
(=disk free) Print disk info about all the filesystems (in human-readable form).

du / -bh | more
(=disk usage) Print detailed disk usage for each subdirectory starting at the "/" (root) directory (in human legible form).

cat /proc/cpuinfo
Cpu info--it shows the content of the file cpuinfo. Note that the files in the /proc directory are not real files--they are hooks to look at information available to the kernel.

cat /proc/interrupts
List the interrupts in use.  May need to find out before setting up new hardware.

cat /proc/version
Linux version and other info.

cat /proc/filesystems
Show the types of filesystems currently in use.

cat /etc/printcap |more
Show the setup of printers.

lsmod
(= "list modules". As root. Use /sbin/lsmod to execute this command when you are a non-root user.) Show the kernel modules currently loaded.

set|more
Show the current user environment.

echo $PATH
Show the content of the environment variable "PATH". This command can be used to show other environment variables as well. Use "set" to see the full environment.

dmesg | less
Print kernel messages (the content of the so-called kernel ring buffer). Press "q" to quit "less". Use less /var/log/dmesg  to see what "dmesg" dumped into this file right after the last system bootup.

chage -l my_login_name
See my password expiry information.

sysctl -a |more
Display all the configurable Linux kernel parameters.

stat filename
Print general info about a file (the contents of the so-called inode).

runlevel
Print the previous and current runlevel.  The output "N5" means: "no previous runlevel" and "5 is the current runlevel".

Runlevel is the mode of operation of Linux. Runlevel can be switched "on the fly" using the command init. For example init 3 (as root) will switch me to runlevel 3. The following runlevels are standard:
     0 - halt (Do NOT set initdefault to this)
     1 - Single user mode
     2 - Multiuser, without NFS (The same as 3, if you do not have networking)
     3 - Full multiuser mode
     4 - unused
     5 - X11
     6 - reboot (Do NOT set initdefault to this)
The system default runlevel is set in the file: /etc/inittab .

Basic operations

ls
dir
List the contents of the current directory. The command dir is an alias to ls so these two commands do exactly the same thing. The file listing is normally color-coded: dark blue= directories, light grey = regular files, green = executable files, magenta = graphics files, red = compressed (zipped) files, light blue = symbolic links, yellow = device files, brown = FIFO ("First-In First-Out" named pipes).

ls -al |more
List the content of the current directory, all files (also those starting with a dot), and in a long form. Pipe the output through the "more" command, so that the display pauses after each screenful.  The ls command has several very useful options.  Some of these may have shortcuts (aliases) to avoid clumsy typing. Try ll (="long ls", an alias to ls -l). Another option I use quite often is ls -ad (list all the subdirectories in my current directory, but don't list their contents).

cd directory
Change directory. Using "cd" without the directory name will take you to your home directory. "cd - " will take you to your previous directory and is a convenient way to toggle between two directories. "cd .." will take you one directory up (very useful).

./program_name
Run an executable in the current directory. The ./ are needed when the executable is not on my PATH. Executables which are you your PATH are simply run using:  program_name

shutdown -h now
(as root) Shut down the system to a halt. Mostly used for a remote shutdown. Use <Ctrl><Alt><Del> for a shutdown at the console (which can be done by any user).

halt
reboot
init 6
(as root, three commands) Halt or reboot the machine. Used for remote shutdown, simpler to type than the previous command. Also great if the computer "hangs" (I lose control over the keyboard)--I telnet to it from another  machine on the network and remotely reboot it.  I use <Ctrl><Alt><Del> for normal shutdown at the console of a local computer.

vlock
(Not present on older versions of RedHat.)  Lock a local (text mode) terminal. I can also use vlock -a to lock all terminals (probably not a good idea). The best is probably to log out.  You don't use vlock in GUI--the windows managers come with password-protected screensaver and a locking utility (e.g., the small icon with padlock in KDE).
 

File management

cp source destination
Copy files. E.g., cp /home/stan/existing_file_name .  will copy a file to my current working directory. Use the "-R" option (stands for "recursive") to copy the contents of whole directory trees, e.g. , cp -R my_existing_dir/ ~  will copy a subdirectory under my current working directory to my home directory.

mcopy source destination
Copy a file from/to a DOS filesystem (no mounting of the DOS filesystem is necessary). E.g., mcopy a:autoexec.bat ~/junk.  See man mtools for other commands that can  access DOS files without mounting: mdir, mcd, mren, mmove, mdel, mmd, mrd, mformat ....  We don't use the mtool commands that often--operations on DOS/MS Windows files can be performed using regular Linux commands after you mount the DOS/MS Windows filesystem.

mv source destination
Move or rename files. The same command is used for moving and renaming files and directories.

rename string replacement_string filename
Flexible utility for changing parts of filenames. For example:
rename .htm .html *.htm

ln source destination
Create a hard link called destination to the file called source. The link appears as a copy of the original files, but in reality only one copy of the file is kept, just two (or more) directory entries point to it. Any changes to the file are automatically visible throughout. When one directory entry is removed, the other(s) stay(s) intact. The limitation of the hard links are: the files have to be on the same filesystem, hard links to directories or special files are impossible.

ln -s source destination
Create a symbolic (soft) link called "destination" to the file called "source". The symbolic link just specifies a path where to look for the "real" file. In contradistinction to hard links, the source and destination do not have to be on the same filesystem. In comparison to hard links, the drawback of symbolic links are: if the original file is removed, the link is "broken"--it points to nowhwere; symbolic links can create circular references (like circular references in spreadsheets or databases, e.g., "a" points to "b" and "b" points back to "a").  In short, symbolic links are a great tool and are very often used (more often than hard links), but they can create an extra level of complexity.

rm files
Remove (delete) files. You must own the file in order to be able to remove it (or be "root"). On many systems, you will be asked for a confirmation of deletion; if you don't want this, use the "-f" (=force) option, e.g., rm -f *  will remove all files in my current working directory, no questions asked.

mkdir directory
Make a new directory.

rmdir directory
Remove an empty directory.

rm -r files
(recursive remove) Remove files, directories, and their subdirectories. Careful with this command as root--you can easily remove all files on the system with such a command executed on the top of your directory tree, and there is no undelete in Linux (yet). But if you really wanted to do it (reconsider), here is how (as root):
rm -rf /*

rm -rf files
(recursive force remove). As above, but skip the prompt for confirmation, if one is set on your system. Careful with this command particularly as root--see the command above.

mc
Launch the "Midnight Commander" file manager (looks like "Norton Commander" for Linux).

konqueror &
(in X terminal) Launch the KDE file manager. Perhaps this is the utltimate for file managment. Much better that the MS "Windows Explorer".  It embeds web browsing, pdf viewing, and more. Really cool.

xwc
(in X terminal). Another excellent file manager (called "X Win Commander"). Faster than konqueror, but not as loaded with features.

Viewing and editing files

cat filename | more
View the content of a text file called "filename", one page a time. The "|" is the "pipe" symbol (on many American keyboards it shares the key with ""). more makes the output stop after each screenful. For long files, it is sometimes convenient to use the commands head and tail that display just the beginning and the end of the file. If you happened to use cat a binary file and your terminal displays funny characters afterwards, you can restore it with the command reset.

cat filename | less
less filename
(two commands, use either) Scroll through a content of a text file. Press q when done. "less" is roughly equivalent to "more" , the command you know from DOS, but often "less" is more convenient than "more".

head filename
Print first 10 lines of the (long) text file.

tail filename
Print last 10 lines of a long or growing text file. Use tail -f filename for tail to follow the file as it grows--really handy for continuing inspection of log files.

pico filename
Edit a text file using the simple and standard text editor called pico.  Use <Ctrl>x to exit.  There are many text editors for Linux, including several GUI-based.   A brand new clone of pico (GPLed) is nano.

pico -w filename
Edit a text file, while disabling the long line wrap. Handy for editing configuration files, e.g. /etc/fstab.

kwrite
(in X terminal) Very nice, "advanced text editor". Supports veritical text selection!

kedit
gedit
(in X terminal). Simple yet nice text editors (GUI based).

gxedit
(in X terminal) Another multi-purpose, feature packed text editor. This one even has timed backup.

latte
(in X termina) "Code" editor, i.e.,  plain text meant for writing programs.

nedit
(in X terminal)  Another programmer editor. Very nice and loaded.

bluefish
(in X terminal) html editor (source with syntax highlighting and maaaany tools and options).

ispell filename
Spell check an ASCII text file.  AbiWord, WordPerfect, StarOffice and other word processors come with "as-you-type" spellchecking, so you really don't have to worry about the simple ispell unless you need it.  Newer Linux distributions (e.g., RH7.0) contain an improved spellchecking module called aspell, yet the above command will still work.

touch filename
Change the date/time stamp of the file filename to the current time. Create an empty file if the file does not exist.

wvHtml ms_word_document.doc > filename.html
Convert a MS Word document to the html file format.

Finding files

find / -name "filename"
Find the file called "filename" on your filesystem starting the search from the root directory "/". The "filename" may contain wildcards (*,?).
The find command is very powerful. It has many options that will let you search for files in a variety of ways e.g., by date, size, permissions, owner, .... Yet some search queries can take you more than a minute to compose. See info find. Here are some more complex examples for using find to accomplish some useful tasks.
find $HOME -name core -exec rm -f {} ;
The above command finds files named "core", starting from your home directory.  For each such file found, it perform the action "rm -f" (force-deleting the file). The {} stands for the file found,  and the "" terminates the command list.

find /dev -user "peter" |more
The above command prints the filename for all devices owned by user "peter". Printing the filename is the default "action" of find, so it does not have to be specified if this is all I need.

find /home/peter -nouser -exec ls -l {} ; -ok chown peter.peter {} ;
Find files without a valid owner in the /home/peter directory. List the file in a long format. Then prompt to change the ownership to the user "peter" and the group "peter". You probably need to be root to hand over the ownership of a file.

locate filename
Find the file name which contains the string "filename". Easier and faster than the previous command but depends on a database that normally rebuilds at night.

which executable_name
Show me the full path to the executable that would run if I just typed its name on the command line. For example, this commmand:
which netscape
on my system produces:
/usr/bin/netscape

whereis command
Print the locations for the binary, source, and manual page files of the command "command".

rgrep -r 'celeste'  . |more
Search all files in the current directory and all its subdirectories (the option "-r" stands for "recursive") for the example string "celeste". Print the filename and the line in the file that contains the searched string.

kfind &
(in X terminal). A GUI front-end to find and grep. Very nice.  The & at the end of the command makes kfind run in the background so that the X terminal remains available.

Basics of X-windows

xinit
Start a barebone X-windows server (without a windows manager).

startx
Start an X-windows server and the default windows manager. Works like typing "win" under DOS with Win3.1

startx -- :1
Start another X-windows session on the display 1 (the default is opened on display 0). You can have several GUI terminals running concurrently. Switch between them using <Ctrl><Alt><F7>, <Ctrl><Alt><F8>, etc.

xterm
(in X terminal) Run a simple X-windows terminal.  Typing exit will close it.  There are other, more advanced "virtual" terminals for X-windows. I like the popular ones: konsole and kvt (both come with kde) and gnome-terminal (comes with gnome).  If you need something really fancy-looking, try Eterm.

startkde
gnome-session
xfce
afterstep
AnotherLevel
fvwm2
fvwm
(in X terminal, 7 different commands, use the one which starts your fav windows manager) Start your favourite windows manager in an X terminal on bare X server.

Network apps

netscape &
(in X terminal) Run netscape.  I currently (March 2001) run Netscape 4.75 and it is pretty good.  Some previous versions of Netscape were known to be buggy: they occasionally crashed by vanishing (no other harm done), when not connected to the network , they liked to refuse to do anything (looked like it hanged) only to revive on connect.  Mozilla is a modern replacement for Netscape, but it is still not quite ready, (still quite usable, requires your own installation).  konqueror may be a good alternative if Netscape does not satisfy your need.

netscape -display host:0.0 &
(in X terminal) Run netscape on the current machine and direct the output to machine named "host" display 0 screen 0. Your current machine must have a permission to display on the machine "host" (typically given by executing the command xhost current_machine_name in the xterminal of the machine host. Other X-windows program can be run remotely the same way.

lynx file.html
View an html file or browse the net from the text mode. Although lynx's look or convenience of use is not as great as GUI-based browser, it is light-weight, almost always works, and does not require any configuration, as long as your networks is functional.

konqueror &
(in X terminal) File manager and web browser in one. Very nice,  in many ways better than netscape. Comes with KDE.

pine
A good text-mode mail reader. Another good and standard one is elm. Your Netscape mail will read the mail from your Internet account. pine will let you read the "local" mail, e.g. the mail your son or a cron process sends to you from a computer on your home network. The command mail could also be used for reading/composing mail, but it would be inconvenient--it is meant to be used in scripts for automation.

mutt
A really basic but extremally useful and fast mail reader.

mail
A basic operating system tool for e-mail. Look at the previous commands for a better e-mail reader. mail is good if you wanted to send an e-mail from a shell script.

kmail
(in X-terminal) Nice, GUI mail program. I use kmail, it is much better than netscape mail. I can have multiple accounts and retrieve mail from the smtp (local) server and pop3 servers (internet service provider) to the same mailbox. Simple and elegant. Supports digital signatures.

licq
(in X terminal) An icq "instant messaging" client. Another good one is kxicq. Older distributions don't have an icq client installed, you have to do download one and install it.

knode
(in X terminal)  Start my favourite newsgroup (usenet) reader. It is MUCH better than the netscape's built-in reader.

talk username1
Talk to another user currently logged on your machine (or use "talk username1@machinename" to talk to a user on a different computer) . To accept the invitation to the conversation, type the command "talk username2". If somebody is trying to talk to you and it disrupts your work, your may use the command "mesg n" to refuse accepting messages. You may want to use "who" or "rwho" to determine the users who are currently logged-in.

telnet server
Connect to another machine using the TELNET protocol. Use a remote machine name or IP address. You will be prompted for your login name and password--you must have an account on the remote machine to login. Telnet will connect you to another machine and let you operate on it as if you were sitting at its keyboard (almost). Telnet is not very secure--everything you type goes in open text, even your password!

rlogin server
(=remote login) Connect to another machine. The login name/password from your current session is used; if it fails you are prompted for a password.

rsh server
(=remote shell) Yet another way to connect to a remote machine. The login name/password from your current session is used; if it fails you are prompted for a password.

ssh server
(=secure shell) Connect to a server (remote login) using a secure connection. ssh is secure because it checks identity of the person connecting, and encrypts all the data transfered over the network using your pair of RSA"public-private" keys.

Both the client and the server must have ssh service (daemon) running. This is normally available on newer Linux distributions (e.g., RH7.0). Before using ssh, some setup is necessary.  The user creates his/her RSA key pair by running the command ssh-keygen.  This stores the private key in the file $HOME/.ssh/identity and the public key in $HOME/.ssh/identity.pub in the user's home directory.  The user should then copy the identity.pub to $HOME/.ssh/authorized_keys in his/her home directory on the remote machine  After this, the user can log in without giving  the password.  The most convenient way to use RSA authentication may be with an authentication agent.  See man 1 ssh-agent for more information. If authomatic authentication methods fail, ssh prompts the user for a password.  The password is sent to the remote host for checking; however, since all communications are encrypted, the password cannot be seen by someone listening on the network.
ftp server
Ftp another machine. (There is also ncftp which adds extra features and gftp for GUI .) Ftp is good for copying files to/from a remote machine. Try user "anonymous" if you don't have an account on the remote server. After connection, use "?" to see the list of available ftp commands.  The essential ftp commands are: ls (see the files on the remote system), ASCII, binary (set the file transfer mode to either text or binary, important that you select the proper one ), get (copy a file from the remote system to the local system), mget (get many files at once), put (copy a file from the local system to the remote system), mput (put many files at once), bye (disconnect). For automation in a script, you may want to use ncftpput and ncftpget, for example:
ncftpput -u my_user_name -p my_password -a remote.host.domain remote_dir *local.html
For keeping mirrors of ftp directories, one can use fmirror

wget -m http://sunsite.dk/linux-newbie
Copy files from web sites. The example above uses the option -m (=mirror) to retrieve a complete set of files from the master site of this guide.

minicom
Minicom program for serial port "terminal emulation". Looks and works like "Procomm" or "Telix". At minimum, useful for testing, debugging serial communication.

rx
Receive files using the Zmodem, Ymodem, or Xmodem protocol. Xmodem requires a filename. Use rx --help for more info. Who uses these protocols any more anyway?

File (de)compression

tar -zxvf filename.tar.gz
(=tape archiver) Untar a tarred and compressed tarball (*.tar.gz or *.tgz) that you downloaded from the Internet.

tar -xvf filename.tar
Untar a tarred but uncompressed tarball (*.tar).

tar czvpf /var/backups/mybackup.tar.gz /home
cd /; tar xzvpf /var/backups/mybackup.tar.gz '*/myfile.rtf'
(as root) Create a backup of /home to a compressed file. The second command shows how to restore a file from the backup.

gunzip filename.gz
Decompress a zipped file (*.gz" or *.z). Use gzip (also zip or compress) if you wanted to compress files to this file format. Note the funny pronounciation of "gun zip".

zcat filename.gz | more
(=zip cat) Display the contents of a compressed file.  Other utilities for operating on compressed files without prior decomprssion are also available: zless, zmore, zgrep, ...

bunzip2 filename.bz2
(=big unzip) Decompress a file (*.bz2) zipped with bzip2 compression utility. Used for big files.

unzip filename.zip
Decompress a file (*.zip) zipped with a compression utility compatible with PKZIP for DOS.

zip filename.zip filename1 filename2
Compress two files "filename1" and "filename2" to a zip archive called "filename.zip".

unarj e filename.arj
Extract the content of an *.arj archive.

lha e filename.lha
Extract the content of an lharc archive.

uudecode -o outputfile filename
Decode a file encoded with uuencode.  uu-encoded files are typically used for transfer of non-text files in e-mail (uuencode transforms any file into an ASCII file).

cat filename | mimencode  -o filename.mime
cat filename.mime |mimencode -u -o filname
(2 commands.) Encode and then decode back a file to/from the mail-oriented Internet standard for 7-bit data transfer called "mime".  On older distributions, the command that does the work (mimencode) is called mmencode.  Usually, you don't have to bother with these commands, your mailer should do the mime encoding/decoding in a transparent way.

ar -x my_archive.a file1 file2
(=archiver). Extract files file1 and file2 from an archive called my_archive.a. The archiver utility ar is mostly used for holding libraries.

ark &
(in X terminal). A GUI (Qt-based) archiver application. Perhaps that's everything what you need to manage your compressed files. An alternative is gnozip.

Process control

ps
(="print status" or "process status") Display the list of currently running processes with their process IDs (PID) numbers. Use ps axu to see all processes currently running on your system (also those of other users or without a controlling terminal), each with the name of the owner. Use "top" to keep listing the processes currently running.

any_command &
Run any command in the background (the symbol "&" means "run the preceding command in the background").  The job_number is printed on the screen so you can bring the command in the foreground (see below) if you want.

jobs
List my background or stopped processes and show their job numbers.

fg job_number
Bring a background or stopped process to the foreground.

bg job_number
Place a process in the background, so it is exactly as if it had been started with &. This will restart a stopped background process. The current foreground process can often be stopped with <Ctrl>z.  If you have stopped or background jobs, you have to type exit twice in row to log out.

batch any_command
Run any command (usually one that is going to take more time) when the system load is low. I can logout, and the process will keep running.

at 17:00
Execute a command at a specified time.  You will be prompted for the command(s) to run, until you press <Ctrl>d.  The associated commands are atq (display the queue of processes started with at) and atrm (remove a process from the "at queue").

kill PID
Force a process shutdown. First determine the PID of the process to kill using ps.

killall program_name
Kill program(s) by name.  For example, killall pppd will disconnect your dialup network.

nohup program_name
(=no hungup). Run program_name so that it does not terminate when you log out.  Output is redirected to the file nohup.out in your home directory.  You surely do not want to run an interactive program under nohup.

xkill
(in X terminal) Kill a GUI-based program with mouse. (Point with your mouse cursor at the window of the process you want to kill and click.)

kpm
(in X terminal) KDE process manager.

lpc
(as root) Check and control the printer(s). Type "?" to see the list of available commands.

lpq
Show the content of the printer queue. Under KDE (X-Windows), you may use GUI-based "Printer Queue" available from "K"menu-Utilities.

lprm job_number
Remove a printing job "job_number" from the queue.

nice program_name
Run program_name adjusting its priority. Since the priority is not specified in this example, it will be increased by 10 (the process will run slower), from the default value (usually 0). The lower the number (of "niceness" to other users on the system), the higher the priority. The priority value may be in the range -20 to 19.  Only root may specify negative values. Use top to display the priorities of the running processes.

renice -18 PID
(as root) Change the priority of a running process to minus 18. Normal users can only adjust processes they own, and only up from the current value (make them run slower). One could also renice +10 -u peter to make user peter use fewer cpu clicks so that other user don't suffer when he runs his computing-intensive tasks.

<Ctrl>c, <Ctrl>z, <Ctrl>s, and <Ctrl>q also belong to this chapter but they were described previously. In short they mean: stop the current command, send the current command to the background, stop the data transfer, resume the data transfer.

lsof
List the opened files. If I am a root, all files will be listed. I can limit myself to files opened by processes owned by the first console if I use lsof /dev/tty1 .  To list only network files (useful for a security audit), I would do lsof -i (as root).

watch -n 60 my_command
Execute my_command at 60-second intervals (the default interval is 2 seconds).

Some administration commands

su
(=substitute user id) Assume the superuser (=root) identity (you will be prompted for the password). Type "exit" to return you to your previous login. Don't habitually work on your machine as root. The root account is for administration and the su command is to ease your access to the administration account when you require it. You can also use "su" to assume any other user identity, e.g. su barbara will make me "barbara" (password required unless I am the superuser).

alias ls="ls --color=tty"
Create an alias for the command "ls" to enhance its format with color. In this example, the alias is also called "ls" and the "color" option is only evoked when the output is done to a terminal (not to files). Put the alias into the file /etc/bashrc if you would like the alias to be always accessible to all users on the system. Aliases are a handy way to customize your system. Type "alias" alone to see the list of aliases for your account. Use unalias alias_name to remove an alias.

cat /var/log/httpd/access_log
Show who connected to your http (apache) server since the last time the log file was "rotated" (normally rotated once a day, when cron runs). The previous log file is access_log.1, the yet previous access_log.2, etc.

cat /var/log/secure
(as root) Inspect the important system log. It is really a good idea to do it from time to time if you use Internet access.

ftpwho
(as root) Determine who is currently connected to your ftp server.

printtool
(as root in X-terminal) Configuration tool for your printer(s). Settings go to the file /etc/printcap and (strangely) /var/spool/lpd.

setup
(as root) Configure mouse, soundcard, keyboard, X-windows, and system services. There are many distibution-specific configuration utilities, setup is the default on RedHat. Mandrake 7.0 offers very nice DrakConf .

linuxconf
(as root, either in text mode or in the X terminal). You can access and change hundreds of network setting from here. Very powerful--don't change too many things at the same time, and be careful with changing entries you don't understand.  ReadHats network configuration utility netconf is a subset of linuxconf, therefore it is simpler and sometimes easier to use.

mouseconf
(as root). Simple tool to configure your mouse (after the initial installation).  Mandrake includes also an alternative mousedrake.

kudzu
(as root). Automatically determines and configures your hardware.  If having mysterious problems with your mouse (or other serial hardware), you may want to disable kudzu, so it does not run on the system startup (kudzu messed up my system so I could not have my mouse working). You can run it manually when you need it.

timeconfig
(as root) Set the timezone for your system.

setclock
(as root). Set your computer hardware clock from the current linux system time. Use the command "date" first to set up the linux system time. E.g., I could change the date and time to 2000-12-31 23:57 using this command:
date 123123572000
and then write the time to the hardware clock using:
setclock

xvidtune
(in X-terminal). Adjust the settings of the graphical display for all resolutions so as to eliminate black bands, shift the display right/left/up/down, etc. (First use the knobs on your monitor to fit your text mode correctly on the screen.) Then use xvidtune to adjust the monitor frequencies for each resolution so it fits well in your secree. To make the changes permanent, display the frequencies on the screen and then transfer them to the setup file /etc/X11/XF86Config.

kvideogen
(in X-terminal). Generate "modelines" for customized resolutions of your screen.  After you generated the setup text (the "modelines"), you can copy-paste it to the X-windows setup file /etc/X11/XF86Config (or /etc/X11/XF86Config-4 if you use X-server version 4.xx). See also the keyboard shortcut <Ctrl><Alt><+>

SVGATextMode 80x25x9
SVGATextMode 80x29x9
(as root) Change the text resolution in the text terminal. In the above example (second line) I changed the text screen to 80 columns x 29 lines with characters 9 pixels high. The first line defines a resolution that always works, so that if the second command did not work on my system, I can press <ArrowUP> twice and <Enter> to regain control over my screen.  The possible modes depend on your video card and your monitor synchronization frequencies--I needed to edit (as root) the file /etc/TextConfig and (un)comment the proper lines to let SVGATextMode know what my system supports.

SuperProbe
(as root). A utility to determine the type of the video card and the amount of its memory.

kernelcfg
(as root in X terminal). GUI to to add/remove kernel modules. Module is like a device driver--a piece of Linux kernel that provides support for a particular piece of hardware or functionality. You can do the same from the command line using the command insmod.

lsmod
(= list modules). List currently loaded kernel modules. A module is like a device driver--it provides operating system kernel support for a particular piece of hardware or feature.

modprobe -l |more
List all the modules available for your kernel. The available modules are determined by how your Linux kernel was compliled. Every possible module/feature can be compiled on linux as either "hard wired" (fast, non-removable), "module" (maybe slower, but loaded/removable on demand), or "no" (no support for this feature at all). The modules which your kernel supports (with which it was compiled) are all as files under the directory /lib/modules (and the subdirectories) so browsing it may give you a clue if you are lost.

modprobe sb
Load the soundblaster (sb) module.

insmod parport
insmod ppa
(as root) Insert modules into the kernel (a module is roughly an equivalent of a DOS device driver). Normally, I use "modprobe" (see the previous command) to insert modules. This example shows how to insert the modules for support of the external parallel port zip drive (it appears to be a problem to get the external zip drive to work  in any other way under RH6.0 and 6.1).

rmmod module_name
(as root, not essential). Remove the module module_name from the kernel.

depmod -a
(as root) Build the module dependency table for the kernel. Not essential unless you modified /etc/modules and don't wish to reboot.

setserial /dev/cua0 port 0x03f8 irq 4
(as root) Set a serial port to a non-standard setting. The example here shows the standard setting for the first serial port (cua0 or ttyS0). The standard PC settings for the second serial port (cua1or ttyS1) are: address of i/o port 0x02f8, irq 3. The third serial port (cua2 or ttyS2): 0x03e8, irq 4. The forth serial port (cua3 or ttyS3): 0x02e8, irq 3. Add your setting to /etc/rc.d/rc.local if you want it to be set at the boot time. See man setserial for good a overview.

tunelp
(as root, rarely needed) Tune up your parallel ports.

/sbin/chkconfig --level 123456 kudzu off
(as root)A tool to check/enable/disable system services which will automatically start under different runlevels. Typically, I just use RedHat ntsysv utility if I need to enable/disable a service in the current runlevel, but chkconfig does give me an extra flexibility.  An alternative tool is tksysv (X-based).  The example above shows how to disable kudzu service so it does not start up at any runlevel (it messes up mouse on one of my computers).  To list all the services started/stopped under all runlevels, I use:
chkconfig --list | more
To check the current status of services, I may use:
service --status-all
To start a service right now, I may use something like (starts an ftp server):
service wu-ftpd start
To re-start samba networking (e.g., after I changed its configuration), I may use:
service smb restart

symlinks -r -cds /
(as root) Check and fix the symbolic links on my system. Start from / and progress through all the subdirectories (option -r="recurse")  and change absolute/messy links to relative, delete dangling links, and shorten lengthy links (options -cds).  If my filesystem spreads over different hard drive partitions, I need to re-run this command for each of them (e.g., symlinks -r -cds /usr).

cd /usr/src/linux-2.2.14
make xconfig
(as root in X terminal). Nice GUI front-end for configuration of the kernel options in preparation for compilation of your customized kernel.  (The directory name contains the version of your Linux kernel so you may need to modify the directory name if your Linux kernel version is different than 2.2.14 used in this example. Also, you  need the "Tk" interpreter and the kernel source code installed.) The alternatives to  "make xconfig" are: "make config"  (runs a scripts that asks you questions in the text mode) and "make menuconfig" (runs a text-based menu-driven configuration utility). Try: less /usr/doc/HOWTO/Kernel-HOWTO for more information.
After configurating the options for the new kernel, you may choose to proceed with kernel compilation of the new kernel by issuing the following commands:
make dep
make bzImage
The last command will take some time to complete (maybe 0.5 h or 2 h, depending on your hardware). It produces the file "bzImage", which is your new Linux kernel. Next:
make modules
make modules_install
Now



This article comes from osforge.com
http://www.osforge.com

The URL for this story is:
http://www.osforge.com/viewtutorial17.html