Linux Cheat Sheet

Last updated 1998 June 16 Roedy Green © 1998 Canadian Mind Products.

This document is designed to help a naive user install and get started with Red Hat Linux 4.2 or 5.0 It presumes you are familiar with Windows 95. I am a Linux virgin, so take anything you read here with a large grain of salt. Please let me know of any errors or omissions. I have been having a exceedingly frustrating time getting Linux to work. Further I have been overwhelmed by the sheer volume of documentation. I hope to make your way a little easier.

Equivalents

These are the closest equivalents I could find to the following Windows 95 utilities and concepts.

Win95 Linux Notes
+ (concatentation) cat
< (input redirect) <
> (output redirect) > 1> redirects stdout, normal output.
2> redirects stderr.
2>&1 redirects stderr to go to wherever stdout is going.
| (pipe) | tee splits the stream to both the console and a file.
alias (4DOS) alias to temporarily turn off an alias and get at the original meaning of a word, preceed it with a \. To permanently turn it off use unalias.
attrib chmod
chown
There are three sets read/write/execute permission attribute bits for each file, one for the owner, one for the group the file belongs to, and one for the universe at large. Each file has an owner and a group. A lead dot on a filename is similar to the DOS hidden attribute. You need ls -a to see them. Any easy way to maintain this information is with Midnight Commander, mc.
autoexec.bat /etc/*rc*,
.login, .profile, .bash_profile, .bash_login,
.bashrc, .cshrc .
/etc/*rc* execute when you first boot.
.login, .profile, .bash_profile, .bash_login execute when you first login.
.bashrc, .cshrc execute when you first start a script.
beep echo -en "\a"
boot manager LILO To modify the Linux boot manager modify /etc/lilo_config then run lilo to parse it and poke the informantion into the various absolute locations on hard disk.
call myscript.bat . myscript . means run in the same process. Without the ., the new scripts starts up a new process. exec myscript stops the current script and starts a new one.
cd cd, pwd cd changes to a directory, default the $HOME directory, where pwd tells you where you are now, print working directory.
config.sys ?
close kill
command bash, sh, csh, Zsh, exec, perl
copy cp -p, scp scp can be used inside or outside of an ssh (secure remote) session. When you use it outside one, it will automatically login, do the copying work and logout. -R is recursive like XCOPY /S. Watch out cp ignores directories and files beginning with "."
del rm
dialler ppp
dial up networking rsh (regular), ssh -v (secure) You can download the source code for ssh from ftp://ftp.cs.hut.fi:/pub/ or alternatively ftp://ftp.achilles.net:/pub/security/ssh. When you install Linux make sure you include the C/C++ development tools so that you can compile this. The easiest way to set up communication with another host is to exchange public keys via email and insert the host's key in the known_hosts file and the user's key in the authorized_keys file. You can use a null passphrase by typing ssh-keygen -p.
dir ls, dir ls -F will mark each executable with a *, directories with a /, and symbolic links with a @. Often ls is aliased to ls -F by default.
Disk Explorer mc Midnight Commander. You will have to install this manually. You will have to mount the CD-ROM first with:
cd /
mount /dev/cdrom /mnt/cdrom
and get to the directory where the install files are with:
cd /mnt/cdrom/RedHat/RPMS
then install:
rpm -i mc-3.2.11-2.i386.rpm
edit emacs, xemacs, nedit, kde, vi, joe, pico, SlickEdit Linux editors are highly configurable. They are almost unusable out the box. You need to edit text files that control how they work. Catch 22! Without special configuring, even simple things like the Del key won't work properly. I think the authors deliberately make the default configurations infuriating to force you, like a tormented oyster, into learning the configuring tools and creating a pearl. Slickedit can be configured to behave in perfectly standard CUA fashion. Others can be coerced grudgingly to sort of behave in a CUA way.
empty afile : > afile
empty the trash rm -R '#'* to get rid of the #xxx files emacs leaves behind as backup. The single quotes ensure # is not treated as a comment.
Eudora Pine
exit exit
file/disk space used, Norton FS du -s /myDir
find locate xxx
find / -name xxx -mount
which xxx
type xxx
whence xxx
find / -type f -print | xargs grep -l "String To Search For"
find / -type f -print | xargs grep -li "String To Search For"
You need to periodically use updatedb to update the database that locate uses. The database does not get updated as a side effect of creating, deleting or copying or moving files.
finger finger
free disk space
SNIFF C: D:
df -k /myDir
help man -k , info, apropos
if "%x" == "orange" echo "fruit" if "${x} = "orange"
then
echo "fruit"
fi
if not exist myfile.txt echo "oops" if ! -f myfile.txt
then
echo "oops"
fi
install rpm
Internet Explorer Netscape, Arena, HotJava
md mkdir
more more, less
MS DOS prompt shell, bash, sh
password passwd passwd is used to change your password. Passwords are stored in the /etc/passwd file in encrypted form. If any are in plain text, the account was not properly set up. The root user can set other people's password with password someUserId.
move mv
Netscape Netscape
path echo $PATH
print lpr
nenscript
cp afile /dev/lp0
lpr adds files to the print queue. nenscript converts text files to PostScript
PVCS cvs You can download the source for the cvs version control software from ftp://download.cyclic.com/pub/.
rd rmdir, rm -r
REM
::REM
# comments in scripts
remote shell rsh, ssh See dial up networking.
rename mv
replace cp -u
resync cp --recursive --update dir1/* dir2
cp --recursive --update dir2/* dir1
To resynchronise two directory trees to make them identical, propagating the newest version of each file in the directory to the other. You can use the short switches -R and -u.
set env | sort, setenv, export
shortcut link, ln -s /usr/local/netscape/netscape netsc Soft Links will be left dangling if the original file is deleted. See section later on soft links.
spawn &
splice cut split
subst mount, umount, ln -s- Before you can use a CD-ROM disc you must mount it with a command like this:
cd /
mount /dev/cdrom /mnt/cdrom
/mnt/cdrom must be a prexisting, but unused, directory where the CD-ROM files will appear. Further, it may not be the current directory. Any files there will be invisible during the time the directory is being used as a mount. Don't expect a meaningful error message if you violate any of these rules. Every time you change discs you must umount and re-mount, as if you were changing a removable disk pack on an ancient mainframe. Mounts are easier to do with the X Windows control-panel. Edit your etc/fstab to have two lines in it one for /dev/cdrom and one for/dev/hda. Use mount point /mnt/cdrom and options iso9660,noauto,ro 0 0 .
task list top, ps, ps aux | grep roedy
tasks tasks, jobs
telnet telnet
TS (Text Search) grep -i Abc myfile
grep '$' myfile
grep "$USER:" myfile
fgrep
grep looks for regular expressions. -i allows case insensitive matches. If your string contains any magic regular expression character such as []$\{}<>, or space then you need to enclose it in apostrophes. If you want $ environment expressions expanded, use quotes.
type cat
uninstall rpm -e uninstallPackageName The catch is, you don't use the same package name to install as to uninstall! To find out the uninstall names, do a rmp -q -a | less. Very likely you will want to uninstall the 1.0 Java and replace it with a 1.1.X.
who is logged on? w
Win95 startx, X Windows, FvwmF* Virtual Window Manager
WinFTP ftp, ncftp
WinZip tar -xvzf afilename.tar.gz
tar -xvf afilename.tar
gunzip afilename.gz
unzip afilename.zip
emacs
with emacs configured with (auto-compression-mode 1).
xcopy cp -R /sourceDir /targetDir

find . -name '*.c' -print | cpio -pd /targetDir

tar cf - myfiles* | (cd /targetDir; tar xf -)
The first form copies the entire directory, and Recursively copies the subdirectories. The second form selects just some of the files by wildcard. find lists the files to copy and cpio makes the copies. -d means create new directories as needed. The third form uses the tar, tape backup utility. cpio can be be persuaded to avoid copying over top of newer files.
.zip .tar, .tar.gz, .gz Watch out trying to download .tar.gz files with Win95. The names will get mangled since Win95 does not live more than one dot per name. You will have to correct them once you get them to Linux. See Winzip entry for various utilities to pack/unpack these files.

Installation Hints

Before you start installing Linux, go into the Windows 95 control panel and glean every obscure fact you can about your hardware, in particular your video card, video chip, RAMDAC, clock chip, and amount of video RAM. You will want your modem manual to concoct a good modem init string, one that insists on hardware compression, that insists on some base speed etc. There is button to print out a multipage summary. Write down the technotrivia about how your TCP/IP and LANs are configured.

Installing Hard Disk Partitions

Create all your partitions with DOS's fdisk or Partition Magic before you start your Linux install. Do not create or delete them with Linux FDisk or Druid. Use Linux FDisk only to change the partition type to 82 for standard Linux ext-2 partitions and 83 for the swap partition. DOS won't be able to see the Linux partition after they are formatted. Partition Magic won't be able to move or resize them. Linux won't let you shuffle them either. So do some work planning the sizes. You might consider installing, then looking to see how full each partition is, then erase everything and use new partition sizes based on your newfound knowledge. DOS Fdisk will not be able to erase the partitions for you. Use Partition Magic, or if you want to live dangerously, use Linux. (I got my own system is such a snit after using Linux to create and delete partitions, the only way I could repair the damage was with a hex disk editor. None of my usual tools could fix the damage.)

Here is how I sized my partitions:

Name Size in MB Purpose
win95 1953 my Win95 C: VFAT (not Fat32) partition visible to Linux.
NT 1326 my NT4.0 NTFS partition. Not accessible to Linux.
swap 200 to swap out programs too big to fit in RAM.
/ 50 root directory. everything needed to boot. My SCSI BIOS lets me put this directory above the 1024 cylinder limit.
/usr 400 where application software bundled with Red Hat resides
/usr/local 320 utilities not part of the Red Hat distribution.
/home 75 where all the user's home directories are.

It is hard to know in advance how big to make your partitions. There is no way to change their sizes later save by erasing everything and starting over. So it is wise to save some unallocated space on your hard drive that you can make into a partition later, then move data off one of your existing overstuffed partitions to it. Also put the Win95 and NT partition contigous so you can move the boundary between them. The Linux swap and root partitions are fairly easy to wipe and and redo if the need arises. Put put them next you your Win95 and NT partitions.

You might need to put a little Linux root partition totally below the 1024 cylinder mark.

You can mount your DOS/Windows partition, either read-only or read-write. You don't set it up during the sysgen. You add it later with a bit of fussing. You first need to mkdir a /win95 directory as the mount point. Then you need to use the control-panel in X windows to add a new partition. Add, not edit! You need to set its type to "vfat" not "DOS" It will be added to the /etc/fstab the auto option, so it will be automatically remounted on any reboot. If you want to set it up before you get X windows working, you can edit the /etc/fstab to insert an entry of type vfat, mount point /win95 and options auto,noexec,nosuid,nouser,rw 0 0. You need to do one mount /dev/sda1 manually, and from then on it seems to work automatically.

Others to consider making a separate partition:

Name Size in MB Purpose
/tmp ? for temporary files.
/usr/src ? for application source code bundled with Red Hat.
/var ? lock files, logs, image of working system.

There are several jobstreams running during the install. You can flip back and forth with Alt-F1 Alt-F2 etc. or Ctrl-Alt-F1 if under X Windows. To get back to X Windows use Alt-F7.

Installing Video and X Windows

If you are a masochist, you will love Xfree86. It is almost like a build-it-yourself driver toolkit but more frustrating. If you want to spend less than a month of your life solving the problem of making the screen display something, use Red Hat 5.0 and the enclosed commercial Metro-X drivers and use configX. Be careful to fill in both panels one for the monitor and one for the video card, and don't touch the add button.

If you want to go with XFree, get the latest documentation from http://www.XFree86.org. Getting X roughly working is fairly easy, but getting it to work in all the resolutions and colour depths, without huge black borders takes considerably more patience. Get the latest drivers from http://www.kernel.org/pub/linux/distributions/redhat/redhat/redhat-4.2/i386/RedHat/RPMS/

Use Xconfigurator to configure X-Windows, and X or startx to start it. Once you have X working you can use the control-panel that you can access inside X to configure a second printer, configure ppp access, add users etc.

If Xconfigurator does not work, you may have to start over from scratch installing Linux or use rpm to make sure you have the right video driver. Look over all the choices, don't just grab the first one that looks good. If X still does not work, try installing fewer video modes in particular leave leave out some of the higher resolution ones. I found the old xf86config line-oriented configuration program gave better results, though it was more awkward to use. Without it I could not get at the high resolution modes and I could not change modes with Ctrl-Alt-Keypad+ and Ctrl-Alt-Keypad-. If X hangs on fireup, hit Alt-F1 and you will be able see some error messages about why it failed. Use xvidtune within X Windows to fine tune the configuration so that the image is sized and centered properly on the monitor in all modes. Not that xvidtune does not change your XF86Config file for you. It just displays settings you can manually add to it. It may be easier to use your monitor's adjustments, then adjust other OS's to those settings.

The first entry on the modes line is the one your X windows will come up in. When you hit Ctrl-Alt-+, it should step through them in order.
Modes "640x480" "800x600" "1024x768" "1280x1024"

You can control which colour depth your X windows comes up in with: startx -- -bpp 16

In theory you should by able to permanently configure this by creating a file in your home directory called .xserverrc with the line exec X :0 -bpp 16 in it. However, I have not got that to to work myself.

To properly solve this configuration problem you have to have entries that exactly match the documented modes supported by your video bios. This may require setting up modes that are specific to a colour depth because your video card my require different rates for different colour depths with the same resolution. I have yet not found documentation on how to generate the required magic numbers.

After that is done, you can start thinking about configuing your .fvwmrc file to configure the menus etc.

Installing Internet Access

There as a plethora (too much of a good thing) of documentation on how to get PPP working. I found that the following document was most useful: http://www.interweft.com.au/other/rhtips/ppp/ppp-tip-6.html. It guides you through using netcfg under X Windows. It is even easier than configuring PPP for Win95, since everything is in one place. The descriptions of the prompts are slightly out-of-date, but nothing you can't handle. This process generates the scripts, creates the /etc/resolve.conf nameserver file etc. In going through this process, it often looks as though the system has hung. What has really happened is a window off screen is demanding your attention. Scroll around to have a look.

If it does not work, before you panic, view the generated scripts in /etc/sysconfig/network-scripts with emacs. You may have misspelled a password or forgotten that everything in Linux is case sensitive. You can test your connection with by starting up a new shell and running ping in it. The only thing that document does not cover is creating alias or short fireup/shutdown scripts so you don't have to type the giant long names and parameters.

If that is not sufficient, here are some other approaches others have recommended:

Get a copy of pppsetup from ftp://ftp.tux.org/pub/people/kent-robotti. It will generate you the bash scripts to handle your ppp needs.

There a giant HowTo document on doing the processes manually at http://sunsite.unc.edu/mdw/HOWTO/PPP-HOWTO.html. There are some Red Hat specific tips at http://www.interweft.com.au/other/.

Installing Other Hardware

The standard install program ignores much of your hardware, e.g. tape backup, sound card, scanner. To use these devices you must generate a new kernel, or find a pre-built one that has the support you need. I'm told you can do this with:
CD /usr/src/linux
make config
Though I have not had quite the nerve to try it yet.

For a sound card you may want $20 commercial drivers from http://www.4front-tech.com.

More Shells Than You Can Shake A Shtick At

autoexec script when run
/etc/*rc* when the system boots
/home/yourname.login, .profile, .bash_profile when you log in
.cshrc, .bashrc whenever you start a new shell

The different names .login, .profile, etc. are used by different shells, which allows them to co-exist more or less amicably. The C shell uses .login, the Bourne and Korn shells use .profile, bash (the Bourne Again SHell) normally looks for .bash_profile first but may also read .profile.

Re-Installing

When you install. Keep notes on what worked. Sooner or later you will have to re-install and those notes will be invaluable. Before you reinstall, save a copy of your /etc directory and your root .bash_profile outside Linux. The master copies will likely be destroyed. You can do quite a bit of your re-install simply by copying selected configuration files back into /etc, or by comparing old and new versions.

Be very careful about copying files to and from a Win95 partition. You will lose the owner, the attribute bits, and files and directories beginning with "." will not be copied. Files will be redated.

Naming Your Computer

If you have registered your own DNS domain, e.g. "ark.com", your computers will have names like "mars.ark.com" and "oberon.ark.com". If you have not, your computer name should match the last two parts of your ISP's domain. So for example if your ISP's computer were called "oberon.ark.com", your computer's hostname should be something like "cmp.ark.com".

Simply editing /etc/HOSTNAME is not sufficient. Change the name with the X control panel netconfig.

Your computer also has another name, localhost@localdomain with dummy IP 127.0.0.1.

Gotchas

Here are a grab bag of miscellaneous things that bit me at some point in my early Linux career.

Symbolic Links

Symbolic links have many uses: The basic idea is:
  1. In some directory,
  2. you put an alias name, a link to:
  3. some other file or directory that exists elswhere.
Let us say that you had a file A/x and you wanted to be able to access it alternatively by tha alias B/y. Here are the steps:
cd /B
ln -s A/x y

emacs

Emacs is an editor that comes in both text (emacs) and X-windows (xemacs) versions. You can get the four *.rpm files for xemacs from the www.xemacs.org web site. Even without source, the download is 20 MB! To further complicate the matter, the text version behaves differently in text mode and under X-windows. Emacs is a powerful editor with a great many features. Everything (even the mouse button) works in a totally non-CUA way. Win-95 users will feel all thumbs and possibly even seasick when no command works in the familiar way.

Emacs is designed solely for the convenience of advanced users. You might think if it as a suite of word processing LISP functions. You edit a file by running in an interactive programming mode where you compose and execute a LISP program on the fly where each keystroke invokes one LISP function.

To begin to make it friendly, (bind home jump to start of line instead of start of file, bind end jump to end of line, bind ^@ behave like Shift-^@, and bind ^- to behave like ^C_) create a .emacs file in your $HOME directory like this:

(global-set-key [home] 'beginning-of-line)
(global-set-key [end] 'end-of-line)
(global-set-key [?\C-2] 'set-mark-command)
(global-set-key [?\C--] 'advertised-undo)

When you have the key bindings set up the way you like, you might copy your .emacs file to /usr/share/emacs/site-lisp/default.el to set it for everybody.

Here is a table of the basic commands to get you started. M-x in Linux-speak means Alt-x, C-x means Ctrl-x and S-x means Shift-X.

KeystrokesEffect
Home or M-<Move to beginning of file
End or M->Move to end of file
PgDn or C-vPage down
PgUp or M-vPage up
M-%Replace text
C-@ or C-spacePlace mark at cursor location
C-gcancel current command.
C-x C-fload a file
C-x C-sSave a file
C-x C-cExit Emacs with option to save
C-x uUndo the last change
C-x 1go back to having a single window
C-x 2Split the window in two
C-x oOther window
C-dDelete a character
M-dDelete a word
C-gCancels the current command
C-kCuts text from cursor to end of line
M-qJustifies the current paragraph
C-sSearch for text
C-tTransposes two characters
M-tTransposes two words
M-uCapitalises current word
C-wCuts text between cursor and mark
M-wCopies text between cursor and mark
C-yPaste/Uncuts text

In emacs under X-windows by default, Shift-C-@, and does not have a binding for M-w. Have fun!

Suggested Reading

Title Author ISBN Publisher Notes
The Linux Bible 1-883601-20-7 Yggdrasil Computing very thick, the Gnu Testament.
Running Linux Matt Welsh and Lar Kaufmann 1-56592-151-8 O'Reilly good introduction to Linux and Unix in general

Credits

As you might guess, many people helped compile this document. If you would like to be added to this list, please tell me.

Andrew Langmead alangmead@bix.com
Bob Friesenhahn thefuzz@BIX.com
Daniel Kulp jdkulp@athena.com
Harvey Fishman fishman@panix.com
James Janney jjaney@bix.com
Matija Grabnar matija@bix.com
Joanne Dow jdow@bix.com
Alan Ogden arog@bix.com
Keven Kreiser kkreiser@bix.com
Alan Ogden arog@bix.com
John Strom john.r.strom@bix.com
C. D. Inchausteinchaust@students.uiuc.edu


HTML Checked!
Canadian Mind Products You can get an updated copy of this page from http://mindprod.com/linux.html