Linux Command-Line Cheat Sheet

ADVERTISEMENT

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

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education
Go