Aide-m ém oire des com m andes Unix de A à L

Transcription

Aide-m ém oire des com m andes Unix de A à L
bg 1
Ce document regroupe les principales commandes
susceptibles d’être employées par les stagiaires de la
formation « Programmation Shell et Langages de
Scripts », en rappelant leurs options les plus utilisées.
Pour avoir plus de détail sur une commande
particulière, on consultera le manuel Unix (commande
man).
%
- 2
$ 3!
$ application
(Ctrl-Z)
[1]+ Stopped
application
$ bg
[1]+ application &
$
bunzip2 4!
.bz2
bzip2
al
cal 5 2003
-n
!
"
-v
! #
0 $ &
cat entete.txt corps.txt signature.txt
mail.txt
cat
propos
apropos shell
arch
at, atq, atrm
!
" #
$ %
#!
!
-f
&!
$ at now + 10 minutes < script.sh
$ at 20:55 -f demarre_magnetoscope.sh
awk '
!
()
NF
$
FS !
NR
!
*
+
$1, $2...$NF
ls -l | awk '{somme+= $5} END{print
somme}'
!
asename ,
-
!.
$ basename /usr/src/linux/signal.c
signal.c
$ basename /usr/src/linux/signal.c .c
signal
$
bash
/
batch
$
!! .
0batch << FIN
tri_des_enregistrements
FIN
bc
!
$
-l $$
-&
! &
$ pi=$(echo "a(1)*4" | bc -l)
$ echo $pi
3.14159265358979323844
$
#
cc
cd
!
.
cd /usr/src/linux
cd –
.
!
!!
cd
.
!
chgrp
!
-R
!
.
2!
chgrp equipe_2 fichier
chmod
-R
!
.
2!
chmod 644 texte
"!
!
chmod 755 script
#!
"!
!
chmod u+s executable
.
$
25'4
chown
!
-R
!
.
2!
chown user1.equipe1 fichier
chsh
!%
#
-l
$ "
-s
#
&!
chsh -s /bin/ksh
cksum 6 $
7
clear
!
cmp
#
-l
&
! "
-s 8
"
. .
#
if cmp –s fichier1 fichier2; then ...
col ,
2 2
-b -.
man col | col -b > col.man.txt
compress
cp
-R
!
.
2!
"
-p
"
! "
"
-d
0 $ &
&
cp fichier fichier.sauve
cp -Rdp fichier_* /autre/repertoire
crontab ,
crontab
-l
"
-e !
crontab"
-r
crontab
csh
csplit 4!
.
#
-f ! #
. #
csplit -f prefixe fichier '/^$/' {*}
! prefixe00 prefixe01
!
&
.
cut
&
-b
& !"
-f
& !"
-d
- !
ls -l | cut -b 20-28
&
% 9"
2%2
ate
0-d
&
%
+
:
date +"Date = %D, Heure = %X"
date -d 20030401 +"%A"
;
;*< .
=+
dd
!! &
.
if=
!"
of=
"
bs=
$
%
"
count=
$
#
$
%
"
skip=
!$
"
seek=
!$ !
dd if=/dev/fd0 of=disquette.img bs=1024
count=1440
df >
!
0-k
) 2
"
-P
23
df –k /tmp/sauvegarde
%
diff ?
.
!
-i
!
@
"
-b
!
8
$
"
-u
$ . patch"
-r !
!
.
2!
diff -u original copie > modifs.patch
dirname
!
$ dirname /usr/src/linux/signal.c
/usr/src/linux
$
dos2unix
.
#
4 . 5 #
&
&
du
-a
&
"
-s
"
-x
2!
0"
-k
) 2
cho
-
-
#
0 $ &
"
2 2
"Message d'avertissement" >&2
-n "Votre choix :"
-e "\r effectué : " $i "%"
–e "\007"
2%2
egrep 0 0
grep -E
emacs ,
/
A
B2C
( Dxemacs
env
.
.
!
-i 4!
.
.
env
.
env -i /bin/sh
!
.
expand
.
$
-t
$
! !"
-i
&
$
!$
expand –i < script.sh > listing.txt
export >
. $
8 .
export REP_APPLI=/usr/local/lib/appli/
VERSION_APPLI=1.5
export VERSION_APPLI
expr ,.
#
expr 4 "*" 3 + 2 affiche 14
*
!
+
-e
-n !.
echo
echo
echo
echo
ed ,
alse ,
until false; do ...
fc ,
8
& . 8!
. $ 8 .
FCEDIT
fg 1 $% 8. 2
fgrep 0 0
grep -F
file
0 8
find 1
$
-name motif
"
-regex expr
"
-atime n
- 0
"
-ctime n
!
"
-mtime n
"
-perm mode
"
-size n
* $ +"
-type t 0
"
-print
.! "
-exec ...\{\} \; #!
&!
\{\}
"
-ok ...\{\}\; exec .
find /tmp -ctime +30 -ok rm \{\} \;
find /home -name core -exec rm \{\} \;
fold
8
%
!
ftp ?
fuser '
-k
.
'/F' "
-i
.
.0
"
-m
!
0fuser -k /mnt/cdrom
rep
%
-E
#
!
-F
:
#
"
-i
!
@
"
-v
"
-l
grep -i "MoTiF" fichiers_*
grep -v "absent" fichier
groups
8
gunzip 4!
.gz
gzip
ead
!$
"
-c n
-n n
hostid
hostname
iconv
.
"
!
d
5'4
/'4
!
-u
5'4"
-g
/'4"
-r
!
if [ $(id -u) == 0 ]; then...
obs
join G
$
#
!
join fichier_1 fichier_2 > fichier_3
E
ill .
%
-numéro
-l
kill -9 30582
killall .
-i
-l
killall xterm
ksh
F
ess
*
lex /! !
ln !
. $
8
0
!
#
& !"
$
#
.
#
3
"
$
2 2
% more +
#
-f
!
# "
-s !
0 $ &
ln -sf appli-1.4.sh appli
logger H
0#
0login 1
logname 6
#
lp 1 & 3 8
-d !
8
-n
$
pr -l 66 appli.c | lp -d listing
ls
8!
!
-a
E
"
-d
!
"
"
-i
!
2 I "
-l
"
-R
!
.
2!
ls -al /home/usera
ls -lR /var/ftp/pub > /var/ftp/listefichiers.txt
8
#
8
- .
iconv –f LATIN1 –t UTF8 < fichier
@@((( $
@
nohup
#
!!
#
$ nohup ~/bin/calcul &
[1] 17300
$ exit
Ce document regroupe les principales commandes
susceptibles d’être employées par les stagiaires de la
formation « Programmation Shell et Langages de
Scripts », en rappelant leurs options les plus utilisées.
Pour avoir plus de détail sur une commande
particulière, on consultera le manuel Unix (commande
man)
ake
man
!
numéro
-a
-t
%
-k $
&
!!
man 1 c
man -k socket
" #
$
apropos
md5sum
mkdir
!
'
( )*
-p
!
-m mode #
+ ,
mkdir -p /var/lib/new-app/font/big
mkfifo
-.-/ 0 1
!! 2
-m mode #
+ ,
mkfifo -m 666 /tmp/fifo_serveur
mknod
#
b
c
1
,
mknod /dev/hda1 b 3 1
!
! 3 4!
546
more
0 less2
mv )
!!
-f
+
!
for i in *.JPG; do mv $i ${i%JPG}jpg;
done
!!
7%8
3
ice
#
!
-n valeur
nl 9 !
-f a !
!!
!
!
+
d
!
-c
-x
asswd
1
!
#
+
! 1
! #
+
$
= ,!
+
renice +20 14210
+
0
#
= ,!
0
ssh2
rev .
rlogin
!!
!
= ,!
ssh2
cript
!
$
rmdir
rsh #
0
$ passwd
# passwd utilisateur
patch
$
!
&
-pn
,
1
!
$ patch –p1 ../new_version/patch_1
pathchk :
+
!
-p
1
if pathchk "$rep/$fic" ; then...
perl .
%
-w !
ping ;
!
-c !1
-w
! #!
pr %
#
+!
-h texte
$ +'<
$
-l n
-t
!
'<
printf
! $
!
printf "%05d %4.2f" $x $y
ps
+
-ax
0 )2
-u
!
! , 0 )2
-e
0 = :2
-f
!
! , 0 = :2
-w
ps -aux
(BSD)
ps -ef
(SysV)
pwd
!
uota
cp
>
renice (
rm
-f
!
-i
!
$
-r
!
'
rm -rf /home/usera/tmp
+
,
#
tac2
'a fic 3
sed ?
'
-e "..." !!
-f fic !!
-n
! +
!!
@
p
d
n
&
s
!
!
sed -ne '1,/^$/p' < mail.txt
#
+'< + !
sh
sleep
!
sleep 14
06
2
sleep 3m
05!
2
sort ;
+
#
-b
1
1
-f
! 3
4!
-r
split )
-l n
-b n
split -b 1440k gros_fichier disquette_
ssh
#
= ,!
ssh user@hostname
ssh –l user hostname /usr/bin/commande
strings
>
stty
!
-a
sane
!
-echo
+
,
-icanon min 0 time 1
, &
su #
".)
8.)
- #
sum
ac
tail
!!
A
!1
,
1
&+
tee
-a 3
!
...| tee hublot_1.log | ...
telnet
#
= ,!
0
ssh2
test ;= +
!
= =!
!!
[...]
if test –f $fichier ; then
time
!
!!
!
touch (
+
+
-t MMJJhhmm
$
-r fichier
+
tr ;
!
,
tr ‘àâäçéèêïîôöùû’ ‘aaaceeeiioouu’|...
true C
&
while true; do ...
tty
!
!
+
!
= ,!
-m =
!
-n
! +A
-r
= ,!
-s = ,! +#
-a
!
uncompress ) !
unexpand
0
expand2
$
-u +
-d +
-c
+
-num
!1
$
-f
!
tail -f /var/log/messages
tar "
+
-f fic
!
+
-c
-t
+
-x #
+
-z
$ 8
B
0 2 !
-j
$ 1B
0 2 !
-v !
1
tar -czf save.tar.gz /home/usera/*
tar -xzf appli-1.10.tgz
tcl .
; 0
wish2
name
uniq D
$
$
$
$
!1
+
unix2dos
unzip ) !
uptime ; !
users 9 !
uudecode )
uuencode
i?
:
E'F
#
! " #
! )
.zip
!
= ,!
.uu
1
alpha
,
digit
xdigit
alnum
,
lower !
upper ! 3
blank
,
space
,
punct
graph =!1
print =!1
cntrl
,
+
$ ./commande &
[1] 2927
./commande
$ wait 2927
[1]+ Done
./commande
$
wc 9 !1
, !
+
whereis C
#
1
!
+
!!
which
!
+ ,
!!
who (
$
whoami
".)
wish .
;
11
,$ ;H
#
!!
find . -name "*.c" | xargs grep "init()"
=
= #$
>
0
Iy 2
yes | rm -r /var/old-backup/
cat
zip !
!
1
Expressions rationnelles
!
,
1 $
! #
#
! #
! $
1
1
1
1
A
!
|
Y|y
+
!
?
! B
[+-]?[[:digit:]]+
{ }
!
!1
( )
!
\|
\+
\?
\{ \}
\( \)
Éléments communs
\
!
prix=25\$
>
>
Équivalences pour les expressions rationnelles
simples
grep sed find –regex
#
grep –e awk perl
#
.Z
,
Éléments des expressions rationnelles étendues
args
!
$
Classes de caractères
G @ gvim
ait
acc 8
yes
. !
!
g.n.rique
J
1
K
^$
0
2
*
$ B
[ ]
[eéêèë]
[0-9]
[[:upper:]]
,!
\i
|
+
?
#
#
#
#{}
#()
#
#
44GGG 1
,
#
4
Partitions et systèmes de fichiers
Distribution / installation de logiciel
fdisk
tar
5
! &!
fdisk /dev/hda
mkswap
Ce document rappelle les commandes et les
options les plus utilisées par l’administrateur d’un
système Linux. Il s’agit surtout de commandes
assez générales, dont tout administrateur aura
besoin un jour ou l’autre. Les commandes pour
l’utilisateur courant se trouvent dans un autre
aide-mémoire. Pour
plus d’informations, on
consultera les pages de manuel ou les
publications du Linux Documentation Project
(http://www.tldp.org/)
swapon
"
#
( )
$
%
&
'
#
! )
!+ !
() !
!
! )
-
.
-
.!
#
! &&!
0
.
/
/
1
2 !
!2 !
!2 !
)
3
% 3
#
/ 3
Utilisateurs
4
+
!
+
6
0
7
7
+
/etc/fstab
6
userdel
+
userdel –r linus
!
!
"
passwd linus
!
!
)
+
7
swapoff /dev/hda2
mkfs
)
+
mkfs.ext2 /dev/hda3
mkfs.ext3 /dev/hda4
mkfs.vfat /dev/hda5
.)
+
!
%3 % 3 %93
()
rpm – >
30 3
*
3
@AA 3
&
# +
-a )
!
umount /dev/hda4
umount /mnt/dos
umount –a
df
0
tar –xzf application-1.01.tar.gz
cd application-1.01
./configure
make && make install
mount –t vfat /dev/hda4 /mnt/dos/
:
73
mount –a
!
/etc/fstab3
mount 192.1.1.254:/home /home/users/
"
# + )
;<
*
0 –o
/etc/fstab
default 73
3 03 % 3
3
3
3
remount
# !
&
+
)3
rw !
)
3
ro !
!3
noauto
/
0 2 3
nodev
!
) %3
noexec
%) &! 3
nosuid = #
! &
2, (8> (3
sync )
3
user
1
)
!
umount
+
installation classique
?
useradd –m –p "" linus
)
3 0 )
0
passwd
7
mount
!
useradd
6
fsck.ext2 –p /dev/hda3
)
/ +
% 8 %93
fsck.vfat /dev/hda4
0)
+
:
7
uname
0
1
3
5
6
0
swapoff – ()
Informations système
dmesg
uptime
free *
vmstat
ipcs ,
ipcrm
ldconfig
init
+
swapon /dev/hda2
-a
0
! 6
fsck
-a
)
mkswap /dev/hda2
mkswap /boot/swap_file
>
-c
)
+
03
-x %
+
03
-t
!
+
03
-f
03
-v
0 !&!3
-z $ )'
0 #$ '6 3
-j $ )'
0 &$ '6
tar –czf archive.tar.gz distrib/
)
0
)
)
distrib/3
tar –tvf archive.tar
! !
!+
03
tar –xjf archive.tar.bz2
%
!
+
0
)
/etc/mtab
)
/
# B C
-h
#
!
#
0 !
rpm –ivh paquet.rpm
!!
+
/ #3
rpm –Uvh paquet.rpm
D4 8
!!
+
/ #3
rpm –Fvh paquet.rpm
D4
+
/ # )4D
!!)3
rpm –e paquet
)
!!
+
/ #3
rpm –qa
!
!
/ #
!!
)3
rpm –qf /chemin/fichier
/ # / !
!
rpm –qip paquet.rpm
/ #3
rpm –qlp paquet.rpm
!
! / #
apt
>
/
3
# (&
apt-get install application
!!
!+ !
)0
apt-get remove application
!
)
)0
apt-get update
D4
!&
)
3
apt-get upgrade
D4
!! 3
!! 3
netstat
Gestion des processus
application &
!
!+ !
D!+
2 ! 3
fg 1
D!+0 2 ! ! 4&
) E3
(Ctrl-Z)
!+ !
D!+0 2 ! 3
bg
!
D!+
2 !
4&
ps
arp
5
top
!
F
renice
# !
0
?
E GHI
H
)3
%
&!
!
fuser
)
D
/)
#
>
)
+)
0
!
B-3
!
+K
/)
+
lsmod
modinfo
insmod
K
3
4
%
)
!!
) +
)
! &!
)
3
#
add -net 192.1.1.0 eth0
/ 0 !+
eth03
add -net 172.1.1.0 gw 192.1.1.5
)
&!
!!3
add default eth1
) 3
del default
!
)
J
0
open
cd 8
lcd 8
get
put
prompt
mget L
mput L
wget
B
0
8
modprobe
3
3
#)
!
+
!
!
+
!)
#)
.)
)
#
#)
!
)
modprobe module.o
'
!!
#
+
3
depmod –an
8
8! !8
!
!
rmmod
depmod
? -8 +
)
#
0
)
rmmod module
K
)
%
3
insmod module.o
K
traceroute www.destination.com
-n
)
!
)/
tcpdump
+
Gestion des modules du noyau
!!
ifconfig -a
!
#
!
ifconfig eth0 192.1.1.50
# !
socklist
! &! B-
rsh
%)
ssh
%)
ftp ?
Utilitaires réseau
route
4
route
4
route
4
route
>
telnet mail.isp.com pop-3
%
EE $
'
0
fuser –k –m /dev/hda5
!
)
D!
route
J
telnet
1
killall –9 boucle_fork
ifconfig
3
tcpdump –i eth0
/
!
eth03
tcpdump –i eth0 port telnet
!
#
80 !
9$
!
# !D
kill –15 12857
-l $!
!' !
#
killall
)
–a
traceroute
+
renice +5 12857
#
!
renice –5 –u root
H!
0
# !0)
! )
1 $SIGHUP'
% 3
2 $SIGINT3
!2 '
)
3 $SIGQUIT3
!2M'
)
9 $SIGKILL'
&!#
15 $SIGTERM'
!
3
ping –c 1 –w 2 192.1.1.53
! /1
!
ping –b 192.1.1.255
/1
)
&
D
!
#
-d )!
Signaux fréquemment utilisés
#
ping
ps –aux
# ! #
)
–r
&!
–i
-a
!
arp –d hote
!
)
ps –ef
kill
/
netstat
!
netstat
!+)
netstat
!+)
,B
wget http://www.site.com/repertoire/
-c
)4D
)3
-r
# )
0
! ! 3
-l niveau
% ! )
3
-k
0
! !
! %
Compilation d’un noyau Linux
ftp ftp.kernel.org
) ) !
) )$
%
)
/pub/linux/kernel/3
tar –xjf linux-XXXX.tar.bz2
cd linux-XXXX
make mrproper
make menuconfig
0 !
#
) )3
make dep clean bzImage $
≤
'
!
'
make $
≥ A'
- 3
make modules && make modules_install
cp System.map /boot/System.map-XXXX
cd arch/i386/boot/
cp bzImage /boot/vmlinuz-XXXX
vi /etc/lilo.conf
4
!+ )
!
0
3
/sbin/lilo
/sbin/init 6
!
88777 &!
#8
Protection des caractères spéciaux
Fonctions
"$var1 $var2"
(
Ce document d’accompagnement du stage
« Programmation Shell et Langages de Scripts »
rappelle les points principaux à retenir
concernant la programmation pour shells Bourne
et Korn.
#
'$var1 $var2'
(
\$var
'
'
*
*
$ &
"
"
"
"
)
"
fonction_1 ()
{
commandes…
}
!
fonction_1 valeur_1 valeur_2...
.
$1# $2/
"%
$#!
local variable
%
return valeur
"
0
%
+#
""
+!
Structures de contrôle
Évaluation des expressions
Boucles
variable=valeur
tableau[rang]=valeur
!
${variable}
"
${tableau[rang]}
"
${variable-valeur}
"
${variable=valeur}
#
#
#
#
${variable?valeur}
!
${#variable}
"
#
${variable#motif}
"
$
#
${variable%motif}
"
$
#
${variable##motif} ${variable%%motif}
$
$
% !
~utilisateur/
"
#
ab{c,d,e}fg
abcfg abdfg abefg
$(commande)
"
#
$((expression))
"
" &
'
!
while cmd_1 ; do
commandes
done
, '
&
until cmd_1 ; do
commandes
done
, '
&
for variable in liste ; do
commandes
done
, '
"
"
!
break
"
%
for# while
continue
%
!
*
* +!
"
&
(
'
*"1"
+#
?
"
\*
&
' #
\?
\\
' *# ?# \#
[liste]
' l# i# s# t# e
[b-e]
' b# c# d# e
[^liste]
2 "
&
'
$!
until!
Redirections
commande < fichier
if cmd_1 ; then
cmd_2
elif cmd_3 ; then
cmd_4
else
cmd_5
fi
$
!
# $
#
$
!
case expression in
motif_1 ) cmd_1 ;;
motif_2 | motif_3 ) cmd_2 ;;
* ) cmd_3 ;;
esac
# $
# $
!
!
Motifs du shell
Tests
$
"
#
#
#
commande > fichier
#
commande >> fichier
3
commande 2> fichier
#
commande 2>> fichier
3
commande 2>&1
& commande <<- ETIQUETTE
lignes à envoyer
vers l’entrée standard
de la commande
ETIQUETTE
"
0
#
#
#
!
test
Exécution des commandes
Ligne shebang
#! /bin/sh
%
!
Liste de pipelines
; pipeline
&
+
& pipeline
' +
&& pipeline
+
|| pipeline
+
Commandes composées
{ liste de pipelines }
*
"
""
+
( liste de pipelines )
* 4
+
Commandes internes essentielles
echo
echo arguments
"
-n
"
-e
'
&
!
!
read
"
&
% IFS+!
!
$
#
!
exec
exec commande
"
*
+
exec redirections
&
!
&
!
source
source script
. script
'
export variable
7
'
"
$
"
set
%
set options
"'
-a $
-u
%
-v
-x
0
!
"
#
5
%
""
"
$
$
unset
unset variable
!
getopts
while getopts "ab:c" variable ; do
case $variable in
a) echo "opt° –a";;
b) echo "opt° –b, arg. $OPTARG";;
c) echo "opt° –c";;
*) echo "opt° invalide"; exit 1;;
esac
done
shift $((OPTIND – 1))
echo "arguments restants :"
echo "$@"
exit 0
0
""
!
"
*?:
'
+#
"
OPTARG! >
#
"
"
"
OPTIND!
shift
shift n
"
#
cd –
cd
&
set
$0
!
cd repertoire
!
"
!
env
cd
exit
exit valeur
"
*
+
!
"
" & 5
-eq /
-/
-ne /
/
-lt *-le+/
*
+-/
-gt *-ge+/
*
+-/
7
( 5
-n
-z
!
"
( 5
8# 8# 9# :
7
5
-a $
#
-b
& "
% #
-c
&
' #
-d
#
-f
" #
-g %
4;<6
#
-G
#
-h
0"% & #
-k %
=0
#
-N "
'
#
-O
#
-p % "" * +#
-r
1
#
-s
4
#
-S
= #
-u %
4><6
#
-w
1
#
-x
1 $
!
"
5
-ef / "1"
0 & & /#
-nt / "
"" & / #
-ot / "
" & /
7
5
-t
"
commande | commande | commande
3
read variables…
"
*
5
6
'
% )
% REPLY! ,
!
export
,
Pipeline
pipeline
*$
pipeline
*$
pipeline
*$
pipeline
*$
pwd
test condition
[ condition ]
# $n+1
""
$1# $n+2
5
$2#
#
$
!
@@AAA!%
!
@

Documents pareils