当前位置: 首页 > 工具软件 > registry-du > 使用案例 >

从小到大列出文件/目录大小------du -a | sort -n

雍兴修
2023-12-01

         linux究竟是方便, 所想即所得, 想什么就能得到什么。 很多时候, linux中文件太多, 需要删除一些, 腾出一些空间, 那先从小到大列出文件/目录吧:

 

taoge@localhost ~> du -a | sort -n
0       ./b.cpp
0       ./cmd/a.txt
0       ./Desktop/a.txt
0       ./Desktop/test/a.txt
0       ./Desktop/test/b.txt
0       ./.gconf/apps/brasero/%gconf.xml
0       ./.gconf/apps/%gconf.xml
0       ./.gconf/apps/gedit-2/%gconf.xml
0       ./.gconf/apps/gedit-2/preferences/%gconf.xml
0       ./.gconf/apps/gedit-2/preferences/ui/%gconf.xml
0       ./.gconf/apps/gnome-terminal/%gconf.xml
0       ./.gconf/apps/gnome-terminal/profiles/%gconf.xml
0       ./.gconf/apps/nautilus/desktop-metadata/%gconf.xml
0       ./.gconf/apps/nautilus/%gconf.xml
0       ./.gconf/apps/panel/applets/clock/%gconf.xml
0       ./.gconf/apps/panel/applets/%gconf.xml
0       ./.gconf/apps/panel/applets/window_list/%gconf.xml
0       ./.gconf/apps/panel/applets/workspace_switcher/%gconf.xml
0       ./.gconf/apps/panel/%gconf.xml
0       ./.gconf/desktop/%gconf.xml
0       ./.gconf/desktop/gnome/accessibility/%gconf.xml
0       ./.gconf/desktop/gnome/%gconf.xml
0       ./.gconf/desktop/gnome/peripherals/%gconf.xml
0       ./.gconf/desktop/gnome/peripherals/keyboard/%gconf.xml
0       ./.gnupg/pubring.gpg
0       ./.gnupg/secring.gpg
0       ./.local/share/.converted-launchers
0       ./.local/share/Trash/files/test.2.html
0       ./.local/share/Trash/files/test.c
0       ./.local/share/Trash/files/test.html
0       ./.pulse/205d7fca86a0af0c45d758ee00000024-runtime
0       ./.RecycleBin/a.txt__DelTime:Sat_May__9_22:16:13_PDT_2015
0       ./.RecycleBin/a.txt__DelTime:Sat_May__9_22:16:38_PDT_2015
0       ./.RecycleBin/a.txt__DelTime:Sat_May__9_22:23:36_PDT_2015
4       ./a.txt
4       ./.bash_logout
4       ./.bash_profile
4       ./.bashrc
4       ./bin/delete
4       ./.cache/gedit/gedit-metadata.xml
4       ./client.c
4       ./cmd/a.txt.haha
4       ./.config/gnome-disk-utility/ata-smart-ignore
4       ./.config/gnome-session/saved-session
4       ./.config/user-dirs.dirs
4       ./.config/user-dirs.locale
4       ./c.sh
4       ./.dbus/session-bus/205d7fca86a0af0c45d758ee00000024-0
4       ./Desktop/a.c
4       ./Desktop/b.c
4       ./Desktop/c.sh
4       ./Desktop/learn_file/a.out
4       ./Desktop/learn_file/libtest.a
4       ./Desktop/learn_file/libtest.so
4       ./Desktop/learn_file/main.c
4       ./Desktop/learn_file/main.o
4       ./Desktop/learn_file/test.c
4       ./Desktop/learn_file/test.h
4       ./Desktop/learn_file/test.o
4       ./Desktop/learn_ldd/libtest.a
4       ./Desktop/learn_ldd/libtest.so
4       ./Desktop/learn_ldd/main.c
4       ./Desktop/learn_ldd/test.c
4       ./Desktop/learn_ldd/test.h
4       ./Desktop/learn_ldd/test.o
4       ./Desktop/learnMakeFile/input.c
4       ./Desktop/learnMakeFile/input.h
4       ./Desktop/learnMakeFile/input.o
4       ./Desktop/learnMakeFile/main.c
4       ./Desktop/learnMakeFile/main.o
4       ./Desktop/learnMakeFile/makefile
4       ./Desktop/learnMakeFile/mymakefile
4       ./Desktop/learnMakeFile/output.c
4       ./Desktop/learnMakeFile/output.h
4       ./Desktop/learnMakeFile/output.o
4       ./Desktop/learnMakeFile/process.c
4       ./Desktop/learnMakeFile/process.h
4       ./Desktop/learnMakeFile/process.o
4       ./Desktop/learn_nm/main.c
4       ./Desktop/learn_objdump/main.c
4       ./Desktop/learn_objdump/main.o
4       ./Desktop/learn_readelf/main.c
4       ./Desktop/learn_reg/a.txt
4       ./Desktop/learn_shell/a.sh
4       ./Desktop/learn_strings/test.c
4       ./Desktop/learn_strings/test.h
4       ./Desktop/learn_strip/a.out
4       ./Desktop/learn_strip/main.c
4       ./Desktop/main.c
4       ./Desktop/reg/test.txt
4       ./Desktop/server.c
4       ./Desktop/sql/taoge.db
4       ./Desktop/test.c
4       ./Desktop/test/tree-1.7.0/doc/xml.dtd
4       ./Desktop/test/tree-1.7.0/hash.c
4       ./Desktop/test/tree-1.7.0/INSTALL
4       ./Desktop/test/tree-1.7.0/Makefile
4       ./Desktop/test/tree-1.7.0/TODO
4       ./Desktop/test.txt
4       ./Desktop/tmp/input.c
4       ./Desktop/tmp/input.h
4       ./Desktop/tmp/main.c
4       ./Desktop/tmp/output.c
4       ./Desktop/tmp/output.h
4       ./Desktop/tmp/process.c
4       ./Desktop/tmp/process.h
4       ./Desktop/tree-1.7.0/doc/xml.dtd
4       ./Desktop/tree-1.7.0/hash.c
4       ./Desktop/tree-1.7.0/INSTALL
4       ./Desktop/tree-1.7.0/Makefile
4       ./Desktop/tree-1.7.0/TODO
4       ./Documents
4       ./Downloads
4       ./.esd_auth
4       ./.gconf/apps/brasero/config/%gconf.xml
4       ./.gconf/apps/brasero/config/priority/%gconf.xml
4       ./.gconf/apps/gedit-2/preferences/ui/statusbar/%gconf.xml
4       ./.gconf/apps/gnome-terminal/profiles/Default/%gconf.xml
4       ./.gconf/apps/gnote/%gconf.xml
4       ./.gconf/apps/nautilus/desktop-metadata/2@46@1@32@GB@32@Filesystem@46@volume/%gconf.xml
4       ./.gconf/apps/nautilus/desktop-metadata/8@46@0@32@GB@32@Filesystem@46@volume/%gconf.xml
4       ./.gconf/apps/nautilus/desktop-metadata/CDROM@46@volume/%gconf.xml
4       ./.gconf/apps/nautilus/desktop-metadata/computer/%gconf.xml
4       ./.gconf/apps/nautilus/desktop-metadata/directory/%gconf.xml
4       ./.gconf/apps/nautilus/desktop-metadata/home/%gconf.xml
4       ./.gconf/apps/nautilus/desktop-metadata/RHEL_6@46@0@32@i386@32@Disc@32@1@46@volume/%gconf.xml
4       ./.gconf/apps/nautilus/desktop-metadata/trash/%gconf.xml
4       ./.gconf/apps/nm-applet/%gconf.xml
4       ./.gconf/apps/panel/applets/clock/prefs/%gconf.xml
4       ./.gconf/apps/panel/applets/window_list/prefs/%gconf.xml
4       ./.gconf/apps/panel/applets/workspace_switcher/prefs/%gconf.xml
4       ./.gconf/desktop/gnome/accessibility/keyboard/%gconf.xml
4       ./.gconf/desktop/gnome/peripherals/keyboard/kbd/%gconf.xml
4       ./.gnome2/gedit/gedit-2
4       ./.gnome2/keyrings/login.keyring
4       ./.gnome2/nautilus-scripts
4       ./.gnome2/panel2.d/default/launchers
4       ./.gnome2/yelp
4       ./.gnote/addins
4       ./.gnote/bbc20544-d90b-41ef-986d-14e79a71d8b8.note
4       ./.gnote/e31c0bfc-8839-455f-a1fa-85812331a2f5.note
4       ./.gnupg/trustdb.gpg
4       ./.gtk-bookmarks
4       ./.gvfs
4       ./.local/share/applications/preferred-mail-reader.desktop
4       ./.local/share/applications/preferred-web-browser.desktop
4       ./.local/share/gvfs-metadata/home
4       ./.local/share/gvfs-metadata/label-CDROM
4       ./.local/share/gvfs-metadata/label-RHEL_6.0\x20i386\x20Disc\x201
4       ./.local/share/gvfs-metadata/uuid-38B8-2797
4       ./.local/share/gvfs-metadata/uuid-B801-BA9B
4       ./.local/share/Trash/files/a.sh
4       ./.local/share/Trash/files/test.txt
4       ./.local/share/Trash/info/a.sh.trashinfo
4       ./.local/share/Trash/info/test.2.html.trashinfo
4       ./.local/share/Trash/info/test.c.trashinfo
4       ./.local/share/Trash/info/test.html.trashinfo
4       ./.local/share/Trash/info/test.txt.trashinfo
4       ./main.cpp
4       ./.mozilla/extensions/{ec8030f7-c20a-464f-9b0e-13a3a9e97384}
4       ./.mozilla/plugins
4       ./Music
4       ./.nautilus
4       ./Pictures
4       ./Public
4       ./.pulse/205d7fca86a0af0c45d758ee00000024-card-database.tdb
4       ./.pulse/205d7fca86a0af0c45d758ee00000024-default-sink
4       ./.pulse/205d7fca86a0af0c45d758ee00000024-default-source
4       ./.pulse-cookie
4       ./.recently-used.xbel
4       ./.RecycleBin/folder__DelTime:Sat_May__9_22:16:13_PDT_2015
4       ./.RecycleBin/folder__DelTime:Sat_May__9_22:16:38_PDT_2015
4       ./.ssh
4       ./taoge/test.cpp
4       ./Templates
4       ./test.c
4       ./test.cpp
4       ./test.sh
4       ./test/test.cpp
4       ./.thumbnails/fail/gnome-thumbnail-factory
4       ./.thumbnails/normal
4       ./tmp/test/add.c
4       ./tmp/test/add.h
4       ./tmp/test/inc
4       ./tmp/test/main.c
4       ./Videos
4       ./.vim/.netrwhist
4       ./.xauthGFiXuo
4       ./.xauthi3iigm
4       ./.xsession-errors
4       ./.xsession-errors.old
8       ./a.out
8       ./bin
8       ./.cache/gedit
8       ./cmd
8       ./.config/gnome-disk-utility
8       ./.config/gnome-session
8       ./.dbus/session-bus
8       ./Desktop/a.out
8       ./Desktop/learn_c/a.out
8       ./Desktop/learn_ldd/a.out
8       ./Desktop/learnMakeFile/main
8       ./Desktop/learn_nm/a.out
8       ./Desktop/learn_objdump/a.out
8       ./Desktop/learn_readelf/a.out
8       ./Desktop/learn_reg
8       ./Desktop/learn_shell
8       ./Desktop/reg
8       ./Desktop/sql
8       ./Desktop/test/tree-1.7.0/doc/tree.1.fr
8       ./Desktop/test/tree-1.7.0/hash.o
8       ./Desktop/test/tree-1.7.0/README
8       ./Desktop/test/tree-1.7.0/strverscmp.c
8       ./Desktop/test/tree-1.7.0/tree.h
8       ./Desktop/test/tree-1.7.0/unix.c
8       ./Desktop/tmp/a.out
8       ./Desktop/tree-1.7.0/doc/tree.1.fr
8       ./Desktop/tree-1.7.0/hash.o
8       ./Desktop/tree-1.7.0/README
8       ./Desktop/tree-1.7.0/strverscmp.c
8       ./Desktop/tree-1.7.0/tree.h
8       ./Desktop/tree-1.7.0/unix.c
8       ./.gconf/apps/brasero/config/priority
8       ./.gconf/apps/gedit-2/preferences/ui/statusbar
8       ./.gconf/apps/gnome-terminal/profiles/Default
8       ./.gconf/apps/gnote
8       ./.gconf/apps/nautilus/desktop-metadata/2@46@1@32@GB@32@Filesystem@46@volume
8       ./.gconf/apps/nautilus/desktop-metadata/8@46@0@32@GB@32@Filesystem@46@volume
8       ./.gconf/apps/nautilus/desktop-metadata/CDROM@46@volume
8       ./.gconf/apps/nautilus/desktop-metadata/computer
8       ./.gconf/apps/nautilus/desktop-metadata/directory
8       ./.gconf/apps/nautilus/desktop-metadata/home
8       ./.gconf/apps/nautilus/desktop-metadata/RHEL_6@46@0@32@i386@32@Disc@32@1@46@volume
8       ./.gconf/apps/nautilus/desktop-metadata/trash
8       ./.gconf/apps/nm-applet
8       ./.gconf/apps/panel/applets/clock/prefs
8       ./.gconf/apps/panel/applets/window_list/prefs
8       ./.gconf/apps/panel/applets/workspace_switcher/prefs
8       ./.gconf/desktop/gnome/accessibility/keyboard
8       ./.gconf/desktop/gnome/peripherals/keyboard/kbd
8       ./.gnome2/gedit
8       ./.gnome2/keyrings
8       ./.gnome2/panel2.d/default
8       ./.gnupg/gpg.conf
8       ./.mozilla/extensions
8       ./taoge/a.out
8       ./test
8       ./.thumbnails/fail
8       ./tmp/test/a.out
8       ./.vim
8       ./.viminfo
12      ./.a.txt.swp
12      ./.cache/event-sound-cache.tdb.205d7fca86a0af0c45d758ee00000024.i386-redhat-linux-gnu
12      ./.dbus
12      ./Desktop/learn_c
12      ./Desktop/learn_strings
12      ./Desktop/learn_strip
12      ./Desktop/test/tree-1.7.0/CHANGES
12      ./Desktop/test/tree-1.7.0/doc/tree.1
12      ./Desktop/test/tree-1.7.0/json.c
12      ./Desktop/test/tree-1.7.0/xml.c
12      ./Desktop/tree-1.7.0/CHANGES
12      ./Desktop/tree-1.7.0/doc/tree.1
12      ./Desktop/tree-1.7.0/json.c
12      ./Desktop/tree-1.7.0/xml.c
12      ./.gconf/apps/gedit-2/preferences/ui
12      ./.gconf/apps/gnome-terminal/profiles
12      ./.gconf/apps/panel/applets/clock
12      ./.gconf/apps/panel/applets/window_list
12      ./.gconf/apps/panel/applets/workspace_switcher
12      ./.gconf/desktop/gnome/accessibility
12      ./.gconf/desktop/gnome/peripherals/keyboard
12      ./.gnome2/panel2.d
12      ./.local/share/applications
12      ./.local/share/Trash/files
12      ./.RecycleBin
16      ./.bash_history
16      ./Desktop/learn_nm
16      ./Desktop/learn_readelf
16      ./Desktop/test/tree-1.7.0/color.c
16      ./Desktop/test/tree-1.7.0/html.c
16      ./Desktop/test/tree-1.7.0/unix.o
16      ./Desktop/tree-1.7.0/color.c
16      ./Desktop/tree-1.7.0/html.c
16      ./Desktop/tree-1.7.0/unix.o
16      ./.gconf/apps/brasero/config
16      ./.gconf/apps/gedit-2/preferences
16      ./.gconf/apps/gnome-terminal
16      ./.gconf/desktop/gnome/peripherals
16      ./.gnote
16      ./.gnupg
16      ./.ICEauthority
16      ./.mozilla
16      ./taoge
16      ./.thumbnails
20      ./Desktop/learn_objdump
20      ./Desktop/test/tree-1.7.0/json.o
20      ./Desktop/test/tree-1.7.0/LICENSE
20      ./Desktop/test/tree-1.7.0/xml.o
20      ./Desktop/tree-1.7.0/json.o
20      ./Desktop/tree-1.7.0/LICENSE
20      ./Desktop/tree-1.7.0/xml.o
20      ./.gconf/apps/brasero
20      ./.gconf/apps/gedit-2
24      ./.cache
24      ./.local/share/Trash/info
28      ./.config
28      ./Desktop/test/tree-1.7.0/color.o
28      ./Desktop/test/tree-1.7.0/doc
28      ./Desktop/test/tree-1.7.0/html.o
28      ./Desktop/tree-1.7.0/color.o
28      ./Desktop/tree-1.7.0/doc
28      ./Desktop/tree-1.7.0/html.o
28      ./tmp/test
32      ./.gconf/desktop/gnome
32      ./.local/share/gvfs-metadata/home-27d2d18f.log
32      ./.local/share/gvfs-metadata/label-CDROM-692a0446.log
32      ./.local/share/gvfs-metadata/label-RHEL_6.0\x20i386\x20Disc\x201-22a4ce3f.log
32      ./.local/share/gvfs-metadata/uuid-38B8-2797-73f21b7b.log
32      ./.local/share/gvfs-metadata/uuid-B801-BA9B-b25463a0.log
32      ./tmp
36      ./Desktop/learn_file
36      ./Desktop/learn_ldd
36      ./Desktop/test/tree-1.7.0/tree.c
36      ./Desktop/tree-1.7.0/tree.c
36      ./.gconf/desktop
40      ./Desktop/tmp
40      ./.gconf/apps/panel/applets
40      ./.gnome2
40      ./.local/share/Trash
44      ./.gconf/apps/panel
48      ./Desktop/test/tree-1.7.0.tgz
48      ./Desktop/tree-1.7.0.tgz
60      ./.pulse/205d7fca86a0af0c45d758ee00000024-device-volumes.tdb
64      ./Desktop/learnMakeFile
68      ./Desktop/test/tree-1.7.0/tree.o
68      ./Desktop/tree-1.7.0/tree.o
68      ./.gconf/apps/nautilus/desktop-metadata
72      ./.gconf/apps/nautilus
72      ./.gconfd/saved_state
72      ./.pulse/205d7fca86a0af0c45d758ee00000024-stream-volumes.tdb
76      ./.gconfd
120     ./Desktop/test/tree-1.7.0/tree
120     ./Desktop/tree-1.7.0/tree
148     ./.pulse
184     ./.local/share/gvfs-metadata
192     ./.gconf/apps
232     ./.gconf
240     ./.local/share
244     ./.local
276     ./Desktop/lrzsz-0.12.20.tar.gz
368     ./.gstreamer-0.10/registry.i386.bin
372     ./.gstreamer-0.10
512     ./Desktop/test/tree-1.7.0
512     ./Desktop/tree-1.7.0
564     ./Desktop/test
1736    ./Desktop
126608  ./jdk-7u51-windows-i586.exe
129852  .

      du -a是列出所有文件/目录大小, sort -n是按照number进行排序。 

 

      注意, 在该例中, 不能用du -ah, 否则可能会出现1.7M < 2k这样的问题。 另外, sort的-n不可忽略。 

      对于linux而言, 执行完一条命令后, 我们很容易看到执行结果的最后几行(离即将输入的地方最近), 所以, 几乎不用更多的过滤。

 

      如果又想排序, 又想看大小, 怎么办呢? 再配合awk和args吧。

 

 

 

 

 

 


 

 类似资料: