Vous êtes sur la page 1sur 1

GNU/Linux most wanted

Summary of most useful commands


Copyright 2014-2005, Free Electrons
Free to share under the terms of the Creati!e Commons
"ttri#ution-Share"li$e %0 license
&http'((creati!ecommonsorg)
Sources'
http'((gitfree-electronscom(training-materials
*pdates'
http'((free-electronscom(doc(training(em#edded-linu+
,ranslations, command and concepts details'
http'((free-electronscom(training(intro-uni+-linu+
,han$s to .ichel /lanc, 0ermann 1 /ec$ers and ,hierry
2rellier
3atest update' Sep 14, 2014
Handling fles and directories
Create a directory'
mkdir dir
Create nested directories'
mkdir -p dir1/dir2
Changing directories'
cd newdir
cd .. &parent directory)
cd - &pre!ious directory)
cd &home directory)
cd 5bill &home directory of user bill)
6rint the 7or$ing &current) directory'
p7d
Copy a 8le to another'
cp source_file dest_file
Copy 8les to a directory'
cp file1 file2 dir
Copy directories recursi!ely'
cp -r source_dir dest_dir
rsync -a source_dir/ dest_dir/
Create a sym#olic lin$'
ln -s linked_file link
9ename a 8le, lin$ or directory'
mv source_file dest_file
9emo!e 8les or lin$s'
rm file1 file2
9emo!e empty directories'
rmdir dir
9emo!e non-empty directories'
rm -rf dir
Listing fles
3ist all :regular; 8les &not starting 7ith .) in
the current directory'
ls
<isplay a long listing'
ls -l
3ist all the 8les in the current directory,
including :hidden; ones &starting 7ith .)'
ls -a
3ist #y time &most recent 8les 8rst)'
ls -t
3ist #y si=e &#iggest 8les 8rst)
ls -S
3ist 7ith a re!erse sort order'
ls -r
3ong list 7ith most recent 8les last'
ls -ltr
Displaying fle contents
Concatenate and display 8le contents'
cat file1 file2
<isplay the contents of se!eral 8les &stopping
at each page)'
more file1 file2
less file1 file2 &#etter' e+tra features)
<isplay the 8rst 10 lines of a 8le'
head -10 file
<isplay the last 10 lines of a 8le'
tail -10 file
File name pattern matching
Concatenate all :regular; 8les'
cat *
Concatenate all :hidden; 8les'
cat .*
Concatenate all 8les ending 7ith .lo'
cat *.lo
3ist :regular; 8les 7ith bu in their name'
ls *bu*
3ist all :regular; 8les ending 7ith . and a
single character'
ls *.!
Handling fle contents
Sho7 only the lines in a 8le containing a gi!en
su#string'
rep substrin file
Case insensiti!e search'
rep -i substrin file
Sho7ing all the lines #ut the ones containing a
su#string'
rep -v substrin file
Search through all the 8les in a directory'
rep -r substrin dir
Sort lines in a gi!en 8le'
sort file
Sort lines, only display duplicate ones once'
sort -u file &uni>ue)
Changing fle access rights
"dd 7rite permissions to the current user'
chmod u"w file
"dd read permissions to users in the 8le group'
chmod "r file
"dd e+ecute permissions to other users'
chmod o"# file
"dd read ? 7rite permissions to all users'
chmod a"rw file
.a$e e+ecuta#le 8les e+ecuta#le #y all'
chmod a"r$ *
.a$e the 7hole directory and its contents
accessi#le #y all users'
chmod -% a"r$ dir &recursi!e)
Comparing fles and directories
Comparing 2 8les'
diff file1 file2
Comparing 2 8les &graphical)'
vimdiff file1 file2
tkdiff file1 file2
meld file1 file2
Comparing 2 directories'
diff -r dir1 dir2
Looking or fles
Find all 8les in the current &.) directory and its
su#directories 7ith lo in their name'
find . -name &*lo*'
Find all the .pdf 8les in dir and su#directories
and run a command on each'
find . -name &*.pdf' -e#ec #pdf () *+*
@uic$ system-7ide 8le search #y pattern
&caution' inde+ #ased, misses ne7 8les)'
locate &*pub*'
!edirecting command output
9edirect command output to a 8le'
ls *.pn , imae_files
"ppend command output to an e+isting 8le'
ls *.-p ,, imae_files
9edirect command output to the input of
another command'
cat *.lo . rep error
"o# control
Sho7 all running processes'
ps -ef
3i!e hit-parade of processes &press /, 0, 1' sort
#y 6rocessor, .emory or ,ime usage)'
top
Send a termination signal to a process'
kill 2pid, &num#er found in ps output)
0a!e the $ernel $ill a process'
kill -3 2pid,
Aill all processes &at least all user ones)'
kill -3 -1
Aill a graphical application'
#kill &clic$ on the program 7indo7 to $ill)
File and partition si$es
Sho7 the total si=e on dis$ of 8les or
directories &dis$ usage)'
du -sh dir1 dir2 file1 file2
Bum#er of #ytes, 7ords and lines in 8le'
wc file &word count)
Sho7 the si=e, total space and free space of the
current partition'
df -h .
<isplay these info for all partitions'
df -h
Compressing
Compress a 8le'
4ip file &.4 format)
b4ip2 file &.b42 format, #etter)
l4ma file &.l4ma format, #est compression)
#4 file &.#4 format, #est for code)
*ncompress a 8le'
un4ip file.4
bun4ip2 file.b42
unl4ma file.l4ma
un#4 file.#4
%rchi&ing
Create a compressed archi!e &tape archi!e)'
tar 4cvf archive.tar.4 dir
tar -cvf archive.tar.b42 dir
tar 5cvf archive.tar.#4 dir
tar --l4ma -cvf archive.tar.l4ma
Test &list) a compressed archi!e'
tar tvf archive.tar.64.b42.l4ma.#47
Extract the contents of a compressed archi!e'
tar #vf archive.tar.64.b42.l4ma.#47
tar options'
c' create
t' test
#' extract
-' on the Cy b4ip2 &un)compression
5' on the Cy #4 &un)compression
4' on the Cy 4ip &un)compression
0andling =ip archi!es
4ip -r archive.4ip 2files, &create)
un4ip -t archive.4ip &test ( list)
un4ip archive.4ip &e+tract)
'rinting
Send 6ostScript or te+t 8les to 8ueue'
lpr -/8ueue f1.ps f2.t#t &local printer)
3ist all the print Do#s in 8ueue'
lp8 -/8ueue
Cancel a print Do# num#er in 8ueue'
cancel 129 8ueue
6rint a 6<F 8le'
pdf2ps doc.pdf
lpr doc.ps
Eie7 a 6ostScript 8le'
ps2pdf doc.ps
#pdf doc.pdf
User management
3ist users logged on the system'
who
Sho7 7hich user F am logged as'
whoami
Sho7 7hich groups user #elongs to'
roups user
,ell more information a#out user'
finer user
S7itch to user hul$'
su - hulk
S7itch to super user &root)'
su - &s7itch user)
su &$eep same directory and en!ironment)
(ime management
Gait for H0 seconds'
sleep :0
Sho7 the current date'
date
Count the time ta$en #y a command'
time find_charmin_prince -cute -rich
Command help
/asic help &7or$s for most commands)'
rep --help
"ccess the full manual page of a command'
man rep
)isc commands
/asic command-line calculator
bc -l
*asic system administration
Change the o7ner and group of a directory and
all its contents'
sudo chown -% newuser.newroup dir
9e#oot the machine in 5 minutes'
sudo shutdown -r ";
Shutdo7n the machine no7'
sudo shutdown -h now
<isplay all a!aila#le net7or$ interfaces'
ifconfi -a
"ssign an F6 address to a net7or$ interface'
sudo ifconfi eth0 20<.=:.190.10>
/ring do7n a net7or$ interface'
sudo ifconfi eth0 down
<e8ne a default gate7ay for pac$ets to
machines outside the local net7or$'
sudo route add default w 132.1:>.0.1
<elete the default route'
sudo route del default
,est net7or$ing 7ith another machine'
pin 20<.=:.190.10>
Create or remo!e partitions on the 8rst F<E
hard dis$'
fdisk /dev/hda1
Create &format) an e+t% 8lesystem'
mkfs.e#t9 /dev/hda1
Create &format) a F",%2 8lesystem'
mkfs.vfat -v -? 92 /dev/hda2
.ount a formatted partition'
mkdir /mnt/usbdisk &Dust do it once)
sudo mount /dev/uba1 /mnt/usbdisk
.ount a 8lesystem image &loop de!ice)'
sudo mount -o loop fs.im /mnt/fs
*nmount a 8lesystem'
sudo umount /mnt/usbdisk
Chec$ the system $ernel !ersion'
uname -a

Vous aimerez peut-être aussi