Hallo Leute, in diesem Artikel zeigen wir Ihnen, wie Sie die Anzahl der Dateien und Unterverzeichnisse in einem Verzeichnis mit einem Baumbefehl zählen können.
Zählen Sie die Anzahl der Dateien und Verzeichnisse mit dem Baumbefehl :
- Der Baum Der Befehl funktioniert auch dann, wenn keine Argumente angegeben werden, wie unten gezeigt:
tree -iLf 1

- „-i“ :ermöglicht dem Baum, Einrückungslinien auszudrucken.
- "-L" :gibt die Stufe an von Tiefe des anzuzeigenden Verzeichnisbaums, im obigen Fall 1 .
- "-f" :lässt den Baum den vollständigen Pfad-Präfix für jede Datei ausgeben.
- Wenn Sie dieselben Informationen ohne Argumente für die Tiefenebene 2 anzeigen möchten:
tree -iLf 2

- Auch wenn Sie dieselben Informationen anzeigen möchten, jedoch für ein bestimmtes Verzeichnis.
Zum Beispiel: /etc/systemd/
tree -iLf 1 /etc/systemd/
Beispielausgabe :
[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 ~]#

- Zum Anzeigen der Informationen für das vorherige Verzeichnis, jedoch mit Tiefenstufe 2
tree -iLf 2 /etc/systemd/
Beispielausgabe:
[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 ~]#
Wie Sie der obigen Ausgabe entnehmen können, wird nach dem Auflisten aller Dateien und Unterverzeichnisse Baum angezeigt zeigt Ihnen die Gesamtzahl der Verzeichnisse und Dateien in dem von Ihnen angegebenen Verzeichnis, und die Werte sind nicht gleich, wenn die Tiefe unterschiedlich ist.
Schlussfolgerung
Das ist es …..
In diesem Artikel haben wir gezeigt, wie man die Anzahl der Dateien und Unterverzeichnisse in einem Verzeichnis zählt.
Terminal-Tools