Você está na página 1de 9

Command Description

apropos whatis Show commands pertinent to string. See also threadsafe


man -t ascii | ps2pdf - > ascii.pdf make a pdf of a manual page
which command Show full path name of command
time command See how long a command takes
time cat Start stopwatch. Ctrl-d to stop. See also sw
dir navigation
cd - Go to previous directory
cd Go to !"#$ directory
%cd dir && command' Go to dir( e)ecute command and return to current dir
pushd . *ut current dir on stack so you can popd +ack to it
file searching
alias l,-ls -l --color,auto- .uick dir listing
ls -lrt /ist files +y date. See also newest and find0mm0yyyy
ls 1usr1+in | pr -23 -4C"/5#6S *rint in 3 columns to width of terminal
find -name -7.8ch9- | )args grep -$ -e)pr- Search -e)pr- in this dir and +elow. See also findrepo
find -type f -print: | )args -r: grep -; -e)ample- Search all regular files for -e)ample- in this dir and +elow
find -ma)depth < -type f | )args grep -; -e)ample- Search all regular files for -e)ample- in this dir

find -ma)depth < -type d | while read dir= do echo dir=
echo cmd2= done
*rocess each item with multiple commands %in while
loop'
find -type f > -perm -??? ;ind files not reada+le +y all %useful for we+ site'
find -type d > -perm -<<< ;ind dirs not accessi+le +y all %useful for we+ site'
locate -r -file8@197A.t)t-
Search cached inde) for names. 2his re is like glo+
7file7.t)t
look reference Buickly search %sorted' dictionary for prefi)
grep --color reference 1usr1share1dict1words !ighlight occurances of regular e)pression in dictionary
archives and compression
gpg -c file $ncrypt file
gpg file.gpg Cecrypt file
tar -c dir1 | +Dip2 > dir.tar.+D2 #ake compressed archive of dir1
+Dip2 -dc dir.tar.+D2 | tar -) $)tract archive %use gDip instead of +Dip2 for tar.gD files'

tar -c dir1 | gDip | gpg -c | ssh userEremote -dd
of,dir.tar.gD.gpg-
#ake encrypted archive of dir1 on remote machine

find dir1 -name -7.t)t- | tar -c --files-from,- | +Dip2 >
dir0t)t.tar.+D2
#ake archive of su+set of dir1 and +elow

find dir1 -name -7.t)t- | )args cp -a --target-
directory,dir0t)t1 --parents
#ake copy of su+set of dir1 and +elow
% tar -c 1dir1to1copy ' | % cd 1where1to1 && tar -) -p ' Copy %with permissions' copy1 dir to 1where1to1 dir

% cd 1dir1to1copy && tar -c . ' | % cd 1where1to1 && tar -) -p
'
Copy %with permissions' contents of copy1 dir to
1where1to1

% tar -c 1dir1to1copy ' | ssh -C userEremote -cd 1where1to1
&& tar -) -p-
Copy %with permissions' copy1 dir to remoteF1where1to1 dir

dd +s,<# if,1dev1sda | gDip | ssh userEremote -dd
of,sda.gD-
Gackup harddisk to remote machine
rsync %6etwork efficient file copierF 5se the --dry-run option for testing'
rsync -* rsyncF11rsync.server.com1path1to1file file
"nly get diffs. Co multiple times for trou+lesome
downloads
rsync --+wlimit,<::: fromfile tofile /ocally copy with rate limit. Ht-s like nice for H1"

rsync -aD -e ssh --delete I1pu+lic0html1
remote.comF-I1pu+lic0html-
#irror we+ site %using compression and encryption'

rsync -auD -e ssh remoteF1dir1 . && rsync -auD -e
ssh . remoteF1dir1
SynchroniDe current directory with remote one
ssh %Secure S!ell'
ssh 5S$JE!"S2 command
Jun command on !"S2 as 5S$J %default
command,shell'
ssh -f -K 5S$JE!"S26L#$ )eyes Jun G5H command on !"S26L#$ as 5S$J
scp -p -r 5S$JE!"S2F file dir1
Copy with permissions to 5S$J-s home directory on
!"S2
scp -c arcfour 5S$JE/L6!"S2F +igfile 5se faster crypto for local /L6. 2his might saturate Gig$
ssh -g -/ M:M:FlocalhostFM: rootE!"S2
;orward connections to !"S26L#$FM:M: out to
!"S2FM:
ssh -J <?N?FimapF<?N rootE!"S2 ;orward connections from !"S2F<?N? in to imapF<?N
ssh-copy-id 5S$JE!"S2
Hnstall pu+lic key for 5S$JE!"S2 for password-less
log in
wget %multi purpose download tool'

%cd dir1 && wget -nd -p!$Ok


httpF11www.pi)el+eat.org1cmdline.html'
Store local +rowsa+le version of a page to the current dir
wget -c httpF11www.e)ample.com1large.file Continue downloading a partially downloaded file
wget -r -nd -np -l< -L -7.Ppg- httpF11www.e)ample.com1dir1 Cownload a set of files to the current directory
wget ftpF11remote1file8<-39.iso1 ;2* supports glo++ing directly

wget -. -"- httpF11www.pi)el+eat.org1timeline.html | grep


-a href- | head
*rocess output directly
echo -wget url- | at :<F:: Cownload url at <L# to current dir
wget --limit-rate,2:k url Co a low priority download %limit to 2:OG1s in this case'
wget -nv --spider --force-html -i +ookmarks.html Check links in a file
wget --mirror httpF11www.e)ample.com1 $fficiently update a local copy of a site %handy from cron'
networking %6ote ifconfig( route( mii-tool( nslookup commands are o+solete'
ethtool eth: Show status of ethernet interface eth:
ethtool --change eth: autoneg off speed <:: duple) full #anually set ethernet interface speed
iwconfig eth< Show status of wireless interface eth<
iwconfig eth< rate <#+1s fi)ed #anually set wireless interface speed
iwlist scan /ist wireless networks in range
ip link show /ist network interfaces
ip link set dev eth: name wan Jename interface eth: to wan
ip link set dev eth: up Gring interface eth: up %or down'
ip addr show /ist addresses for interfaces
ip addr add <.2.N.?12? +rd Q dev eth: Ldd %or del' ip and mask %2RR.2RR.2RR.:'
ip route show /ist routing ta+le
ip route add default via <.2.N.2R? Set default gateway to <.2.N.2R?
host pi)el+eat.org /ookup C6S ip address for name or vice versa
hostname -i /ookup local ip address %e.uivalent to host ShostnameS'
whois pi)el+eat.org /ookup whois info for hostname or ip address
netstat -tupl /ist internet services on a system
netstat -tup /ist active connections to1from system
windows networking %6ote sam+a is the package that provides all this windows specific networking support'
sm+tree ;ind windows machines. See also findsm+
nm+lookup -L <.2.N.?
;ind the windows %net+ios' name associated with ip
address
sm+client -/ windows0+o) /ist shares on windows machine or sam+a server

mount -t sm+fs -o fmask,TTT(guest
11windows0+o)1share 1mnt1share
#ount a windows share
echo -message- | sm+client -# windows0+o)
Send popup to windows machine %off +y default in U*
sp2'
text manipulation %6ote sed uses stdin and stdout. 6ewer versions support inplace editing with the -i option'
sed -s1string<1string21g- Jeplace string< with string2
sed -s1A%.7A'<1A<21g- #odify anystring< to anystring2
sed -1 7V1d= 1@ 71d- Jemove comments and +lank lines
sed -Fa= 1AA16= s1AAAn11= ta- Concatenate lines with trailing A
sed -s18 At9711- Jemove trailing spaces from lines
sed -s1A%8SWA9A'1AAA<1g- $scape shell metacharacters active within dou+le .uotes
se. <: | sed Ws1@1 1= s1 7A%.AXY(AZA'1A<1W Jight align num+ers
sed -n -<:::Xp=.Z- *rint <:::th line
sed -n -<:(2:p=2:.- *rint lines <: to 2:
sed -n -s1.7[title>A%.7A'[A1title>.71A<1ip=2=.- $)tract title from !2#/ we+ page
sed -i ?2d I1.ssh1known0hosts Celete a particular line
sort -t. -k<(<n -k2(2n -kN(Nn -k?(?n Sort H*\? ip addresses
echo -2est- | tr -8FlowerF9- -8FupperF9- Case conversion
tr -dc -8FprintF9- [ 1dev1urandom ;ilter non printa+le characters
tr -s -8F+lankF9- -At- [1proc1diskstats | cut -f? cut fields separated +y +lanks
history | wc -l Count lines
set operations %6ote you can e)port /L6G,C for speed. Llso these assume no duplicate lines within a file'
sort file< file2 | uni. 5nion of unsorted files
sort file< file2 | uni. -d Hntersection of unsorted files
sort file< file< file2 | uni. -u Cifference of unsorted files
sort file< file2 | uni. -u Symmetric Cifference of unsorted files
Poin -t-A:- -a< -a2 file< file2 5nion of sorted files
Poin -t-A:- file< file2 Hntersection of sorted files
Poin -t-A:- -v2 file< file2 Cifference of sorted files
Poin -t-A:- -v< -v2 file< file2 Symmetric Cifference of sorted files
math
echo -%< Q s.rt%R''12- | +c -l Buick math %Calculate ]'. See also +c
se. -f -?1^g- < 2 33333 | paste -sd-Q | +c -l Calculate _ the uni) way
echo -pad,2:= min,T?= %<::7<:@T'1%%padQmin'7M'- | +c #ore comple) %int' e.g. 2his shows ma) ;ast$ packet rate

echo -pad,2:= min,T?= print %<::$T'1%%padQmin'7M'- |


python
*ython handles scientific notation

echo -pad,2:= plot 8T?F<R<M9 %<::7<:77T'1%%padQ)'7M'- |


gnuplot -persist
*lot ;ast$ packet rate vs packet siDe
echo -o+ase,<T= i+ase,<:= T?2:T- | +c Gase conversion %decimal to he)adecimal'
echo %%:)2dec''
Gase conversion %he) to dec' %%shell arithmetic
e)pansion''
units -t -<::m13.RMs- -miles1hour- 5nit conversion %metric to imperial'
units -t -R::GG- -GiG- 5nit conversion %SH to H$C prefi)es'
units -t -< googol- Cefinition lookup
se. <:: | %tr -An- Q= echo :' | +c Ldd a column of num+ers. See also add and funcpy
calendar
cal -N Cisplay a calendar
cal 3 <YR2 Cisplay a calendar for a particular month year
date -d fri 4hat date is it this friday. See also day
8 %date -d WtomorrowW Q^d' , W:<W 9 || e)it e)it a script unless it-s the last day of the month
date --date,-2R Cec- Q^L 4hat day does )mas fall on( this year
date --date,-E2<?Y?MNT?Y-
Convert seconds since the epoch %<3Y:-:<-:< 52C' to
date
2`,-Lmerica1/os0Lngeles- date
4hat time is it on west coast of 5S %use tDselect to find
2`'
date --date,-2`,WLmerica1/os0LngelesW :3F:: ne)t ;ri-
4hat-s the local time for 3L# ne)t ;riday on west coast
5S
locales
printf W^-dAnW <2N?
*rint num+er with thousands grouping appropriate to
locale
G/"CO0SH`$,A-< ls -l 5se locale thousands grouping in ls. See also l
echo WH live in Slocale territorySW $)tract info from locale data+ase
/L6G,en0H$.utfM locale int0prefi) /ookup locale info for specific country. See also ccodes
locale -kc %locale | sed -n -s1A%/C0.AX?(AZA',.71A<1p-' | less /ist fields availa+le in locale data+ase
recode %"+soletes iconv( dos2uni)( uni)2dos'
recode -l | less Show availa+le conversions %aliases on each line'
recode windows-<2R2.. file0to0change.t)t
4indows WansiW to local charset %auto does CJ/;
conversion'
recode utf-M1CJ/;.. file0to0change.t)t 4indows utfM to local charset
recode iso-MMR3-<R..utfM file0to0change.t)t /atin3 %western europe' to utfM
recode ..1+T? [ file.t)t > file.+T? GaseT? encode
recode 1.p.. [ file..p > file.t)t Buoted printa+le decode
recode ..!2#/ [ file.t)t > file.html 2e)t to !2#/
recode -lf windows-<2R2 | grep euro /ookup ta+le of characters
echo -n :)M: | recode latin-31)<..dump Show what a code represents in latin-3 charmap
echo -n :)2:LC | recode ucs-21)2..latin-31) Show latin-3 encoding
echo -n :)2:LC | recode ucs-21)2..utf-M1) Show utf-M encoding
CDs
gDip [ 1dev1cdrom > cdrom.iso.gD Save copy of data cdrom
mkisofs -\ /LG$/ -r dir | gDip > cdrom.iso.gD Create cdrom image from contents of dir
mount -o loop cdrom.iso 1mnt1dir #ount the cdrom image at 1mnt1dir %read only'
cdrecord -v dev,1dev1cdrom +lank,fast Clear a CCJ4
gDip -dc cdrom.iso.gD | cdrecord -v dev,1dev1cdrom -
Gurn cdrom image %use dev,L2L*H -scan+us to confirm
dev'
cdparanoia -G Jip audio tracks from CC to wav files in current dir
cdrecord -v dev,1dev1cdrom -audio -pad 7.wav
#ake audio CC from all wavs in current dir %see also
cdrdao'
oggenc --tracknum,-track- track.cdda.wav -o -track.ogg- #ake ogg file from wav file
disk space %See also ;Slint'
ls -lSr Show files +y siDe( +iggest last
du -s 7 | sort -k<(<rn | head Show top disk users in current dir. See also dutop
du -hs 1home17 | sort -k<(<h Sort paths +y easy to interpret disk usage
df -h Show free space on mounted filesystems
df -i Show free inodes on mounted filesystems
fdisk -l Show disks partitions siDes and types %run as root'
rpm -. -a --.f -^<:XSH`$ZAt^X6L#$ZAn- | sort -k<(<n /ist all packages +y installed siDe %Gytes' on rpm distros

dpkg-.uery -4 -f,-XHnstalled-SiDe=<:ZAtX*ackageZAn- |
sort -k<(<n
/ist all packages +y installed siDe %OGytes' on de+ distros
dd +s,< seek,22G if,1dev1null of,e)tN.test Create a large test file %taking no space'. See also truncate
> file truncate data of file or create an empty file
monitoring/debugging
tail -f 1var1log1messages #onitor messages in a log file
strace -c ls >1dev1null Summarise1profile system calls made +y command
strace -f -e open ls >1dev1null /ist system calls made +y command
strace -f -e trace,write -e write,<(2 ls >1dev1null #onitor what-s written to stdout and stderr
ltrace -f -e getenv ls >1dev1null /ist li+rary calls made +y command
lsof -p /ist paths that process id has open
lsof I /ist processes that have specified path open
tcpdump not port 22 Show network traffic e)cept ssh. See
also tcpdump0not0me
ps -e -o pid(args --forest /ist processes in a hierarchy

ps -e -o pcpu(cpu(nice(state(cputime(args --sort pcpu | sed


-1@ :.: 1d-
/ist processes +y ^ cpu usage
ps -e -orss,(args, | sort -+ -k<(<n | pr -24C"/5#6S /ist processes +y mem %OG' usage. See also ps0mem.py
ps -C firefo)-+in -/ -o pid(tid(pcpu(state /ist all threads for a particular process
ps -p <( -o etime, /ist elapsed wall time for particular process HCs
last re+oot Show system re+oot history
free -m Show amount of %remaining' JL# %-m displays in #G'
watch -n.< -cat 1proc1interrupts- 4atch changea+le data continuously
udevadm monitor #onitor udev events to help configure rules
system information %see also sysinfo' %-V- means root access is re.uired'
uname -a Show kernel version and system architecture
head -n< 1etc1issue Show name and version of distri+ution
cat 1proc1partitions Show all partitions registered on the system
grep #em2otal 1proc1meminfo Show JL# total seen +y the system
grep Wmodel nameW 1proc1cpuinfo Show C*5%s' info
lspci -tv Show *CH info
lsus+ -tv Show 5SG info
mount | column -t /ist mounted filesystems on the system %and align output'
grep -; capacityF 1proc1acpi1+attery1GL2:1info Show state of cells in laptop +attery
Vdmidecode -. | less Cisplay S#GH"S1C#H information
Vsmartctl -L 1dev1sda | grep *ower0"n0!ours !ow long has this disk %system' +een powered on in total
Vhdparm -i 1dev1sda Show info a+out disk sda
Vhdparm -t2 1dev1sda Co a read speed test on disk sda
V+ad+locks -s 1dev1sda 2est for unreada+le +locks on disk sda
interactive %see also linu) key+oard shortcuts'
readline /ine editor used +y +ash( python( +c( gnuplot( ...
screen \irtual terminals with detach capa+ility( ...
mc *owerful file manager that can +rowse rpm( tar( ftp( ssh( ...
gnuplot Hnteractive1scripta+le graphing
links 4e+ +rowser
)dg-open . open a file or url with the registered desktop application
Command Description
grep . 1proc1sys1net1ipv?17 /ist the contents of flag files
set | grep 5S$J Search current environment
tr -A:- -An- [ 1proc11environ Cisplay the startup environment for any process
echo *L2! | tr F -An- Cisplay the *L2! one per line
kill -: && echo process e)ists and can accept signals Check for the e)istence of a process %pid'

find 1etc -reada+le | )args less -O -p-7ntp- -P %%X/H6$SF-


2RZ12''
Search paths and data with full conte)t. 5se n to iterate
Low impact admin
V
apt-get install WpackageW -o Lc.uireFFhttpFFCl-/imit,?2 A
-o Lc.uireFFBueue-mode,access
Jate limit apt-get to ?2OG1s
echo -wget url- | at :<F:: Cownload url at <L# to current dir
Vapache2ctl configtest && apache2ctl graceful Jestart apache if config is "O
nice openssl speed sha< Jun a low priority command %openssl +enchmark'
renice <3 -p = ionice -cN -p
#ake shell %script' low priority. 5se for non interactive
tasks
Interactive monitoring
watch -t -n< uptime Clock with system load
htop -d R Getter top %scrolla+le( tree view( lsof1strace integration( ...'
iotop 4hat-s doing H1"
V
watch -d -nN: Wnice ps0mem.py | tail -n %%X/H6$SF-<2Z-
2''W
4hat-s using JL#
Viftop 4hat-s using the network. See also iptraf
Vmtr www.pi)el+eat.org ping and traceroute com+ined
Useful utilities
pv [ 1dev1Dero > 1dev1null *rogress \iewer for data copying from files and pipes

wkhtml2pdf httpF11...1linu)0commands.html linu)0comma


nds.pdf
#ake a pdf of a we+ page
timeout < sleep N run a command with +ounded time. See also timeout
etworking
python -m Simple!22*Server Serve current directory tree at httpF11!"S26L#$FM:::1

openssl s0client -connect www.google.comF??N [1dev1null


2>&: |
openssl )R:3 -dates -noout
Cisplay the date range for a site-s certs
curl -H www.pi)el+eat.org Cisplay the server headers for a we+ site
Vlsof -i tcpFM: 4hat-s using port M:
Vhttpd -S Cisplay a list of apache virtual hosts
vim scpF11userEremote11path1to1file
$dit remote file using local vim. Good for high latency
links

curl -s httpF11www.pi)el+eat.org1pi)el+eat.asc | gpg


--import
Hmport a gpg key from the we+
tc .disc add dev lo root handle <F: netem delay 2:msec Ldd 2:ms latency to loop+ack device %for testing'
tc .disc del dev lo root Jemove latency added a+ove
otification

echo WCHS*/LK,CHS*/LK )message cookerW | at


W6"4 QN:minW
*opup reminder
notify-send Wsu+PectW WmessageW Cisplay a gnome popup notification

echo Wmail -s -go home- *EdraigGrady.com [ 1dev1nullW |
at <YFN:
$mail reminder
uuencode file name | mail -s su+Pect *EdraigGrady.com Send a file via email

ansi2html.sh | mail -a WContent-2ypeF te)t1htmlW
*EdraigGrady.com
Send1Generate !2#/ email
!etter default settings %useful in your .+ashrc'
Vtail -s.< -f 1var1log1messages Cisplay file additions more responsively
se. <:: | tail -n %%X/H6$SF-<2Z-2'' Cisplay as many lines as possi+le without scrolling
Vtcpdump -s: Capture full network packets
Useful functions/aliases %useful in your .+ashrc'
md %' X mkdir -p W<W && cd W<W= Z Change to a new directory
strerror%' X python -c Wimport os= print os.strerror%<'W= Z Cisplay the meaning of an errno
plot%' X X echo -plot W-W- WEW= cat= Z | gnuplot -persist= Z *lot stdin. %e.gF se. <::: | sed -s1.71s%&'1- | +c -l | plot'

hili%' X e,W<W= shift= grep --col,always -$ih We|W WEW=


Z
highlight occurences of e)pr. %e.gF env | hili 5S$J'
alias hd,-od -L) -t)<D -v- !e)dump. %usage e.g.F hd 1proc1self1cmdline | less'
alias realpath,-readlink -f- CanonicaliDe path. %usage e.g.F realpath I1..15S$J'
"ultimedia
CHS*/LK,F:.: import -window root orig.png 2ake a %remote' screenshot

convert -filter catrom -resiDe -T::)>- orig.png


T::p)0wide.png
Shrink to width( computer gen images or screenshots
mplayer -ao pcm -vo null -vc dummy 1tmp1;lash7 $)tract audio from flash video to audiodump.wav
ffmpeg -i filename.avi Cisplay info a+out multimedia file
ffmpeg -f )<<gra+ -s )ga -r 2R -i F: -same. demo.mpg Capture video of an U display
D#D

for i in %se. 3'= do ffmpeg -i i.avi -target pal-dvd
i.mpg= done
Convert video to the correct encoding and aspect for C\C

dvdauthor -odvd -t -v Wpal(?FN(Y2:)fullW 7.mpg=dvdauthor
-odvd -2
Guild C\C file system. 5se <TF3 for widescreen input
growisofs -dvd-compat -` 1dev1dvd -dvd-video dvd Gurn C\C file system to disc
Unicode

python -c Wimport unicodedata as u= print


u.name%unichr%:)2:2M''W
/ookup a unicode character
uconv -f utfM -t utfM -) nfc 6ormaliDe com+ining characters
printf -AN::A2::- | iconv -futfM -tutfM >1dev1null \alidate 52;-M
printf -a2;MAn- | /L6G,C grep --color,always -8@ -I9AQ- !ighlight non printa+le LSCHH chars in 52;-M
fc-match -s WsansFlang,DhW /ist font match order for language and style
Development

gcc -march,native -$ -v -[1dev1null 2>&<|sed -n -s1.7-


mar1-mar1p-
Show autodetected gcc tuning params. See also gcccpuopt
for i in %se. ?'= do X 8 i , < 9 && Compile and e)ecute C code from stdin
wget httpF11url.ie1Tlko -."-||
.1a.out= Z | tee 1dev1tty | gcc -)c - 2>1dev1null= done
cpp -d# 1dev1null Show all predefined macros

echo WVinclude [features.h>W | cpp -d6 | grep WVdefine


005S$0W
Show all gli+c feature macros
gd+ -tui Ce+ug showing source code conte)t in separate windows
$xtended %ttributes %6ote you may need to %re'mount with WaclW or Wuser0)attrW options'
getfacl . Show LC/s for file
setfacl -m uFno+odyFr . Lllow a specific user to read file
setfacl -) uFno+ody . Celete a specific user-s rights to file
setfacl --default -m groupFusersFrw- dir1 Set umask for a for a specific dir
getcap file Show capa+ilities for a program
setcap cap0net0rawQep your0gtk0prog Lllow gtk program raw access to network
stat -c^C . Show S$/inu) conte)t for file
chcon ... file Set S$/inu) conte)t for file %see also restorecon'
getfattr -m- -d . Show all e)tended attri+utes %includes selinu)(acls(...'
setfattr -n Wuser.fooW -v W+arW . Set ar+itrary user attri+utes
!%&' specific
echo <2N | tee >%tr < a' | tr < + Split data to 2 commands %using process su+stitution'
meld local0file [%ssh host cat remote0file'
Compare a local and remote file %using process
su+stitution'
"ulticore
taskset -c : nproc Jestrict a command to certain processors
find -type f -print: | )args -r: -*%nproc' -n<: mdRsum *rocess files in parallel over availa+le processors
sort -m [%sort data<' [%sort data2' >data.sorted Sort separate data files over 2 processors

Você também pode gostar