GNU/Linux >> Belajar Linux >  >> Linux

Cara Menghitung Jumlah File dan Sub-direktori di dalam Direktori

Hi guys, Pada artikel ini kami akan menunjukkan cara menghitung jumlah file dan sub-direktori dalam sebuah direktori menggunakan perintah pohon.

Hitung jumlah file dan direktori dengan perintah pohon :

  • Pohon perintah akan bekerja bahkan jika tidak ada argumen yang diberikan seperti yang ditunjukkan di bawah ini:
tree -iLf 1
  1. “-i” :memungkinkan pohon untuk mencetak garis lekukan.
  2. “-L” :menentukan level dari kedalaman dari pohon direktori yang akan ditampilkan, yang dalam kasus di atas adalah 1 .
  3. “-f” :membuat pohon mencetak awalan path lengkap untuk setiap file.
  • Jika Anda ingin melihat informasi yang sama tanpa argumen untuk tingkat kedalaman 2:
tree -iLf 2
  • Juga jika Anda ingin melihat informasi yang sama tetapi untuk direktori tertentu.

Misalnya: /etc/systemd/

tree -iLf 1 /etc/systemd/

Contoh keluaran :

[root@rhel-pc ~]# tree -iLf 1 /etc/systemd/
/etc/systemd
/etc/systemd/coredump.conf
/etc/systemd/journald.conf
/etc/systemd/logind.conf
/etc/systemd/resolved.conf
/etc/systemd/system
/etc/systemd/system.conf
/etc/systemd/user
/etc/systemd/user.conf

2 directories, 6 files
[root@rhel-pc ~]# 
  • Untuk melihat info direktori sebelumnya tetapi dengan kedalaman level 2
tree -iLf 2 /etc/systemd/

Contoh keluaran:

[root@rhel-pc ~]# tree -iLf 2 /etc/systemd/
/etc/systemd
/etc/systemd/coredump.conf
/etc/systemd/journald.conf
/etc/systemd/logind.conf
/etc/systemd/resolved.conf
/etc/systemd/system
/etc/systemd/system/basic.target.wants
/etc/systemd/system/bluetooth.target.wants
/etc/systemd/system/dbus-org.bluez.service -> /usr/lib/systemd/system/bluetooth.service
/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service -> /usr/lib/systemd/system/firewalld.service
/etc/systemd/system/dbus-org.freedesktop.Avahi.service -> /usr/lib/systemd/system/avahi-daemon.service
/etc/systemd/system/dbus-org.freedesktop.ModemManager1.service -> /usr/lib/systemd/system/ModemManager.service
/etc/systemd/system/dbus-org.freedesktop.nm-dispatcher.service -> /usr/lib/systemd/system/NetworkManager-dispatcher.service
/etc/systemd/system/dbus-org.freedesktop.timedate1.service -> /usr/lib/systemd/system/timedatex.service
/etc/systemd/system/default.target -> /usr/lib/systemd/system/graphical.target
/etc/systemd/system/default.target.wants
/etc/systemd/system/dev-virtio\x2dports-org.qemu.guest_agent.0.device.wants
/etc/systemd/system/display-manager.service -> /usr/lib/systemd/system/gdm.service
/etc/systemd/system/getty.target.wants
/etc/systemd/system/graphical.target.wants
/etc/systemd/system/local-fs.target.wants
/etc/systemd/system/multi-user.target.wants
/etc/systemd/system/network-online.target.wants
/etc/systemd/system/printer.target.wants
/etc/systemd/system/remote-fs.target.wants
/etc/systemd/system/snap.remmina.ssh-agent.service
/etc/systemd/system/sockets.target.wants
/etc/systemd/system/sysinit.target.wants
/etc/systemd/system/syslog.service -> /usr/lib/systemd/system/rsyslog.service
/etc/systemd/system/sysstat.service.wants
/etc/systemd/system/systemd-timedated.service -> /dev/null
/etc/systemd/system/timers.target.wants
/etc/systemd/system/var-lib-snapd-snap-bare-5.mount
/etc/systemd/system/var-lib-snapd-snap-core-11993.mount
/etc/systemd/system/var-lib-snapd-snap-core18-2284.mount
/etc/systemd/system/var-lib-snapd-snap-core20-1270.mount
/etc/systemd/system/var-lib-snapd-snap-discord-131.mount
/etc/systemd/system/var-lib-snapd-snap-gnome\x2d3\x2d28\x2d1804-161.mount
/etc/systemd/system/var-lib-snapd-snap-gnome\x2d3\x2d38\x2d2004-87.mount
/etc/systemd/system/var-lib-snapd-snap-gtk\x2dcommon\x2dthemes-1519.mount
/etc/systemd/system/var-lib-snapd-snap-remmina-5130.mount
/etc/systemd/system/var-lib-snapd-snap-snapd-14295.mount
/etc/systemd/system/var-lib-snapd-snap-spotify-56.mount
/etc/systemd/system/var-lib-snapd-snap-telegram\x2ddesktop-3544.mount
/etc/systemd/system/vmtoolsd.service.requires
/etc/systemd/system.conf
/etc/systemd/user
/etc/systemd/user/dbus-org.bluez.obex.service -> /usr/lib/systemd/user/obex.service
/etc/systemd/user/default.target.wants
/etc/systemd/user/sockets.target.wants
/etc/systemd/user.conf

20 directories, 30 files
[root@rhel-pc ~]# 

Seperti yang Anda lihat dari output di atas, setelah mendaftar semua file dan sub-direktori, pohon menunjukkan jumlah total direktori dan file dalam direktori yang Anda tentukan dan nilainya tidak akan sama ketika tingkat kedalaman berbeda.

Kesimpulan

Itu dia…..

Dalam artikel ini kami mengilustrasikan cara menghitung jumlah file dan sub-direktori dalam sebuah direktori.

alat terminal


Linux
  1. Cara Menghitung Jumlah File dan Subdirektori di dalam Direktori yang Diberikan

  2. Cara Menghitung Jumlah Baris dalam File di Linux (Contoh Perintah wc dan nl)

  3. Bagaimana cara menghitung jumlah file di setiap direktori?

  1. Cara Menemukan Jumlah File dalam Direktori dan Subdirektori

  2. Bagaimana Cara Mendapatkan Hitungan File Dalam Direktori Menggunakan Baris Perintah?

  3. Bagaimana cara membuat tautan simbolik ke semua file (kelas file) dalam direktori?

  1. Apa Cara Terbaik Untuk Menghitung Jumlah File Dalam Direktori?

  2. Bagaimana Menghitung Jumlah File Dalam Sebuah Direktori Dan Menghapus Yang Terlama Jika Jumlahnya Melebihi 5?

  3. Bagaimana cara menghitung jumlah baris file yang ditemukan?