Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Beide Seiten der vorigen RevisionVorhergehende ÜberarbeitungNächste Überarbeitung | Vorhergehende Überarbeitung | ||
du [2009/06/16 11:41] – gerald | du [2025/04/05 21:14] (aktuell) – [du (disk usage)] gerald | ||
---|---|---|---|
Zeile 11: | Zeile 11: | ||
</ | </ | ||
zählt alle Verzeichnisse und Dateien (-a) zusammen uns zeigt Ergebnis in MB (-m) | zählt alle Verzeichnisse und Dateien (-a) zusammen uns zeigt Ergebnis in MB (-m) | ||
+ | |||
+ | -h : human readable (or " | ||
+ | |||
+ | -x : berücksichtigt keine gemounteten Unterverzeichnisse | ||
+ | |||
+ | z.B. nummerisch sortiert | ||
+ | |||
+ | < | ||
+ | du -shx | sort -n | ||
+ | </ | ||
+ | |||
+ | Der Größe nach sortieren (Grösste zuerst) | ||
+ | |||
+ | < | ||
+ | du / | ||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | ===== eMail for tracking disc space ===== | ||
+ | |||
+ | A partition filled >=90% for cronscript: | ||
+ | < | ||
+ | # | ||
+ | |||
+ | # loop over each device name culled from df with grep, excluding tmpfs entries | ||
+ | # the device name is stored in $dev | ||
+ | for dev in `df | grep -v tmpfs | egrep -o ^/ | ||
+ | used=`df | grep ^$dev | egrep -o [0-9]\{1, | ||
+ | fs=`df | grep ^$dev | egrep -o / | ||
+ | if [ $used -ge 90 ]; then # if more than 90% of space is used | ||
+ | echo "$dev ($fs) is $used% full." | mail -s "$dev is low on free space." | ||
+ | fi | ||
+ | done | ||
+ | </ | ||
+ | or | ||
+ | < | ||
+ | #!/bin/bash | ||
+ | system=`hostname --fqdn` | ||
+ | for line in `df -aPh | grep " | ||
+ | percent=`echo " | ||
+ | partition=`echo " | ||
+ | |||
+ | limit=90 | ||
+ | |||
+ | if [ $partition == '/ | ||
+ | limit=101 | ||
+ | fi | ||
+ | |||
+ | if [ $percent -ge $limit ]; then | ||
+ | echo "Free Space warning!" | ||
+ | fi | ||
+ | done | ||
+ | </ | ||
+ | |||
+ | Quelle((http:// | ||
+ | |||
+ | ===== Get and display the file size and the directory size using du command ===== | ||
+ | |||
+ | |||
+ | The du command ( disk usage ) gather and summarize about how much your disk space being used by your file and the disk space being use by directory in the Linux system | ||
+ | |||
+ | Using du command to get file size. | ||
+ | |||
+ | | ||
+ | |||
+ | < | ||
+ | [root@fedora ~]# du -h | ||
+ | 4.0K ./ | ||
+ | 108K ./ | ||
+ | 28K ./ | ||
+ | 32K ./ | ||
+ | 6.0M ./ | ||
+ | 12K ./ | ||
+ | 12M . | ||
+ | </ | ||
+ | The output from above command show the size of each file, directory and with the total size used in your system in human readable size ( -h ). | ||
+ | |||
+ | ==== Get the total size of current directory. ==== | ||
+ | |||
+ | The du command can be use to determine the total size of file in current directory. | ||
+ | < | ||
+ | [root@fedora ~]# du -s | ||
+ | 768096 . | ||
+ | [root@fedora ~]# du -sh | ||
+ | 751M . | ||
+ | [root@fedora ~]# | ||
+ | </ | ||
+ | ==== To get the size of file and directory in current directory. ==== | ||
+ | < | ||
+ | [root@fedora ~]# du -sh * | ||
+ | 14M 20060524-033-x86.exe | ||
+ | 85M labu-punyer | ||
+ | 8.0K libjmti.odt | ||
+ | 4.0K linux-feeds.txt | ||
+ | 4.0K mambo_conf.txt | ||
+ | 8.0K yumex-0-1.0.1-1.0.fc5.html | ||
+ | 408K yumex-1.0.1-1.0.fc5.noarch.rpm | ||
+ | 8.0K yum install | ||
+ | 11M zope-2.8.5-1.fc5.i386.rpm | ||
+ | [root@fedora ~]# | ||
+ | </ | ||
+ | ==== Display the size of specific file extension. ==== | ||
+ | |||
+ | The example below show du command execute with -c option to get the size of each file that have filename ending with .txt and then display grand total of all files in human readable format. | ||
+ | < | ||
+ | [root@fedora ~]# du -ch *.txt | ||
+ | 4.0K create.drupal-2.txt | ||
+ | 4.0K create.drupal.db.txt | ||
+ | 4.0K drupal-pass.txt | ||
+ | 4.0K joomla-bazz.txt | ||
+ | 4.0K linux-feeds.txt | ||
+ | 4.0K mambo_conf.txt | ||
+ | 8.0K msql-bazz.txt | ||
+ | 4.0K setup_mysql_mambo.txt | ||
+ | 4.0K simple.txt | ||
+ | 40K total | ||
+ | [root@fedora ~]# | ||
+ | </ | ||
+ | ==== Check the size of home directory. ==== | ||
+ | |||
+ | The example below show the use of du command to get the disk usage of each user home directory on the system. | ||
+ | < | ||
+ | [root@fedora home]# | ||
+ | /home | ||
+ | [root@fedora home]# | ||
+ | 492K bazz | ||
+ | 48K botol | ||
+ | 44K hamirul | ||
+ | 22M kambing | ||
+ | 48K kayu | ||
+ | 56K labu | ||
+ | 80K sysuser | ||
+ | 40K william | ||
+ | 40K ycluckers | ||
+ | [root@fedora home]# | ||
+ | </ | ||
+ | ==== To produce grand total of the /home directory size. ==== | ||
+ | |||
+ | < | ||
+ | /home | ||
+ | [root@fedora home]# | ||
+ | 492K bazz | ||
+ | 48K botol | ||
+ | 44K hamirul | ||
+ | 22M kambing | ||
+ | 48K kayu | ||
+ | 56K labu | ||
+ | 80K sysuser | ||
+ | 40K william | ||
+ | 40K ycluckers | ||
+ | 23M total | ||
+ | [root@fedora home]# | ||
+ | </ | ||
+ | ==== The following are some of the flags and arguments that can be used ==== | ||
+ | |||
+ | * '' | ||
+ | * --apparent-size | ||
+ | * -B, --block-size=SIZE | ||
+ | * -b, --bytes | ||
+ | * -c, --total | ||
+ | * -D, --dereference-args | ||
+ | * -H like --si, but also evokes a warning; will soon change to be equivalent to --dereference-args (-D) | ||
+ | * -h, --human-readable | ||
+ | * --si like -h, but use powers of 1000 not 1024 | ||
+ | * -k like --block-size=1K | ||
+ | * -l, --count-links count sizes many times if hard linked | ||
+ | * -L, --dereference dereference all symbolic links | ||
+ | * -P, --no-dereference don't follow any symbolic links (this is the default) | ||
+ | * -0, --null end each output line with 0 byte rather than newline | ||
+ | * -S, --separate-dirs do not include size of subdirectories | ||
+ | * -s, --summarize display only a total for each argument | ||
+ | * -x, --one-file-system skip directories on different filesystems | ||
+ | * -X FILE, --exclude-from=FILE Exclude files that match any pattern in FILE | ||
+ | * --exclude=PATTERN Exclude files that match PATTERN | ||
+ | * --max-depth=N print the total for a directory (or file, with --all) only if it is N or fewer levels below the command line argument; --max-depth=0 is the same as --summarize | ||
+ | * --help display this help and exit | ||
+ | |||
+ | | ||
+ | |||
+ | {{tag>" |