V0.3 (April 2009)
Linux command-line Cheat Sheet
Compress and archive
Useful tools for compressing and archive files. cvf filename.tar files xvf filename.tar cvfz filename.tgz files xvfz filename.tgz files Archive Unarchive Arch+Compress Uncompress Compress Decompress Compress Decompress
Environment
Verify and set the environment variables in BASH.
Network
Miscellaneous commands for networking. List all active interfaces
export VAR=content env echo
$PATH $HOME $SHELL
Store the variable with content Display environment vars Display path where commands are located. Location of the home dir Shell in use
tar tar bzip2
ifconfig
eth0 eth0 up eth0 1.1.1.1
Display information about eth0 interface. Brings up eth0. Give a static IP to eth0. List all routes. Send a packet to hostname machine. List all open ports and conections in and out of the machine. List process that is listening in port 80. Establish a secure shell to server Copy file to remote location “/” in server 1.1.1.1 as “user”.
bunzip2 finaname.bz2 zip unzip
files filename.zip filename.zip
route ping netstat lsof
-n hostname
$LD_LIBRARY Directory with dynamic _PATH shared libraries. $DISPLAY To which display applications should be sent Set a new alias Show language settings Where alias and environment vars can be stored to persist
-a
alias locale
newalias=cmd
-i:80 server
~/.bashrc ~/.bash_profile
Redirection
Redirect input (stdin), errors (stderr) and output (stdout) between files and applications.
ssh scp
file user@1.1.1.1:/
echo msg > file1
Redirect stdout to file1 Redirect stderr to file1 Redirect both stdout and stderr to file Redirect file1 content into stdin of myprog Redirect stdout to myprog
Configuring the system
Command line applications provided by distributions to configure the system.
echo msg 2> file1 myprog &> file1 myprog < file1 echo msg | myprog
Session
Useful shortcuts and commands for advanced session management. d Exit from the command line. Freezes stdout. Unfreezes stdout. Look backward in command history Complete the prompt with the last matching command in history The next matching command. Launch screen. s q r
drakconf (?) (?) yast2 (?)
Mandriva, Caixa Mágica Debian, Ubuntu Fedora OpenSuSE
Control +
Locating files Files and directories
Commands for managing files and directories Commands for managing files and directories.
Page
Up Down
whereis command locate
-i file
ls cp mv cat rm
-al file1 dir2/ file1 dir2/ file1 file1
List files Copy file to directory dir2/ Move file / rename file Show content of a text file1 Delete file1 Create directory Change into directory
Where in $PATH is command Locate file in disk (-i = not case sensitive). Requires updatedb before. Updates the database of existent files and directories.
screen
(Ctrl-A d) -r
Dettach session. Reattach a previous session.
updatedb
/ -name file
Help
If none of the above works for you, try this.
mkdir dir cd
dir
find find
Finds recursively starting in location “/” the file with the given name.
man
command 1 command -k string
. -exec ls {} \; Executes command “ls” over each entry of find result
Get information about command. Get section 1 of command man page. List all commands with “string” in the description . Display documentation in info format for command.
System status & Users
Get information about system and manage users.
Parsing
Commands for parsing files and messages. pattern file Prints line where pattern occur in file. Use extend regexp. Use Perl regexp. Print field 2 of each line of file (space separated). Sends to stdout the content of file1 replacing str1 by str2.
info
command
ps pstree top free df vmstat uname
-aux
List processes. List processes as a tree. Sort processes by CPU (or RAM). Check free memory and swap.
grep -E ext_regexp file
-P Perl_regexp file
-h -d -a
Show disk space in active partitions. Display virtual memory, CPU and IO statistics Show info about Kernel & hw. Add an user, copy skel. Delete an user.
awk sed
'{print $2}' file
Get updates of this Linux command-line Cheat Sheet in: http://paulotrezentos.polo-sul.org/cheatsheet/
Paulo.Trezentos@iscte.pt Paulo.Trezentos@caixamagica.pt This cheat sheet is under:
s/str1/str2 file1
useradd -m user userdel
user