So, the purpose of this is to provide a ready reference, a sort of ultimate *nix cheatsheet, something like a pocket thesaurus, for the newbie and the journeyman alike. If an expert finds something useful or wants to contribute, I'd certainly appreciate it, but I hope no truly arcane expert-only knowledge ends up here. Eg, rare tricks do not belong here, though I may very well find them fascinating in another context. Anyone can edit it, hopefully for the better.
A couple of key concepts that may help
Everything in a UNIX-like system is a file. As far as Linux is concerned, the mouse is a file.
What you write on the command line goes into a special file called stdin (standard input)
What the shell (the command line program) prints on the screen under the command you just executed, if anything, is written in a special file called stdout. Found in the /dev directory, like null. Errors go to a special file called stderr.
special punctuation
There are some privileged characters
| -- pipeline commands, that is, use output of one command as input for the next: eg: ls -al | less
> -- put results in following file, eg: $ ls -al > listing. Another useful example: netstat > /dev/null (dumps stdout into a trashbin called the null device)
& -- background a task to get your command line back with the ampersand (particularly useful if you're in a non-windowing environment, eg make install lots of packages > /dev/null &)
Useful key combos for the command line
ctrl-c -- kill the last given command (I think this is technically a sighup)
ctrl-z -- stop the last given command (I think this is technically a sigstop)
Useful key combos for text editors generally
These are so common, they persist even into the most backwoods, arcane, backwards Windows app, like AHLTA. If you are interested in the copious key combos for a particular text editor, go check that website.
ctrl-z -- undo
ctrl-x -- cut
ctrl-c -- copy
ctrl-v -- paste
ctrl-a -- select all
ctrl-b -- bold (not useful in true plain text editors, but I thought I'd throw it in)
ctrl-i -- italic (not useful in true plain text editors, but I thought I'd throw it in)
commands
A bit on style. I'm not a linux guru. I started this list for my own benefit. If you quizzed me on this list tomorrow, I'd get some wrong. Some of the things I've put here may not by exactly correct. This is not meant to be a comprehensive list of every program in the Debian repositories, nor is it intended to be the complete set of man pages for all those programs. It's meant to be a bit like a pocket thesaurus. Easily searchable with ctrl-f, good enough to get the drift, with some pointers to other helpful ideas.
The commands and some examples are wrapped in tags. The input for that command is in plain text. A brief explanation, sometimes with a very useful example or a very useful flag or two, follows, finished with "See also" where appropriate.
apt -- debian's package manager. See also rpm, yum.
bg -- background a task. Typically used like this: 1) ctrl-z 2) bg 3) disown %1
cal -- displays calendar
cat filename -- Displays the contents of a file in the terminal. See also: head, less, more, tail
cd -- change directory
cp sourcefile detstinationfilename -- copies a file
chkconfig -- manages the services that start up and shut down in different runlevels (we are running in runlevel 3) the --list option is safe. Don't add or delete things unless you know what you're doing.
chgrp -- change group of a file or directory, usually need to do this before chown, as the owner must belong to the group that owns the files
chown -- change owner of a file or directory.
chmod -- change permissions of a file or directory. Usually better to change the owner and group. chmod 777 is not a command you should be using on a webserver.
clear -- clears the terminal window
curl -- a very useful http fetching tool. See the scripting section below.
date -- displays current date and time
diff -- compare two files. diff, grep, and the operators | and > can be very useful if you're trying to troubleshoot.
disown PID or %job number -- orphan a process. See also bg, screen.
df -- displays all mounted filesystems
echo string -- copies string to terminal, technically to stdout.
file filename -- displays information about file contents
finger username -- User information lookup program
finger username@hostname -- obtains detailed information about a user currently using the system
ftp -- utility to transfer files between systems on a network. See also
grep string filename -- look through file for following expression ('get regular expression'). To search all files in the working directory: grep -rl "string" . (don't forget the period or you'll search the whole filesystem!)
gunzip filename -- decompresses a compressed file. See also tar, gzip.
gzip filename - compresses a file. See also gunzip, tar.
head filename -- displays first 10 lines of file. See also: cat, less, more, tail
hostname -- Displays system identity name. See also uname, netstat, finger, nslookup.
info -- displays information and documentation on shells, utilities and programs
iptables -- poke holes in the firewall or plug them. Don't play with this unless you have nmap and wireshark and know how to use them.
jobs -- displays a list of current jobs
kill PID or %job number: Aborts a process by PID (Process Identification Number) or job number
kssh -- if you use KDE, you really need to check this one out. Provides most of the common but sometimes complex ssh commands in a GUI.
lcd -- change local directory while logged into a remote machine. See also cd, ftp, lls, rcp, sftp.
locate -- print location of certain system files, such as administrative commands (eg, locate ifconfig)
lls -- list local directory contents while logged into a remote machine. See also ftp, lcd, ls, rcp, sftp.
ls -- list directory contents (ls -al lists all, including hidden, and shows permissions and owners
ln -- link one file to another. Remember, directories are files. Particularly, symbolic links, symlinks, are very handy:
$ mkdir pond
$ ln -s pond puddle
$ cd puddle
$ touch drizzle
$ cd ..
$ cd pond
$ ls
puddle
less filename -- read a file from the terminal. Use up/down to scroll, use f and b to jump half a page at a time less. See also: cat, head, more, tail
lpr filename -- sends file to printer
man -- manual page for the command (man w, man top, man less)
mc -- midnight commander, an ncurses file manager in your shell, similar to mutt, pine, elm, or yast.
mesg y/n -- sets options for letting other users write you messages. See also: talk, w, who, write.
more filename -- Displays the contents of a file in the terminal one page at a time
motd -- read the Message of the Day
mv existingfilename newfilename -- technically this moves a file or directory, but it's also used to rename things: eg, to rename the directory wordpress-2.5.1 as blogs : mv wordpress-2.5.1 blogs
nano filename -- simple test editor. See also edit, emacs, gedit, pico, vi, vim.
netstat -- displays network connections. See also finger, traceroute.
nslookup -- queries Internet domain name servers. See also finger, traceroute.
passwd username -- changes password
ping host -- utility used to test connection to a remote system
ps process number -- information about a task. Useful flag: -C process number by command name.
rcp file remotemachine -- used to copy from a remote computer. See also ftp, scp, sftp.
rlogin host -- utility to connect to a remote system. See also ftp, ssh, sftp, telnet.
rm filename: removes a file
rsh command -- utility to run a command on a remote system without logging in.
rsync -- a very powerful backup utility that runs via ssh. See also: cp, sftp, ssh.
screen -- opens a new teletype console within, say, an ssh session, which allows you to run commands and then detach from that terminal without killing the process. See also bg and disown.
sftp -- use the secure file transfer subsystem of the ssh protocol. Useful commands: put, get, cd (change directories in the remote machine) , lcd (local cd), ls, lls, you get the idea. Very useful flag: -oPort=####. See also ftp.
ssh -- a means of accessing a computer remotely. From an admin standpoint, this is as good as sitting in front of the box.
startx -- starts an X Window System server
strace -- useful for debugging, it logs every system call. If you're using this, something has probably gone wrong. Eg. to find out what happens while using rpm to install a package, you could run "strace -s 255 -o /tmp/rpm.log rpm -U your_rpm_file_name.rpm"
service -- commonly used on Red Hat systems to start and stop services.
tail filename -- displays last 10 lines of file. See also: cat, head, less, more.
talk user -- allows two way chat to other users. See also mesg, w, who, write.
tar -- extract an archive in the directory you're currently in, eg: to unpack a wordpress tarball, you might "tar -xzvf wordpress-2.5.1.tar.gz". See also gzip, gunzip.
telnet host -- utility to connect to a remote system (similar to rlogin but more interactive). See also ssh.
top -- displays updating list of running processes, sortable by cpu time, memory, etc
touch -- make an empty file
traceroute host -- prints the route packets take to the host. See also finger, netstat, nslookup.
tty -- displays the name of the terminal in which the command was issued
uname -- name of the operating system currently running. See also hostname.
vi -- the standard Unix text editor. Very good, but missing some basic user friendliness, like arrow keys. There is a command mode where keys do things, and an insert mode where keys leave characters in the buffer. In command mode, to move, use h, j, k, l. To enter insert mode, type i. To return to command mode, hit esc. There are lots of cheatsheets, google for them.
vim -- vi modified for humans with modern keyboards and color monitors. Because the backspace key doesn't suck.
w -- who's currently logged on, with processing usage
wget -- download a file from the internet to the directory you're currently in, eg: wget http://wordpress.org/wordpress-2.5.1.tar.gz. See also curl.
whereis command -- displays paths to locations of commands. See also which.
which command -- displays path to command. See also whereis.
who -- lists currently logged on users. See also mesg, talk, w, write.
write username -- exchange messages with someone else online. See also mesg, talk, w, who.
yum -- install a standard package maintained by CentOS in it's online repositories. eg: "yum install perl" will install perl. This very powerful package manager is the preferred way to install software in Red Hat based distros. It can get quite complicated, receiving packages from all sorts of non-standard repos, etc. See also apt, rpm.
zfs list -- list the user filesystems in a pool.
zpool -- manage a zfs storage pool and all the file systems in it.
Some other shells you might want to try
bash (default)
korn (the original)
zsh (Sun's be-all-end-all shell. According to them)
Regular expressions
I am woefully uninformed about the hallowed regex world. Those more informed souls, please contribute.
* -- wildcard for any number of characters
% -- wildcard for one character
Scripting -- the extreme basics
A basic shell script:
#!/bin/sh
echo "City Sky Tc Tl Th Wind Baro"
curl -s http://www.srh.noaa.gov/data/LIX/RWRLA | grep "BELLE CHASSE"
What I'd really like to see in this section are scripts in python, php, perl, scheme, , etc, that can be dropped into a web-accessible directory, which will render a form that asks for your first and last names, take the input you submit, store it in a MySQL database, and then asks you to query a first name, and prints all associated last names in the database. Why? Because I have no idea how to do that in any language except I bought php and MySQL book once that showed the script for this in two pages of code, and I keep meaning to implement that to start really learning web programming, but I never get around to it.