Thursday, April 5, 2012

Linux

 Linux :-


CommandDescription
•apropos whatisShow commands pertinent to string. See also threadsafe
•man -t ascii | ps2pdf - > ascii.pdfmake a pdf of a manual page
which commandShow full path name of command
time commandSee how long a command takes
•time catStart stopwatch. Ctrl-d to stop. See also sw
dir navigation
•cd -Go to previous directory
•cdGo to $HOME directory
(cd dir && command)Go to dir, execute command and return to current dir
•pushd .Put current dir on stack so you can popd back to it
•alias l='ls -l --color=auto'quick dir listing
•ls -lrtList files by date. See also newest and find_mm_yyyy
•ls /usr/bin | pr -T9 -W$COLUMNSPrint in 9 columns to width of terminal
find -name '*.[ch]' | xargs grep -E 'expr'Search 'expr' in this dir and below. See also findrepo
find -type f -print0 | xargs -r0 grep -F 'example'Search all regular files for 'example' in this dir and below
find -maxdepth 1 -type f | xargs grep -F 'example'Search all regular files for 'example' in this dir
find -maxdepth 1 -type d | while read dir; do echo $dir; echo cmd2; doneProcess each item with multiple commands (in while loop)
•find -type f ! -perm -444Find files not readable by all (useful for web site)
•find -type d ! -perm -111Find dirs not accessible by all (useful for web site)
•locate -r 'file[^/]*\.txt'Search cached index for names. This re is like glob *file*.txt
•look referenceQuickly search (sorted) dictionary for prefix
•grep --color reference /usr/share/dict/wordsHighlight occurances of regular expression in dictionary
archives and compression
gpg -c fileEncrypt file
gpg file.gpgDecrypt file
tar -c dir/ | bzip2 > dir.tar.bz2Make compressed archive of dir/
bzip2 -dc dir.tar.bz2 | tar -xExtract archive (use gzip instead of bzip2 for tar.gz files)
tar -c dir/ | gzip | gpg -c | ssh user@remote 'dd of=dir.tar.gz.gpg'Make encrypted archive of dir/ on remote machine
find dir/ -name '*.txt' | tar -c --files-from=- | bzip2 > dir_txt.tar.bz2Make archive of subset of dir/ and below
find dir/ -name '*.txt' | xargs cp -a --target-directory=dir_txt/ --parentsMake copy of subset of dir/ and below
( tar -c /dir/to/copy ) | ( cd /where/to/ && tar -x -p )Copy (with permissions) copy/ dir to /where/to/ dir
( cd /dir/to/copy && tar -c . ) | ( cd /where/to/ && tar -x -p )Copy (with permissions) contents of copy/ dir to /where/to/
( tar -c /dir/to/copy ) | ssh -C user@remote 'cd /where/to/ && tar -x -p'Copy (with permissions) copy/ dir to remote:/where/to/ dir
dd bs=1M if=/dev/sda | gzip | ssh user@remote 'dd of=sda.gz'Backup harddisk to remote machine
rsync (Network efficient file copier: Use the --dry-run option for testing)
rsync -P rsync://rsync.server.com/path/to/file fileOnly get diffs. Do multiple times for troublesome downloads
rsync --bwlimit=1000 fromfile tofileLocally copy with rate limit. It's like nice for I/O
rsync -az -e ssh --delete ~/public_html/ remote.com:'~/public_html'Mirror web site (using compression and encryption)
rsync -auz -e ssh remote:/dir/ . && rsync -auz -e ssh . remote:/dir/Synchronize current directory with remote one
ssh (Secure SHell)
ssh $USER@$HOST commandRun command on $HOST as $USER (default command=shell)
•ssh -f -Y $USER@$HOSTNAME xeyesRun GUI command on $HOSTNAME as $USER
scp -p -r $USER@$HOST: file dir/Copy with permissions to $USER's home directory on $HOST
scp -c arcfour $USER@$LANHOST: bigfileUse faster crypto for local LAN. This might saturate GigE
ssh -g -L 8080:localhost:80 root@$HOSTForward connections to $HOSTNAME:8080 out to $HOST:80
ssh -R 1434:imap:143 root@$HOSTForward connections from $HOST:1434 in to imap:143
ssh-copy-id $USER@$HOSTInstall public key for $USER@$HOST for password-less log in
wget (multi purpose download tool)
•(cd dir/ && wget -nd -pHEKk http://www.pixelbeat.org/cmdline.html)Store local browsable version of a page to the current dir
wget -c http://www.example.com/large.fileContinue downloading a partially downloaded file
wget -r -nd -np -l1 -A '*.jpg' http://www.example.com/dir/Download a set of files to the current directory
wget ftp://remote/file[1-9].iso/FTP supports globbing directly
•wget -q -O- http://www.pixelbeat.org/timeline.html | grep 'a href' | headProcess output directly
echo 'wget url' | at 01:00Download url at 1AM to current dir
wget --limit-rate=20k urlDo a low priority download (limit to 20KB/s in this case)
wget -nv --spider --force-html -i bookmarks.htmlCheck links in a file
wget --mirror http://www.example.com/Efficiently update a local copy of a site (handy from cron)
networking (Note ifconfig, route, mii-tool, nslookup commands are obsolete)
ethtool eth0Show status of ethernet interface eth0
ethtool --change eth0 autoneg off speed 100 duplex fullManually set ethernet interface speed
iwconfig eth1Show status of wireless interface eth1
iwconfig eth1 rate 1Mb/s fixedManually set wireless interface speed
•iwlist scanList wireless networks in range
•ip link showList network interfaces
ip link set dev eth0 name wanRename interface eth0 to wan
ip link set dev eth0 upBring interface eth0 up (or down)
•ip addr showList addresses for interfaces
ip addr add 1.2.3.4/24 brd + dev eth0Add (or del) ip and mask (255.255.255.0)
•ip route showList routing table
ip route add default via 1.2.3.254Set default gateway to 1.2.3.254
•host pixelbeat.orgLookup DNS ip address for name or vice versa
•hostname -iLookup local ip address (equivalent to host `hostname`)
•whois pixelbeat.orgLookup whois info for hostname or ip address
•netstat -tuplList internet services on a system
•netstat -tupList active connections to/from system
windows networking (Note samba is the package that provides all this windows specific networking support)
•smbtreeFind windows machines. See also findsmb
nmblookup -A 1.2.3.4Find the windows (netbios) name associated with ip address
smbclient -L windows_boxList shares on windows machine or samba server
mount -t smbfs -o fmask=666,guest //windows_box/share /mnt/shareMount a windows share
echo 'message' | smbclient -M windows_boxSend popup to windows machine (off by default in XP sp2)
text manipulation (Note sed uses stdin and stdout. Newer versions support inplace editing with the -i option)
sed 's/string1/string2/g'Replace string1 with string2
sed 's/\(.*\)1/\12/g'Modify anystring1 to anystring2
sed '/ *#/d; /^ *$/d'Remove comments and blank lines
sed ':a; /\\$/N; s/\\\n//; ta'Concatenate lines with trailing \
sed 's/[ \t]*$//'Remove trailing spaces from lines
sed 's/\([`"$\]\)/\\\1/g'Escape shell metacharacters active within double quotes
•seq 10 | sed "s/^/      /; s/ *\(.\{7,\}\)/\1/"Right align numbers
sed -n '1000{p;q}'Print 1000th line
sed -n '10,20p;20q'Print lines 10 to 20
sed -n 's/.*<title>\(.*\)<\/title>.*/\1/ip;T;q'Extract title from HTML web page
sed -i 42d ~/.ssh/known_hostsDelete a particular line
sort -t. -k1,1n -k2,2n -k3,3n -k4,4nSort IPV4 ip addresses
•echo 'Test' | tr '[:lower:]' '[:upper:]'Case conversion
•tr -dc '[:print:]' < /dev/urandomFilter non printable characters
•tr -s '[:blank:]' '\t' </proc/diskstats | cut -f4cut fields separated by blanks
•history | wc -lCount lines
set operations (Note you can export LANG=C for speed. Also these assume no duplicate lines within a file)
sort file1 file2 | uniqUnion of unsorted files
sort file1 file2 | uniq -dIntersection of unsorted files
sort file1 file1 file2 | uniq -uDifference of unsorted files
sort file1 file2 | uniq -uSymmetric Difference of unsorted files
join -t'\0' -a1 -a2 file1 file2Union of sorted files
join -t'\0' file1 file2Intersection of sorted files
join -t'\0' -v2 file1 file2Difference of sorted files
join -t'\0' -v1 -v2 file1 file2Symmetric Difference of sorted files
math
•echo '(1 + sqrt(5))/2' | bc -lQuick math (Calculate φ). See also bc
•seq -f '4/%g' 1 2 99999 | paste -sd-+ | bc -lCalculate Ï€ the unix way
•echo 'pad=20; min=64; (100*10^6)/((pad+min)*8)' | bcMore complex (int) e.g. This shows max FastE packet rate
•echo 'pad=20; min=64; print (100E6)/((pad+min)*8)' | pythonPython handles scientific notation
•echo 'pad=20; plot [64:1518] (100*10**6)/((pad+x)*8)' | gnuplot -persistPlot FastE packet rate vs packet size
•echo 'obase=16; ibase=10; 64206' | bcBase conversion (decimal to hexadecimal)
•echo $((0x2dec))Base conversion (hex to dec) ((shell arithmetic expansion))
•units -t '100m/9.58s' 'miles/hour'Unit conversion (metric to imperial)
•units -t '500GB' 'GiB'Unit conversion (SI to IEC prefixes)
•units -t '1 googol'Definition lookup
•seq 100 | (tr '\n' +; echo 0) | bcAdd a column of numbers. See also add and funcpy
calendar
•cal -3Display a calendar
•cal 9 1752Display a calendar for a particular month year
•date -d friWhat date is it this friday. See also day
•[ $(date -d '12:00 +1 day' +%d) = '01' ] || exitexit a script unless it's the last day of the month
•date --date='25 Dec' +%AWhat day does xmas fall on, this year
•date --date='@2147483647'Convert seconds since the epoch (1970-01-01 UTC) to date
•TZ='America/Los_Angeles' dateWhat time is it on west coast of US (use tzselect to find TZ)
•date --date='TZ="America/Los_Angeles" 09:00 next Fri'What's the local time for 9AM next Friday on west coast US
locales
•printf "%'d\n" 1234Print number with thousands grouping appropriate to locale
•BLOCK_SIZE=\'1 ls -lUse locale thousands grouping in ls. See also l
•echo "I live in `locale territory`"Extract info from locale database
•LANG=en_IE.utf8 locale int_prefixLookup locale info for specific country. See also ccodes
•locale -kc $(locale | sed -n 's/\(LC_.\{4,\}\)=.*/\1/p') | lessList fields available in locale database
recode (Obsoletes iconv, dos2unix, unix2dos)
•recode -l | lessShow available conversions (aliases on each line)
recode windows-1252.. file_to_change.txtWindows "ansi" to local charset (auto does CRLF conversion)
recode utf-8/CRLF.. file_to_change.txtWindows utf8 to local charset
recode iso-8859-15..utf8 file_to_change.txtLatin9 (western europe) to utf8
recode ../b64 < file.txt > file.b64Base64 encode
recode /qp.. < file.qp > file.txtQuoted printable decode
recode ..HTML < file.txt > file.htmlText to HTML
•recode -lf windows-1252 | grep euroLookup table of characters
•echo -n 0x80 | recode latin-9/x1..dumpShow what a code represents in latin-9 charmap
•echo -n 0x20AC | recode ucs-2/x2..latin-9/xShow latin-9 encoding
•echo -n 0x20AC | recode ucs-2/x2..utf-8/xShow utf-8 encoding
CDs
gzip < /dev/cdrom > cdrom.iso.gzSave copy of data cdrom
mkisofs -V LABEL -r dir | gzip > cdrom.iso.gzCreate cdrom image from contents of dir
mount -o loop cdrom.iso /mnt/dirMount the cdrom image at /mnt/dir (read only)
cdrecord -v dev=/dev/cdrom blank=fastClear a CDRW
gzip -dc cdrom.iso.gz | cdrecord -v dev=/dev/cdrom -Burn cdrom image (use dev=ATAPI -scanbus to confirm dev)
cdparanoia -BRip audio tracks from CD to wav files in current dir
cdrecord -v dev=/dev/cdrom -audio -pad *.wavMake audio CD from all wavs in current dir (see also cdrdao)
oggenc --tracknum='track' track.cdda.wav -o 'track.ogg'Make ogg file from wav file
disk space (See also FSlint)
•ls -lSrShow files by size, biggest last
•du -s * | sort -k1,1rn | headShow top disk users in current dir. See also dutop
•du -hs /home/* | sort -k1,1hSort paths by easy to interpret disk usage
•df -hShow free space on mounted filesystems
•df -iShow free inodes on mounted filesystems
•fdisk -lShow disks partitions sizes and types (run as root)
•rpm -q -a --qf '%10{SIZE}\t%{NAME}\n' | sort -k1,1nList all packages by installed size (Bytes) on rpm distros
•dpkg-query -W -f='${Installed-Size;10}\t${Package}\n' | sort -k1,1nList all packages by installed size (KBytes) on deb distros
•dd bs=1 seek=2TB if=/dev/null of=ext3.testCreate a large test file (taking no space). See also truncate
•> filetruncate data of file or create an empty file
monitoring/debugging
•tail -f /var/log/messagesMonitor messages in a log file
•strace -c ls >/dev/nullSummarise/profile system calls made by command
•strace -f -e open ls >/dev/nullList system calls made by command
•strace -f -e trace=write -e write=1,2 ls >/dev/nullMonitor what's written to stdout and stderr
•ltrace -f -e getenv ls >/dev/nullList library calls made by command
•lsof -p $$List paths that process id has open
•lsof ~List processes that have specified path open
•tcpdump not port 22Show network traffic except ssh. See also tcpdump_not_me
•ps -e -o pid,args --forestList processes in a hierarchy
•ps -e -o pcpu,cpu,nice,state,cputime,args --sort pcpu | sed '/^ 0.0 /d'List processes by % cpu usage
•ps -e -orss=,args= | sort -b -k1,1n | pr -TW$COLUMNSList processes by mem (KB) usage. See also ps_mem.py
•ps -C firefox-bin -L -o pid,tid,pcpu,stateList all threads for a particular process
•ps -p 1,$$ -o etime=List elapsed wall time for particular process IDs
•last rebootShow system reboot history
•free -mShow amount of (remaining) RAM (-m displays in MB)
•watch -n.1 'cat /proc/interrupts'Watch changeable data continuously
•udevadm monitorMonitor udev events to help configure rules
system information (see also sysinfo) ('#' means root access is required)
•uname -aShow kernel version and system architecture
•head -n1 /etc/issueShow name and version of distribution
•cat /proc/partitionsShow all partitions registered on the system
•grep MemTotal /proc/meminfoShow RAM total seen by the system
•grep "model name" /proc/cpuinfoShow CPU(s) info
•lspci -tvShow PCI info
•lsusb -tvShow USB info
•mount | column -tList mounted filesystems on the system (and align output)
•grep -F capacity: /proc/acpi/battery/BAT0/infoShow state of cells in laptop battery
#dmidecode -q | lessDisplay SMBIOS/DMI information
#smartctl -A /dev/sda | grep Power_On_HoursHow long has this disk (system) been powered on in total
#hdparm -i /dev/sdaShow info about disk sda
#hdparm -tT /dev/sdaDo a read speed test on disk sda
#badblocks -s /dev/sdaTest for unreadable blocks on disk sda
interactive (see also linux keyboard shortcuts)
•readlineLine editor used by bash, python, bc, gnuplot, ...
•screenVirtual terminals with detach capability, ...
•mcPowerful file manager that can browse rpm, tar, ftp, ssh, ...
•gnuplotInteractive/scriptable graphing
•linksWeb browser
•xdg-open .open a file or url with the registered desktop application

Basic Linux Commands

Linux Commands:-






catSends file contents to standard output. This is a way to list the contents of short files to the screen. It works well with piping.
cat .bashrcSends the contents of the ".bashrc" file to the screen.
cdChange directory
cd /homeChange the current working directory to /home. The '/' indicates relative to root, and no matter what directory you are in when you execute this command, the directory will be changed to "/home".
cd httpdChange the current working directory to httpd, relative to the current location which is "/home". The full path of the new working directory is "/home/httpd".
cd ..Move to the parent directory of the current directory. This command will make the current working directory "/home.
cd ~Move to the user's home directory which is "/home/username". The '~' indicates the users home directory.
cpCopy files
cp myfile yourfileCopy the files "myfile" to the file "yourfile" in the current working directory. This command will create the file "yourfile" if it doesn't exist. It will normally overwrite it without warning if it exists.
cp -i myfile yourfileWith the "-i" option, if the file "yourfile" exists, you will be prompted before it is overwritten.
cp -i /data/myfile .Copy the file "/data/myfile" to the current working directory and name it "myfile". Prompt before overwriting the file.
cp -dpr srcdir destdirCopy all files from the directory "srcdir" to the directory "destdir" preserving links (-p option), file attributes (-p option), and copy recursively (-r option). With these options, a directory and all it contents can be copied to another directory.
dddd if=/dev/hdb1 of=/backup/Disk duplicate. The man page says this command is to "Convert and copy a file", but although used by more advanced users, it can be a very handy command. The "if" means input file, "of" means output file.
dfShow the amount of disk space used on each mounted filesystem.
lessless textfileSimilar to the more command, but the user can page up and down through the file. The example displays the contents of textfile.
lnCreates a symbolic link to a file.
ln -s test symlinkCreates a symbolic link named symlink that points to the file test Typing "ls -i test symlink" will show the two files are different with different inodes. Typing "ls -l test symlink" will show that symlink points to the file test.
locateA fast database driven file locator.
slocate -uThis command builds the slocate database. It will take several minutes to complete this command. This command must be used before searching for files, however cron runs this command periodically on most systems.
locate whereisLists all files whose names contain the string "whereis".
logoutLogs the current user off the system.
lsList files
lsList files in the current working directory except those starting with . and only show the file name.
ls -alList all files in the current working directory in long listing format showing permissions, ownership, size, and time and date stamp
moreAllows file contents or piped output to be sent to the screen one page at a time.
more /etc/profileLists the contents of the "/etc/profile" file to the screen one page at a time.
ls -al |morePerforms a directory listing of all files and pipes the output of the listing through more. If the directory listing is longer than a page, it will be listed one page at a time.
mvMove or rename files
mv -i myfile yourfileMove the file from "myfile" to "yourfile". This effectively changes the name of "myfile" to "yourfile".
mv -i /data/myfile .Move the file from "myfile" from the directory "/data" to the current working directory.
pwdShow the name of the current working directory
more /etc/profileLists the contents of the "/etc/profile" file to the screen one page at a time.
shutdownShuts the system down.
shutdown -h nowShuts the system down to halt immediately.
shutdown -r nowShuts the system down immediately and the system reboots.
whereisShow where the binary, source and manual page files are for a command

whereis lsLocates binaries and manual pages for the ls command.








Editors: emacs, vi, pico, jed, vim



Linux Commands:-





A
  • alias - create names or abbreviations for commands
  • apropos - search the manual page names and descriptions
  • at  - queue, examine or delete jobs for later execution
B
  • bc  - An arbitrary precision calculator language
C
  • cal - displays a calendar
  • cat  - concatenate files and print on the standard output
  • cd - change directory
  • chgrp  - change group ownership
  • chmod  - change file access permissions
  • cksum  - checksum and count the bytes in a file
  • cp  - copy files and directories
  • csplit  - split a file into sections determined by context lines
D
  • date  - print or set the system date and time
  • dd  - convert and copy a file
  • du  - estimate file space usage
E
  • egrep  - print lines matching a pattern
  • export - set an environment variable
F

  • fgrep  - print lines matching a pattern
  • find - search for files in a directory hierarchy
  • fold  - wrap each input line to fit in specified width
G
  • grep  - print lines matching a pattern
H

  • head  - output the first part of files
I
J
  • join  - join lines of two files on a common field
K
L
  • logrotate  - rotates, compresses, and mails system logs
  • ls [man page] - list directory contents
M
  • mkdir  - make directories
  • mv  - move (rename) files
  • mount  - mount a file system
N
  • nl  - number lines of files
O
  • od  - dump files in octal and other formats
P
  • pwd  - print name of current/working directory
Q
R
  • rgrep  - print lines matching a pattern
  • rm  - remove files or directories
S
  • scp - secure copy (remote file copy program)
  • ssh - OpenSSH SSH client (remote login program)
T
  • tail - output the last part of files
  • tar  - The GNU version of the tar archiving utility
  • tee  - read from standard input and write to standard output and files
  • time  - run programs and summarize system resource usage
  • touch  - change file timestamps
V
  • vim - Vi IMproved, a programmers text editor
W
  • watch  - execute a program periodically, showing output fullscreen
  • wc  - print newline, word, and byte counts for each file
  • whoami  - print effective userid
X

  • Y yes  - output a string repeatedly until killed             



ls : list files/directories in a directory, comparable to dir in windows/dos.
ls -al : shows all files (including ones that start with a period), directories, and details attributes for each file.
cd : change directory
cd /usr/local/apache : go to /usr/local/apache/ directory
cd ~ : go to your home directory
cd – : go to the last directory you were in
cd .. : go up a directory
cat : print file contents to the screen
cat filename.txt : cat the contents of filename.txt to your screen
tail : like cat, but only reads the end of the file
tail /var/log/messages : see the last 20 (by default) lines of /var/log/messages
tail -f /var/log/messages : watch the file continuously, while it’s being updated
tail -200 /var/log/messages : print the last 200 lines of the file to the screen
more : like cat, but opens the file one screen at a time rather than all at once
more /etc/userdomains : browse through the userdomains file. hit to go to the next page, to quit
pico : friendly, easy to use editor. A clone of it is “nano”
pico /home/burst/public_html/index.html : edit the index page for the user’s website.
vi : another editor, tons of features, harder to use at first than pico
vi /home/burst/public_html/index.html : edit the index page for the user’s website.
grep : looks for patterns in files
grep root /etc/passwd : shows all matches of root in /etc/passwd
grep -v root /etc/passwd : shows all lines that do not match root
touch : create an empty file
touch /home/burst/public_html/404.html : create an empty file called 404.html in the directory /home/burst/public_html/
ln : create’s “links” between files and directories
ln -s /usr/local/apache/conf/httpd.conf /etc/httpd.conf : Now you can edit /etc/httpd.conf rather than the original. changes
will affect the orginal, however you can delete the link and it will not delete the original.
rm : delete a file
rm filename.txt : deletes filename.txt, will more than likely ask if you really want to delete it.
rm -f filename.txt : deletes filename.txt, will not ask for confirmation before deleting.
rm -rf tmp/ : recursively deletes the directory tmp, and all files in it, including subdirectories. BE VERY CAREFULL WITH THIS COMMAND!!!
last : shows who logged in and when
last -20 : shows only the last 20 logins
last -20 -a : shows last 20 logins, with the hostname in the last field
w : shows who is currently logged in and where they are logged in from.
netstat : shows all current network connections.
netstat -an : shows all connections to the server, the source and destination ips and ports.
netstat -rn : shows routing table for all ips bound to the server.
file : attempts to guess what type of file a file is by looking at it’s content.
file * : prints out a list of all files/directories in a directory
du : shows disk usage.
du -sh : shows a summary, in human-readble form, of total disk space used in the current directory, including subdirectories.
du -sh * : same thing, but for each file and directory. helpful when finding large files taking up space.
wc : word count
wc -l filename.txt : tells how many lines are in filename.txt
cp : copy a file
cp filename filename.backup : copies filename to filename.backup
cp -a /home/burst/new_design/* /home/burst/public_html/ : copies all files, retaining permissions form one directory to another.
Putting commands together.
Often you will find you need to use different commands on the same line. Here are some examples.
Note that the | character is called a pipe, it takes date from one program and pipes it to another.
> means create a new file, overwriting any content already there.
>> means tp append data to a file, creating a newone if it doesn not already exist.
< send input from a file back into a command.
grep User /usr/local/apache/conf/httpd.conf |more
-- this will dump all lines that match User from the httpd.conf, then print the results to your screen one page at a time.
last -a > /root/lastlogins.tmp
— this will print all the current login history to a file called lastlogins.tmp in /root/
tail -10000 /var/log/exim_mainlog |grep domain\.com |more
— this will grab the last 10,000 lines from /var/log/exim_mainlog, find all occurances of domain.com (the period represents ‘anything’,
— comment it out with a \ so it will be interpretted literally), then send it to your screen page by page.
netstat -an |grep :80 |wc -l
— show how many active connections there are to apache (httpd runs on port 80)
mysqladmin processlist |wc -l
— show how many current open connections there are to mysql

Linux keyboard shortcuts - 2.0

keyboard shortcuts:-



Virtual terminals 

Ctrl + Alt + F1
Switch to the first virtual terminal. In Linux, you can have several virtual terminals at the same time. The default is 6.
Ctrl + Alt + Fn
Switch to the nth virtual terminal. Because the number of virtual terminals is 6 by default, n = 1...6.
tty
Typing the tty command tells you what virtual terminal you're currently working in.
Ctrl + Alt + F7
Switch to the GUI. If you have the X Window System running, it runs in the seventh virtual terminal by default in most Linux distros. If X isn't running, this terminal is empty.
Note: in some distros, X runs in a different virtual terminal by default. For example, in Puppy Linux, it's 3.

 X Window System 

Ctrl + Alt + +
Switch to the next resolution in the X Window System. This works if you've configured more than one resolution for your X server. Note that you must use the + in your numpad.
Ctrl + Alt + -
Switch to the previous X resolution. Use the - in your numpad.
MiddleMouseButton
Paste the highlighted text. You can highlight the text with your left mouse button (or with some other highlighting method, depending on the application you're using), and then press the middle mouse button to paste. This is the traditional way of copying and pasting in the X Window System, but it may not work in some X applications.
If you have a two-button mouse, pressing both of the buttons at the same time has the same effect as pressing the middle one. If it doesn't, you must enable 3-mouse-button emulation.
This works also in text terminals if you enable the gpm service.
Ctrl + Alt + Backspace
Kill the X server. Use this if X crashes and you can't exit it normally. If you've configured your X Window System to start automatically at bootup, this restarts the server and throws you back to the graphical login screen.


 Command line - input 

Home or Ctrl + a
Move the cursor to the beginning of the current line.
End or Ctrl + e
Move the cursor to the end of the current line.
Alt + b
Move the cursor to the beginning of the current or previous word. Note that while this works in virtual terminals, it may not work in all graphical terminal emulators, because many graphical applications already use this as a menu shortcut by default.
Alt + f
Move the cursor to the end of the next word. Again, like with all shortcuts that use Alt as the modifier, this may not work in all graphical terminal emulators.
Tab
Autocomplete commands and file names. Type the first letter(s) of a command, directory or file name, press Tab and the rest is completed automatically! If there are more commands starting with the same letters, the shell completes as much as it can and beeps. If you then press Tab again, it shows you all the alternatives.
This shortcut is really helpful and saves a lot of typing! It even works at the lilo prompt and in some X applications.
Ctrl + u
Erase the current line.
Ctrl + k
Delete the line from the position of the cursor to the end of the line.
Ctrl + w
Delete the word before the cursor.


 Command line - output 

Shift + PageUp
Scroll terminal output up.
Shift + PageDown
Scroll terminal output down.
clear
The clear command clears all previously executed commands and their output from the current terminal.
Ctrl + l
Does exactly the same as typing the clear command.
reset
If you mess up your terminal, use the reset command. For example, if you try to cat a binary file, the terminal starts showing weird characters. Note that you may not be able to see the command when you're typing it.


 Command line - history 

history
When you type the history command, you'll see a list of the commands you executed previously.
ArrowUp or Ctrl + p
Scroll up in the history and edit the previously executed commands. To execute them, press Enter like you normally do.
ArrowDown or Ctrl + n
Scroll down in the history and edit the next commands.
Ctrl + r
Find the last command that contained the letters you're typing. For example, if you want to find out the last action you did to a file called "file42.txt", you'll press Ctrl + r and start typing the file name. Or, if you want to find out the last parameters you gave to the "cp" command, you'll press Ctrl + r and type in "cp".


 Command line - misc

Ctrl + c
Kill the current process.
Ctrl + z
Send the current process to background. This is useful if you have a program running, and you need the terminal for awhile but don't want to exit the program completely. Then just send it to background with Ctrl+z, do whatever you want, and type the command fg to get the process back.
Ctrl + d
Log out from the current terminal. If you use this in a terminal emulator under X, this usually shuts down the terminal emulator after logging you out.
Ctrl + Alt + Del
Reboot the system. You can change this behavior by editing /etc/inittab if you want the system to shut down instead of rebooting.