Linux에서 파티션의 모든 파일을 나열하는 방법은 무엇입니까?

Linux에서 파티션의 모든 파일을 나열하는 방법은 무엇입니까?

내 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뚱뚱한 디렉토리에 가서 거기에 무엇이 있는지 알아내는 것입니다.

답변2

find / -mount -type f -ls 

와 유사한 출력을 가진 모든 파일을 나열합니다 ls -dils.

find / -mount  -type f -printf "%s  %h/%f\n"

크기와 이름만 인쇄됩니다.

-mount(또는 ) 옵션은 find가 마운트된 다른 파일 시스템( 일반적으로 최소한 몇 개가 있음) -xdev으로 내려가지 않도록 지시 하고 디렉토리나 링크가 나열되지 않고 파일만 나열되도록 합니다./type -f

자세한 내용은 을 참조하세요 man find.

답변3

cd /
ls -lR > lists.txt

디렉토리가 있는 모든 파일 나열

관련 정보