Você está na página 1de 1

V0.

3 (April 2009)
Linux command-line
Cheat Sheet

Environment Network
Compress and archive
Verify and set the environment variables in BASH. Miscellaneous commands for networking.
Useful tools for compressing and archive files.
export VAR=content Store the variable with
content cvf filename.tar files Archive List all active interfaces
tar
env Display environment vars xvf filename.tar Unarchive Display information
eth0
ifconfig about eth0 interface.
echo $PATH Display path where cvfz filename.tgz files Arch+Compress
commands are located. tar eth0 up Brings up eth0.
xvfz filename.tgz Uncompress
$HOME Location of the home dir eth0 1.1.1.1 Give a static IP to eth0.
bzip2 files Compress
$SHELL Shell in use route -n List all routes.
bunzip2 finaname.bz2 Decompress
$LD_LIBRARY Directory with dynamic Send a packet to
_PATH shared libraries. zip files filename.zip Compress ping hostname
hostname machine.
$DISPLAY To which display applications unzip filename.zip Decompress List all open ports and
should be sent netstat -a conections in and out
of the machine.
alias newalias=cmd Set a new alias
List process that is
locale Show language settings lsof -i:80
listening in port 80.

~/.bashrc Where alias and Redirection Establish a secure shell


environment vars can be ssh server
to server
~/.bash_profile
stored to persist Redirect input (stdin), errors (stderr) and output (stdout)
between files and applications. Copy file to remote
scp file user@1.1.1.1:/ location “/” in server
1.1.1.1 as “user”.
echo msg > file1 Redirect stdout to file1

Configuring the system echo msg 2> file1 Redirect stderr to file1

myprog &> file1 Redirect both stdout and Session


Command line applications provided by distributions to stderr to file
configure the system. Useful shortcuts and commands for advanced session
drakconf Mandriva, Caixa Mágica myprog < file1 Redirect file1 content into management.
stdin of myprog
d Exit from the command line.
(?) Debian, Ubuntu
echo msg | myprog Redirect stdout to myprog
s Freezes stdout.
(?) Fedora Control
+ q Unfreezes stdout.
yast2 (?) OpenSuSE
Look backward in command
r
history
Complete the prompt with the
Locating files Up last matching command in
Page history
Files and directories Commands for managing files and directories.
Down The next matching command.
Commands for managing files and directories whereis command Where in $PATH is Launch screen.
ls -al List files command
screen (Ctrl-A d) Dettach session.
cp file1 dir2/ Copy file to directory dir2/ locate -i file Locate file in disk (-i = not
case sensitive). Requires -r Reattach a previous session.
mv file1 dir2/ Move file / rename file updatedb before.

cat file1 Show content of a text file1 updatedb Updates the database of
existent files and directories. Help
rm file1 Delete file1
/ -name file Finds recursively starting in
If none of the above works for you, try this.
mkdir dir Create directory find location “/” the file with the
given name. man command Get information about
cd dir Change into directory command.
. -exec ls {} \; Executes command “ls” over
find each entry of find result 1 command Get section 1 of command
man page.
-k string List all commands with
System status & Users “string” in the description .

Get information about system and manage users.


Parsing info command Display documentation in
info format for command.
ps -aux List processes. Commands for parsing files and messages.

pstree List processes as a tree.


Prints line where pattern
pattern file
top Sort processes by CPU (or occur in file.
RAM). grep -E ext_regexp file Use extend regexp.
free Check free memory and swap.
-P Perl_regexp file Use Perl regexp.

df -h Show disk space in active Print field 2 of each line of Get updates of this Linux command-line Cheat
awk '{print $2}' file
file (space separated). Sheet in:
partitions.
http://paulotrezentos.polo-sul.org/cheatsheet/
vmstat -d Display virtual memory, CPU Sends to stdout the
and IO statistics sed s/str1/str2 file1 content of file1 replacing
str1 by str2. Paulo.Trezentos@iscte.pt
uname -a Show info about Kernel & hw. Paulo.Trezentos@caixamagica.pt

useradd -m user Add an user, copy skel. This cheat sheet is under:

userdel user Delete an user.

Você também pode gostar