(5 réponses)
Fermé il y a 4 ans.
[[email protected] ~]# df -h /appl/was  | grep [0-9]%  | awk '{ print $4 }' # => 53%
[[email protected] ~]# df -h /  | grep [0-9]%  | awk '{ print $4 }' # -> 108G
 Cela se produit car en cas de nom de périphérique long, la sortie est imprimée sur deux lignes
 [[email protected] ~]# df -h /appl/was 
 Filesystem Size Used Avail Use% Mounted on
 /dev/mapper/appsvg-lvwasapp
 6.9G 3.4G 3.1G 53% /appl/was
 [[email protected] ~]# df -h / 
 Filesystem Size Used Avail Use% Mounted on
 /dev/sda2 122G 8.1G 108G 7% /
Comment puis-je éviter cela ?
La version de core-utils est coreutils-8.4-46.el6.x86_64.
Réponse acceptée :
 Utilisez --output option de df commande pour afficher uniquement le "pourcentage nécessaire ” champ :
df / --output=pcent | tail -n 1
 La sortie :
 7%
 --output[=FIELD_LIST] use the output format defined by FIELD_LIST
 Alternative df + awk le pipeline ressemblerait à :
df / | awk 'END{ print $(NF-1) }'
7%