GNU/Linux >> Linux Esercitazione >  >> Linux

Come contare il numero di file e sottodirectory all'interno di una directory

Ciao ragazzi, in questo articolo vi mostreremo come contare il numero di file e sottodirectory in una directory usando un comando tree.

Conta il numero di file e directory con il comando tree :

  • L'albero il comando funzionerà anche se non vengono forniti argomenti come mostrato di seguito:
tree -iLf 1
  1. “-i” :consente all'albero di stampare linee di rientro.
  2. “-L” :specifica il livello di profondità dell'albero delle directory da visualizzare, che nel caso precedente è 1 .
  3. “-f” :fa stampare ad albero il prefisso del percorso completo per ogni file.
  • Se vuoi visualizzare le stesse informazioni senza argomenti per il livello di profondità 2:
tree -iLf 2
  • Anche se vuoi visualizzare le stesse informazioni ma per una directory specificata.

Ad esempio: /etc/systemd/

tree -iLf 1 /etc/systemd/

Risultato di esempio :

[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 ~]# 
  • Per visualizzare le informazioni per la directory precedente ma con livello di profondità 2
tree -iLf 2 /etc/systemd/

Risultato di esempio:

[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 ~]# 

Come puoi vedere dall'output sopra, dopo aver elencato tutti i file e le sottodirectory, albero mostra il numero totale di directory e file nella directory specificata e i valori non saranno gli stessi quando il livello di profondità è diverso.

Conclusione

Questo è tutto…..

In questo articolo abbiamo illustrato come contare il numero di file e sottodirectory in una directory.

strumenti terminali


Linux
  1. Come contare il numero di file e sottodirectory all'interno di una determinata directory

  2. Come trovare il numero di file in una directory e sottodirectory

  3. Come ottenere un conteggio di file in una directory utilizzando la riga di comando?

  4. Qual è il modo migliore per contare il numero di file in una directory?

  5. Come contare il numero di file in ogni directory?

Come contare i file nella directory in Linux

Come contare i file nella directory su Linux

Conta il numero di file in una directory in Linux

Come contare il numero di file in una directory in Linux

Linux:trova il numero di file in una directory e sottodirectory

Come controllare la dimensione di file e directory su Linux