我的 RHEL 盒子磁盘不足。我正在尝试查找全部文件中/dev/sda2
。我们是否有一个命令可以给出全部文件系统中的文件(理想情况下,具有大小)/dev/sda2
?
/dev/sda2
31297508 28615356 1092292 97% /
mybox > df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda2 31297508 28615356 1092292 97% /
答案1
Sven 的回答确实回答了“如何列出 Linux 上某个分区的所有文件?”这个字面问题。但我认为隐含的问题更有趣:“如何找出驱动器中的内容?”。
我从根文件系统开始,然后使用命令du
。这会告诉我“最常用”的那些。然后我进入该目录并重复此操作,直到深入下去。您也可以删除该--max-depth=1
部分,它会一次性分解每个子目录。我发现输出有点令人不知所措,但这就是风格问题。
在以下示例中,/etc 目录是最大目录。(我稍微缩短了输出。)
$ cd /
$ sudo du -amDx --max-depth=1|sort -nk1
0 ./bin
0 ./lib
0 ./lib64
0 ./sbin
1 ./lost+found
1 ./media
1 ./mnt
1 ./.rnd
1 ./srv
7 ./root
40 ./etc
46 .
$ cd etc/
$ sudo du -amDx --max-depth=1|sort -nk1
0 ./cron.deny
0 ./crypttab
0 ./environment
...
1 ./wpa_supplicant
1 ./X11
1 ./xdg
1 ./xinetd.d
1 ./yum
1 ./yum.conf
1 ./yum.repos.d
2 ./csf
2 ./pki
8 ./udev
24 ./selinux
40 .
在以下同一个盒子上的示例中,我取出--max-depth=1
:
$ sudo du -amDx |sort -nk1
0 ./bin
0 ./etc/alternatives/cifs-idmap-plugin
0 ./etc/alternatives/ld
0 ./etc/alternatives/libnssckbi.so.x86_64
0 ./etc/alternatives/libwbclient.so.0.13-64
0 ./etc/alternatives/mta
0 ./etc/alternatives/mta-aliasesman
0 ./etc/alternatives/mta-mailq
0 ./etc/alternatives/mta-mailqman
0 ./etc/alternatives/mta-newaliases
...
1 ./etc/services
1 ./etc/sestatus.conf
1 ./etc/setuptool.d
1 ./etc/setuptool.d/98netconfig
1 ./etc/setuptool.d/98system-config-authentication
1 ./etc/setuptool.d/98system-config-display
1 ./etc/setuptool.d/98system-config-keyboard
1 ./etc/setuptool.d/99authconfig
1 ./etc/setuptool.d/99kbdconfig
1 ./etc/setuptool.d/99mouseconfig
1 ./etc/setuptool.d/99ntsysv
1 ./etc/setuptool.d/99printconf-tui
1 ./etc/setuptool.d/99sndconfig
1 ./etc/setuptool.d/99system-config-firewall-tui
1 ./etc/setuptool.d/99system-config-network-tui
1 ./etc/setuptool.d/99timeconfig
1 ./etc/setuptool.d/99Xconfigurator
1 ./etc/shadow
1 ./etc/shadow-
1 ./etc/shells
1 ./etc/skel
1 ./etc/skel/.bash_logout
1 ./etc/skel/.bash_profile
1 ./etc/skel/.bashrc
1 ./etc/smartmontools
1 ./etc/smartmontools/smartd.conf
1 ./etc/smartmontools/smartd_warning.d
1 ./etc/smartmontools/smartd_warning.sh
1 ./etc/sos.conf
1 ./etc/ssh
1 ./etc/ssh/moduli
1 ./etc/ssh/ssh_config
1 ./etc/ssh/sshd_config
1 ./etc/ssh/ssh_host_ecdsa_key
1 ./etc/ssh/ssh_host_ecdsa_key.pub
1 ./etc/ssh/ssh_host_ed25519_key
1 ./etc/ssh/ssh_host_ed25519_key.pub
1 ./etc/ssh/ssh_host_rsa_key
1 ./etc/ssh/ssh_host_rsa_key.pub
1 ./etc/ssl
1 ./etc/statetab
1 ./etc/statetab.d
1 ./etc/sudo.conf
1 ./etc/sudoers
1 ./etc/sudoers.d
1 ./etc/sudoers.d/waagent
1 ./etc/sudo-ldap.conf
1 ./etc/sysconfig
1 ./etc/sysconfig/anaconda
1 ./etc/sysconfig/atd
1 ./etc/sysconfig/authconfig
1 ./etc/sysconfig/cbq
1 ./etc/sysconfig/cbq/avpkt
1 ./etc/sysconfig/cbq/cbq-0000.example
1 ./etc/sysconfig/certbot
1 ./etc/sysconfig/chronyd
1 ./etc/sysconfig/console
1 ./etc/sysconfig/cpupower
1 ./etc/sysconfig/crond
1 ./etc/sysconfig/ebtables-config
1 ./etc/sysconfig/firewalld
1 ./etc/sysconfig/htcacheclean
1 ./etc/sysconfig/httpd
1 ./etc/sysconfig/init
1 ./etc/sysconfig/ip6tables
1 ./etc/sysconfig/ip6tables-config
1 ./etc/sysconfig/iptables
1 ./etc/sysconfig/iptables-config
1 ./etc/sysconfig/irqbalance
1 ./etc/sysconfig/kdump
1 ./etc/sysconfig/kernel
1 ./etc/sysconfig/man-db
1 ./etc/sysconfig/modules
1 ./etc/sysconfig/netconsole
1 ./etc/sysconfig/ntpdate
1 ./etc/sysconfig/raid-check
1 ./etc/sysconfig/rdisc
1 ./etc/sysconfig/readonly-root
1 ./etc/sysconfig/rpcbind
1 ./etc/sysconfig/rpc-rquotad
1 ./etc/sysconfig/rsyncd
1 ./etc/sysconfig/rsyslog
1 ./etc/sysconfig/samba
1 ./etc/sysconfig/smartmontools
1 ./etc/sysconfig/sshd
1 ./etc/sysconfig/sysstat
1 ./etc/sysconfig/sysstat.ioconf
1 ./etc/sysconfig/wpa_supplicant
1 ./etc/sysctl.conf
1 ./etc/sysctl.d
1 ./etc/systemd
1 ./etc/systemd/bootchart.conf
1 ./etc/systemd/coredump.conf
1 ./etc/systemd/journald.conf
1 ./etc/systemd/logind.conf
1 ./etc/systemd/system
1 ./etc/systemd/system/basic.target.wants
1 ./etc/systemd/system.conf
1 ./etc/systemd/system/default.target.wants
1 ./etc/systemd/system/getty.target.wants
1 ./etc/systemd/system/multi-user.target.wants
1 ./etc/systemd/system/sockets.target.wants
1 ./etc/systemd/system/sysinit.target.wants
1 ./etc/systemd/system/system-update.target.wants
1 ./etc/systemd/user
1 ./etc/systemd/user.conf
1 ./etc/system-release-cpe
1 ./etc/terminfo
1 ./etc/tmpfiles.d
1 ./etc/trusted-key.key
1 ./etc/tuned
1 ./etc/tuned/active_profile
1 ./etc/tuned/bootcmdline
1 ./etc/tuned/tuned-main.conf
1 ./etc/udev/rules.d
1 ./etc/udev/rules.d/66-azure-storage.rules
1 ./etc/udev/rules.d/99-azure-product-uuid.rules
1 ./etc/udev/udev.conf
1 ./etc/.updated
1 ./etc/updatedb.conf
1 ./etc/usb_modeswitch.conf
1 ./etc/vconsole.conf
1 ./etc/vimrc
1 ./etc/virc
1 ./etc/waagent.conf
1 ./etc/wgetrc
1 ./etc/wpa_supplicant
1 ./etc/wpa_supplicant/wpa_supplicant.conf
1 ./etc/X11
1 ./etc/X11/applnk
1 ./etc/X11/fontpath.d
1 ./etc/X11/xorg.conf.d
1 ./etc/X11/xorg.conf.d/00-keyboard.conf
1 ./etc/xdg
1 ./etc/xdg/autostart
1 ./etc/xdg/systemd
1 ./etc/xinetd.d
1 ./etc/yum
1 ./etc/yum.conf
1 ./etc/yum/fssnap.d
1 ./etc/yum/pluginconf.d
1 ./etc/yum/pluginconf.d/fastestmirror.conf
1 ./etc/yum/pluginconf.d/langpacks.conf
1 ./etc/yum/protected.d
1 ./etc/yum/protected.d/systemd.conf
1 ./etc/yum.repos.d
1 ./etc/yum.repos.d/CentOS-Base.repo
1 ./etc/yum.repos.d/CentOS-CR.repo
1 ./etc/yum.repos.d/CentOS-Debuginfo.repo
1 ./etc/yum.repos.d/CentOS-fasttrack.repo
1 ./etc/yum.repos.d/CentOS-Media.repo
1 ./etc/yum.repos.d/CentOS-Sources.repo
1 ./etc/yum.repos.d/CentOS-Vault.repo
1 ./etc/yum.repos.d/epel.repo
1 ./etc/yum.repos.d/epel-testing.repo
1 ./etc/yum.repos.d/OpenLogic.repo
1 ./etc/yum/vars
1 ./etc/yum/vars/infra
1 ./etc/yum/version-groups.conf
1 ./lost+found
1 ./media
1 ./mnt
1 ./mnt/cdrom
1 ./mnt/cdrom/secure
1 ./.rnd
1 ./root/anaconda-ks.cfg
1 ./root/.bash_history
1 ./root/.bash_logout
1 ./root/.bash_profile
1 ./root/.bashrc
1 ./root/.cache/abrt
1 ./root/.cache/abrt/lastnotification
1 ./root/.cache/pip/http/0
1 ./root/.cache/pip/http/0/2
1 ./root/.cache/pip/http/0/2/c
1 ./root/.cache/pip/http/0/2/c/7
1 ./root/.cache/pip/http/0/2/c/7/2
1 ./root/.cache/pip/http/9
1 ./root/.cache/pip/http/9/4
1 ./root/.cache/pip/http/9/4/f
1 ./root/.cache/pip/http/9/4/f/3
1 ./root/.cache/pip/http/9/4/f/3/2
1 ./root/.cache/pip/http/9/e
1 ./root/.cache/pip/http/9/e/6
1 ./root/.cache/pip/http/9/e/6/1
1 ./root/.cache/pip/http/9/e/6/1/9
1 ./root/.cache/pip/http/a
1 ./root/.cache/pip/http/a/6
1 ./root/.cache/pip/http/a/6/9
1 ./root/.cache/pip/http/a/6/9/b
1 ./root/.cache/pip/http/a/6/9/b/d
1 ./root/.cache/pip/http/a/6/d
1 ./root/.cache/pip/http/a/6/d/a
1 ./root/.cache/pip/http/a/6/d/a/3
1 ./root/.cache/pip/http/b
1 ./root/.cache/pip/http/b/9
1 ./root/.cache/pip/http/b/9/2
1 ./root/.cache/pip/http/b/9/2/d
1 ./root/.cache/pip/http/b/9/2/d/5
1 ./root/.cache/pip/http/b/b
1 ./root/.cache/pip/http/b/b/b
1 ./root/.cache/pip/http/b/b/b/e
1 ./root/.cache/pip/http/b/b/b/e/e
1 ./root/.cache/pip/http/d
1 ./root/.cache/pip/http/d/b
1 ./root/.cache/pip/http/d/b/c
1 ./root/.cache/pip/http/d/b/c/4
1 ./root/.cache/pip/http/d/b/c/4/0
1 ./root/.cache/pip/http/d/f
1 ./root/.cache/pip/http/d/f/6
1 ./root/.cache/pip/http/d/f/6/b
1 ./root/.cache/pip/http/d/f/6/b/4
1 ./root/.cache/pip/http/e
1 ./root/.cache/pip/http/e/7
1 ./root/.cache/pip/http/e/7/9
1 ./root/.cache/pip/http/e/7/9/4
1 ./root/.cache/pip/http/e/7/9/4/7
1 ./root/.cache/pip/http/e/e
1 ./root/.cache/pip/http/e/e/d
1 ./root/.cache/pip/http/e/e/d/f
1 ./root/.cache/pip/http/e/e/d/f/d
1 ./root/.cache/pip/http/e/f
1 ./root/.cache/pip/http/e/f/e
1 ./root/.cache/pip/http/e/f/e/f
1 ./root/.cache/pip/http/e/f/e/f/5
1 ./root/.cache/pip/http/f/4
1 ./root/.cache/pip/http/f/4/6
1 ./root/.cache/pip/http/f/4/6/d
1 ./root/.cache/pip/http/f/4/6/d/d
1 ./root/.cache/pip/http/f/7
1 ./root/.cache/pip/http/f/7/6
1 ./root/.cache/pip/http/f/7/6/f
1 ./root/.cache/pip/http/f/7/6/f/f
1 ./root/.cache/pip/http/f/8
1 ./root/.cache/pip/http/f/8/a
1 ./root/.cache/pip/http/f/8/a/c
1 ./root/.cache/pip/http/f/8/a/c/9
1 ./root/.cache/pip/http/f/c
1 ./root/.cache/pip/http/f/c/9
1 ./root/.cache/pip/http/f/c/9/f
1 ./root/.cache/pip/http/f/c/9/f/0
1 ./root/.cache/pip/http/f/e
1 ./root/.cache/pip/http/f/e/d
1 ./root/.cache/pip/http/f/e/d/0
1 ./root/.cache/pip/http/f/e/d/0/e
1 ./root/.cache/pip/selfcheck.json
1 ./root/.cache/pip/wheels
1 ./root/.cache/pip/wheels/8d
1 ./root/.cache/pip/wheels/8d/05
1 ./root/.cache/pip/wheels/8d/05/e9
1 ./root/.cache/pip/wheels/95
1 ./root/.cache/pip/wheels/95/14
1 ./root/.cache/pip/wheels/95/14/9a
1 ./root/.cache/pip/wheels/d7
1 ./root/.cache/pip/wheels/d7/6b
1 ./root/.cache/pip/wheels/d7/6b/69
1 ./root/.config
1 ./root/.config/abrt
1 ./root/.lesshst
1 ./root/.pki
1 ./root/.pki/nssdb
1 ./root/.rnd
1 ./root/tall epel-release
1 ./root/.tcshrc
1 ./root/.viminfo
1 ./srv
2 ./etc/csf
2 ./etc/csf/ui
2 ./etc/csf/ui/images
2 ./root/.cache/pip/http/2
2 ./root/.cache/pip/http/2/3
2 ./root/.cache/pip/http/2/3/b
2 ./root/.cache/pip/http/2/3/b/7
2 ./root/.cache/pip/http/2/3/b/7/9
3 ./root/.cache/pip/http/f
3 ./root/.cache/pip/http/f/f
3 ./root/.cache/pip/http/f/f/f
3 ./root/.cache/pip/http/f/f/f/e
3 ./root/.cache/pip/http/f/f/f/e/a
6 ./root/.cache
6 ./root/.cache/pip
6 ./root/.cache/pip/http
7 ./root
8 ./etc/udev
8 ./etc/udev/hwdb.bin
11 ./etc/selinux/targeted/active/modules
11 ./etc/selinux/targeted/active/modules/100
18 ./etc/selinux/targeted/active
24 ./etc/selinux
24 ./etc/selinux/targeted
40 ./etc
46 .
剩下的就是找到ls
fat dirs 并找出其中的内容。
答案2
find / -mount -type f -ls
将列出所有文件,其输出类似于ls -dils
。
find / -mount -type f -printf "%s %h/%f\n"
只会打印尺寸和名称。
-mount
(或)选项-xdev
告诉 find 不要进入其他已安装的文件系统(/
通常至少有几个),并type -f
确保只列出文件而不是目录或链接。
请参阅man find
以了解更多信息。
答案3
cd /
ls -lR > lists.txt
列出所有带有目录的文件