Kuinka löytää tiedostojen ja hakemistojen levykäyttö Linuxissa


Linuxin 'du' (Levyn käyttö) on tavallinen Unix/Linux-komento, jota käytetään koneen tiedostojen ja hakemistojen levynkäyttötietojen tarkistamiseen.

du-komennolla on monia parametrivaihtoehtoja, joiden avulla voidaan saada tulokset useissa muodoissa. du-komento näyttää myös tiedostot ja hakemistokoot rekursiivisesti.

Tässä artikkelissa selitetään hyödyllisiä du-komentoja esimerkkien avulla, joiden avulla voit määrittää tiedostojen ja hakemistojen koon Linuxissa. Tämän artikkelin tiedot ovat peräisin du-komennon man-sivuilta.

Kuinka löytää hakemiston koko Linuxissa

1. Saat yhteenvedon levyn käytöstä hakemistopuulle /home/tecmint ja sen alihakemistoille käyttämällä seuraavaa komentoa.

du /home/tecmint

4       /home/tecmint/bin
4       /home/tecmint/.ffbinaries-cache
672     /home/tecmint/.openjfx/cache/17.0.3-ea
676     /home/tecmint/.openjfx/cache
680     /home/tecmint/.openjfx
36      /home/tecmint/.ssh
92      /home/tecmint/.config/xfce4/xfconf/xfce-perchannel-xml
96      /home/tecmint/.config/xfce4/xfconf
12      /home/tecmint/.config/xfce4/desktop
...
56758808	/home/tecmint

Yllä olevan komennon tulos näyttää levylohkojen määrän /home/tecmint-hakemistossa ja sen alihakemistot.

Kuinka löytää hakemiston koko ihmisen luettavassa muodossa

2. Käyttämällä '-h'-vaihtoehtoa du-komennon kanssa voit saada tuloksia ihmisen luettavissa Muoto", jonka avulla voit tarkastella kokoja yksiköissä, kuten tavuina, kilotavuina, megatavuina, gigatavuina ja niin edelleen.

du -h /home/tecmint

4.0K    /home/tecmint/bin
4.0K    /home/tecmint/.ffbinaries-cache
672K    /home/tecmint/.openjfx/cache/17.0.3-ea
676K    /home/tecmint/.openjfx/cache
680K    /home/tecmint/.openjfx
36K     /home/tecmint/.ssh
92K     /home/tecmint/.config/xfce4/xfconf/xfce-perchannel-xml
96K     /home/tecmint/.config/xfce4/xfconf
12K     /home/tecmint/.config/xfce4/desktop
...
55G	/home/tecmint

Kuinka löytää hakemiston kokonaiskoko Linuxissa

3. Saat yhteenvedon hakemiston levyn kokonaiskäytöstä käyttämällä '-s'-vaihtoehtoa seuraavasti.

du -sh /home/tecmint

55G	/home/tecmint

4. '-a'-lipun käyttäminen du-komennon kanssa näyttää kaikkien tiedostojen ja hakemistojen levyn käytön.

du -a /home/tecmint

4       /home/tecmint/fix-deb-src-error-ubuntu
4       /home/tecmint/tecmint.py
0       /home/tecmint/bin/FoxitReader
4       /home/tecmint/bin
4       /home/tecmint/.ffbinaries-cache
52      /home/tecmint/Eclipse-with-PyDev.jpg
300     /home/tecmint/Screenshot from 2023-07-27 14-02-45.png
16      /home/tecmint/.openjfx/cache/17.0.3-ea/libglass.so
28      /home/tecmint/.openjfx/cache/17.0.3-ea/libjavafx_font_pango.so
20      /home/tecmint/.openjfx/cache/17.0.3-ea/libjavafx_font.so
64      /home/tecmint/.openjfx/cache/17.0.3-ea/libprism_es2.so
512     /home/tecmint/.openjfx/cache/17.0.3-ea/libglassgtk3.so
...
56759528	/home/tecmint

5. Lippu '-a' ja '-h' näyttää kaikkien tiedostojen ja kansioiden levykäytön ihmisen luettavassa muodossa. muoto. Tuloksena oleva tulos on helpompi ymmärtää, koska se esittää tiedostokoot yksiköissä, kuten kilotavuina, megatavuina ja niin edelleen.

du -ah /home/tecmint

4.0K    /home/tecmint/fix-deb-src-error-ubuntu
4.0K    /home/tecmint/tecmint.py
28K     /home/tecmint/download.php?file=%2Foomph%2Fepp%2F2023-06%2FR%2Feclipse-inst-jre-linux64.tar.gz.1
0       /home/tecmint/bin/FoxitReader
4.0K    /home/tecmint/bin
4.0K    /home/tecmint/.ffbinaries-cache
52K     /home/tecmint/Eclipse-with-PyDev.jpg
300K    /home/tecmint/Screenshot from 2023-07-27 14-02-45.png
16K     /home/tecmint/.openjfx/cache/17.0.3-ea/libglass.so
28K     /home/tecmint/.openjfx/cache/17.0.3-ea/libjavafx_font_pango.so
20K     /home/tecmint/.openjfx/cache/17.0.3-ea/libjavafx_font.so
64K     /home/tecmint/.openjfx/cache/17.0.3-ea/libprism_es2.so
512K    /home/tecmint/.openjfx/cache/17.0.3-ea/libglassgtk3.so
...
55G	/home/tecmint

6. Määrittääksesi hakemistopuun ja sen alihakemistojen levynkäytön kilobyte-lohkoissa, käytä '-k'-vaihtoehtoa (näyttää koot 1024 tavun yksikköä).

du -k /home/tecmint

4       /home/tecmint/bin
4       /home/tecmint/.ffbinaries-cache
672     /home/tecmint/.openjfx/cache/17.0.3-ea
676     /home/tecmint/.openjfx/cache
680     /home/tecmint/.openjfx
8       /home/tecmint/.uk.co.screamingfrog.seospider.ui.b/webview
12      /home/tecmint/.uk.co.screamingfrog.seospider.ui.b
36      /home/tecmint/.ssh
92      /home/tecmint/.config/xfce4/xfconf/xfce-perchannel-xml
96      /home/tecmint/.config/xfce4/xfconf
12      /home/tecmint/.config/xfce4/desktop
4       /home/tecmint/.config/xfce4/xfwm4
8       /home/tecmint/.config/xfce4/panel/launcher-18
8       /home/tecmint/.config/xfce4/panel/launcher-17
8       /home/tecmint/.config/xfce4/panel/launcher-14
8       /home/tecmint/.config/xfce4/panel/launcher-3
8       /home/tecmint/.config/xfce4/panel/launcher-16
8       /home/tecmint/.config/xfce4/panel/launcher-5
...
56769128	/home/tecmint

7. Jos haluat saada yhteenvedon hakemistopuun levyn käytöstä, mukaan lukien sen alihakemistot, vain megatavuina (MB) käyttämällä '-mh' vaihtoehto seuraavasti. Lippu '-m' laskee lohkot MB-yksiköissä ja '-h' tarkoittaa ihmisen luettavaa muotoa.

du -mh /home/tecmint

4.0K    /home/tecmint/bin
4.0K    /home/tecmint/.ffbinaries-cache
672K    /home/tecmint/.openjfx/cache/17.0.3-ea
676K    /home/tecmint/.openjfx/cache
680K    /home/tecmint/.openjfx
8.0K    /home/tecmint/.uk.co.screamingfrog.seospider.ui.b/webview
12K     /home/tecmint/.uk.co.screamingfrog.seospider.ui.b
36K     /home/tecmint/.ssh
92K     /home/tecmint/.config/xfce4/xfconf/xfce-perchannel-xml
96K     /home/tecmint/.config/xfce4/xfconf
12K     /home/tecmint/.config/xfce4/desktop
4.0K    /home/tecmint/.config/xfce4/xfwm4
8.0K    /home/tecmint/.config/xfce4/panel/launcher-18
8.0K    /home/tecmint/.config/xfce4/panel/launcher-17
8.0K    /home/tecmint/.config/xfce4/panel/launcher-14
8.0K    /home/tecmint/.config/xfce4/panel/launcher-3
...
55G	/home/tecmint

8. Lippu '-c' näyttää levytilan kokonaismäärän viimeisellä rivillä. Jos hakemistosi vie 55 Gt tilaa, tulosteen kaksi viimeistä riviä näkyvät seuraavasti.

du -ch /home/tecmint

4.0K    /home/tecmint/bin
4.0K    /home/tecmint/.ffbinaries-cache
672K    /home/tecmint/.openjfx/cache/17.0.3-ea
676K    /home/tecmint/.openjfx/cache
680K    /home/tecmint/.openjfx
8.0K    /home/tecmint/.uk.co.screamingfrog.seospider.ui.b/webview
12K     /home/tecmint/.uk.co.screamingfrog.seospider.ui.b
36K     /home/tecmint/.ssh
92K     /home/tecmint/.config/xfce4/xfconf/xfce-perchannel-xml
96K     /home/tecmint/.config/xfce4/xfconf
12K     /home/tecmint/.config/xfce4/desktop
4.0K    /home/tecmint/.config/xfce4/xfwm4
8.0K    /home/tecmint/.config/xfce4/panel/launcher-18
8.0K    /home/tecmint/.config/xfce4/panel/launcher-17
8.0K    /home/tecmint/.config/xfce4/panel/launcher-14
8.0K    /home/tecmint/.config/xfce4/panel/launcher-3
8.0K    /home/tecmint/.config/xfce4/panel/launcher-16
...
55G	/home/tecmint
55G	total

Tiedostojen poissulkeminen du Commandilla

9. Seuraava komento laskee ja näyttää kaikkien tiedostojen ja hakemistojen levynkäytön, pois lukien tiedostot, jotka vastaavat annettua mallia.

Esitetyssä esimerkissä komento sulkee pois '.txt'-tiedostot laskettaessa hakemiston kokonaiskokoa. Tämän lähestymistavan avulla voit sulkea pois tiettyjä tiedostomuotoja '--exclude'-lipulla.

Kun tarkastelet tulostetta, huomaat, että '.txt'-tiedostoissa ei ole merkintöjä.

du -ah --exclude="*.txt" /home/tecmint

4.0K    /home/tecmint/fix-deb-src-error-ubuntu
4.0K    /home/tecmint/tecmint.py
0       /home/tecmint/bin/FoxitReader
4.0K    /home/tecmint/bin
4.0K    /home/tecmint/.ffbinaries-cache
52K     /home/tecmint/Eclipse-with-PyDev.jpg
300K    /home/tecmint/Screenshot from 2023-07-27 14-02-45.png
16K     /home/tecmint/.openjfx/cache/17.0.3-ea/libglass.so
28K     /home/tecmint/.openjfx/cache/17.0.3-ea/libjavafx_font_pango.so
20K     /home/tecmint/.openjfx/cache/17.0.3-ea/libjavafx_font.so
64K     /home/tecmint/.openjfx/cache/17.0.3-ea/libprism_es2.so
512K    /home/tecmint/.openjfx/cache/17.0.3-ea/libglassgtk3.so
28K     /home/tecmint/.openjfx/cache/17.0.3-ea/libjavafx_font_freetype.so
672K    /home/tecmint/.openjfx/cache/17.0.3-ea
...
55G	/home/tecmint

Kuinka löytää hakemiston käyttö muokkausajan mukaan

10. Jos haluat näyttää levyn käytön muokkausajan perusteella, käytä '--time'-lippua alla kuvatulla tavalla.

du -ha --time /home/tecmint

4.0K    2023-07-06 13:15        /home/tecmint/fix-deb-src-error-ubuntu
4.0K    2023-06-14 12:50        /home/tecmint/tecmint.py
0       2021-12-07 12:26        /home/tecmint/bin/FoxitReader
4.0K    2021-12-07 12:26        /home/tecmint/bin
4.0K    2022-10-10 11:02        /home/tecmint/.ffbinaries-cache
52K     2023-05-12 12:09        /home/tecmint/Eclipse-with-PyDev.jpg
300K    2023-07-27 14:02        /home/tecmint/Screenshot from 2023-07-27 14-02-45.png
16K     2022-10-01 12:41        /home/tecmint/.openjfx/cache/17.0.3-ea/libglass.so
28K     2022-10-01 12:41        /home/tecmint/.openjfx/cache/17.0.3-ea/libjavafx_font_pango.so
20K     2022-10-01 12:41        /home/tecmint/.openjfx/cache/17.0.3-ea/libjavafx_font.so
64K     2022-10-01 12:41        /home/tecmint/.openjfx/cache/17.0.3-ea/libprism_es2.so
512K    2022-10-01 12:41        /home/tecmint/.openjfx/cache/17.0.3-ea/libglassgtk3.so
28K     2022-10-01 12:41        /home/tecmint/.openjfx/cache/17.0.3-ea/libjavafx_font_freetype.so
672K    2022-10-01 12:41        /home/tecmint/.openjfx/cache/17.0.3-ea
676K    2022-10-01 12:41        /home/tecmint/.openjfx/cache
...
55G	2023-08-14 10:22	/home/tecmint

du-komento on monipuolinen, ja se voidaan räätälöidä tarpeidesi mukaan käyttämällä erilaisia vaihtoehtoja ja lippuja. Käytä päätteen man du-komentoa saadaksesi tarkempia tietoja sen vaihtoehdoista ja käytöstä.