Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[bash] contare i file [risolto]
View unanswered posts
View posts from last 24 hours
View posts from last 7 days

 
Reply to topic    Gentoo Forums Forum Index Forum italiano (Italian) Forum di discussione italiano
View previous topic :: View next topic  
Author Message
cloc3
Advocate
Advocate


Joined: 13 Jan 2004
Posts: 4792
Location: http://www.gentoo-users.org/user/cloc3/

PostPosted: Fri Dec 08, 2006 9:01 pm    Post subject: [bash] contare i file [risolto] Reply with quote

Vorrei conoscere il numero di file contenuti in una partizione.

Esiste un modo di farlo?
_________________
vu vu vu
gentù
mi piaci tu


Last edited by cloc3 on Sat Dec 09, 2006 8:03 pm; edited 1 time in total
Back to top
View user's profile Send private message
crisandbea
Veteran
Veteran


Joined: 03 Jul 2005
Posts: 1778
Location: BOSCO (SA) ... ma domiciliato a Bologna....

PostPosted: Fri Dec 08, 2006 9:12 pm    Post subject: Re: [bash] contare i file. Reply with quote

cloc3 wrote:
Vorrei conoscere il numero di file contenuti in una partizione.

Esiste un modo di farlo?


dovresti crearti uno script, che ti fa ciò. io ne avevo fatto uno simile, se lo trovo lo posto.

ciauz
Back to top
View user's profile Send private message
cloc3
Advocate
Advocate


Joined: 13 Jan 2004
Posts: 4792
Location: http://www.gentoo-users.org/user/cloc3/

PostPosted: Fri Dec 08, 2006 9:19 pm    Post subject: Re: [bash] contare i file. Reply with quote

crisandbea wrote:
cloc3 wrote:
Vorrei conoscere il numero di file contenuti in una partizione.

Esiste un modo di farlo?


dovresti crearti uno script, che ti fa ciò. io ne avevo fatto uno simile, se lo trovo lo posto.

ciauz

grazie. ma temo che sarebbe una cosa mostruosa.
Non tanto per scriverlo, ma per farlo girare.

Speravo che esistesse un qualche strumento o una qualche file di /proc capace di conservare questa informazione.
_________________
vu vu vu
gentù
mi piaci tu
Back to top
View user's profile Send private message
Luca89
Advocate
Advocate


Joined: 27 Apr 2005
Posts: 2107
Location: Agrigento (Italy)

PostPosted: Fri Dec 08, 2006 9:24 pm    Post subject: Re: [bash] contare i file. Reply with quote

cloc3 wrote:
Speravo che esistesse un qualche strumento o una qualche file di /proc capace di conservare questa informazione.


Il numero di inode occupati ("df -i") potrebbe essere abbastanza realistico come dato.
_________________
Running Fast!
Back to top
View user's profile Send private message
cloc3
Advocate
Advocate


Joined: 13 Jan 2004
Posts: 4792
Location: http://www.gentoo-users.org/user/cloc3/

PostPosted: Fri Dec 08, 2006 9:39 pm    Post subject: Re: [bash] contare i file. Reply with quote

Luca89 wrote:

Il numero di inode occupati ("df -i") potrebbe essere abbastanza realistico come dato.

Non capisco bene il significato dell'output.
Provo una mia interpretazione:
Code:

s939 ~ # df -hi
Filesystem             Inode   IUsati  ILib. IUso% Montato su
/dev/mapper/raid5-root64
                        1,2M     65K    1,1M    6% /

Significa che la partizione contiene 1,2 milioni di inode, ma solo il 6% di essi (cioè 65 mila) è occupato.

Leggo bene?
_________________
vu vu vu
gentù
mi piaci tu
Back to top
View user's profile Send private message
Luca89
Advocate
Advocate


Joined: 27 Apr 2005
Posts: 2107
Location: Agrigento (Italy)

PostPosted: Fri Dec 08, 2006 10:26 pm    Post subject: Re: [bash] contare i file. Reply with quote

-h non mi pare adatto per gli inode, visto che considera i multipli di 1024 per contare, meglio che usi -H (considera i multipli di 1000) oppure niente, così ti da il numero esatto di inode usati.
_________________
Running Fast!
Back to top
View user's profile Send private message
syntaxerrormmm
Guru
Guru


Joined: 17 Apr 2005
Posts: 449
Location: Romano di Lombardia - BG - ITALY

PostPosted: Fri Dec 08, 2006 10:52 pm    Post subject: Reply with quote

Solo files o anche cartelle? Se vanno bene anche le cartelle (e il link simbolici), un grezzissimo
Code:
ls -1R /mnt/dir | wc -l
dovrebbe darti il risultato voluto.

Altrimenti, solo files...
Code:
find /mnt/dir -type f | wc -l


Ciao.
_________________
"Every rule can be broken, but no rule may be ignored."

Last.fm - Gentoo 2006.1 on:
Acer Aspire 1355LC - suspend2-sources-2.6.18-r3
IBM Thinkpad T30 - suspend2-sources-2.6.19-r3
Back to top
View user's profile Send private message
cloc3
Advocate
Advocate


Joined: 13 Jan 2004
Posts: 4792
Location: http://www.gentoo-users.org/user/cloc3/

PostPosted: Sat Dec 09, 2006 8:25 am    Post subject: Reply with quote

Quote:

s939 mnt # mount /dev/mapper/raid5-usr32 raid5-usr
s939 mnt # df -i raid5-usr
Filesystem Inode IUsati ILib. IUso% Montato su
/dev/mapper/raid5-usr32
20971520 313222 20658298 2% /mnt/raid5-usr
s939 mnt # time ls -1R raid5-usr/ | wc -l
341933

real 0m2.293s
user 0m1.000s
sys 0m1.276s

ero convinto che il numero di inode dovesse essere maggiore di quello dei file, in quanto pensavo che un file grosso potesse frammentato in più parti.
invece no. perché?
_________________
vu vu vu
gentù
mi piaci tu
Back to top
View user's profile Send private message
lucapost
Veteran
Veteran


Joined: 24 Nov 2005
Posts: 1419
Location: <ud|me|ts> - Italy

PostPosted: Sat Dec 09, 2006 11:04 am    Post subject: Reply with quote

Molto sporca, ma una volta ho fatto così:
Code:
du / >> allfiles.txt

Lo apri con vi, e ti guardi quante righe ha.
_________________
LP
Back to top
View user's profile Send private message
cloc3
Advocate
Advocate


Joined: 13 Jan 2004
Posts: 4792
Location: http://www.gentoo-users.org/user/cloc3/

PostPosted: Sat Dec 09, 2006 1:57 pm    Post subject: Reply with quote

Code:

s939 mnt # time du -a raid5-usr/|wc -l
313220

real    0m2.724s
user    0m0.648s
sys     0m2.056s
s939 mnt # time ls -1Ra raid5-usr/|wc -l
390396

real    0m2.512s
user    0m1.116s
sys     0m1.376s
s939 mnt # df -i raid5-usr/
Filesystem             Inode   IUsati  ILib. IUso% Montato su
/dev/mapper/raid5-usr32
                     20971520  313222 20658298    2% /mnt/raid5-usr

Ho aggiunto ad ls l'opzione -a per non perdere i file nascosti e il risultato è peggiorato ancora.
Evidentemente cicla sui link, producendo dei doppi conteggi.

`du -a` e `df -i` danno lo stesso risultato. Almeno in questo caso, dunque, esiste identità tra file e nodi.
_________________
vu vu vu
gentù
mi piaci tu
Back to top
View user's profile Send private message
fikiz
Apprentice
Apprentice


Joined: 07 Mar 2005
Posts: 282
Location: Italy

PostPosted: Sat Dec 09, 2006 4:04 pm    Post subject: Reply with quote

io faccio:
Code:
$ find /directory -type f | wc -l


che conta i file escludendo le directory.

ciao
Back to top
View user's profile Send private message
cloc3
Advocate
Advocate


Joined: 13 Jan 2004
Posts: 4792
Location: http://www.gentoo-users.org/user/cloc3/

PostPosted: Sat Dec 09, 2006 5:21 pm    Post subject: Reply with quote

fikiz wrote:
io faccio:
Code:
$ find /directory -type f | wc -l


come sintaxerrormmm.
Code:

s939 mnt # time find raid5-usr|wc -l
313254

real    0m0.962s
user    0m0.308s
sys     0m0.656s
s939 mnt # time du -a raid5-usr|wc -l
313220

real    0m2.576s
user    0m0.600s
sys     0m1.976s
s939 mnt # time df -i raid5-usr|wc -l
3

real    0m0.004s
user    0m0.000s
sys     0m0.004s

Per i me le cartelle sono file anch'esse.
find è più veloce che du, ma restituisce un valore diverso e maggiore. Ho verificato che non dipende da eventuali cicli sui link.
Cosa conteggerà in più?
_________________
vu vu vu
gentù
mi piaci tu
Back to top
View user's profile Send private message
syntaxerrormmm
Guru
Guru


Joined: 17 Apr 2005
Posts: 449
Location: Romano di Lombardia - BG - ITALY

PostPosted: Sat Dec 09, 2006 6:20 pm    Post subject: Reply with quote

man find wrote:
-type c
File is of type c:

b block (buffered) special

c character (unbuffered) special

d directory

p named pipe (FIFO)

f regular file

l symbolic link; this is never true if the -L option or the
-follow option is in effect, unless the symbolic link is
broken. If you want to search for symbolic links when -L is
in effect, use -xtype.

s socket

D door (Solaris)
Credo che di default assuma tutti questi...

Ciao.
_________________
"Every rule can be broken, but no rule may be ignored."

Last.fm - Gentoo 2006.1 on:
Acer Aspire 1355LC - suspend2-sources-2.6.18-r3
IBM Thinkpad T30 - suspend2-sources-2.6.19-r3
Back to top
View user's profile Send private message
cloc3
Advocate
Advocate


Joined: 13 Jan 2004
Posts: 4792
Location: http://www.gentoo-users.org/user/cloc3/

PostPosted: Sat Dec 09, 2006 8:03 pm    Post subject: Reply with quote

trovato:
Code:

s939 mnt # time find raid5-usr/|wc -l
313254

real    0m0.951s
user    0m0.300s
sys     0m0.648s
s939 mnt # time du -al raid5-usr/|wc -l
313254

real    0m2.572s
user    0m0.608s
sys     0m1.964s

Per ottenere risultati identici, du vuole anche l'opzione -l:
man du wrote:

-l, --count-links
Count the size of all files, even if they have appeared already (as a hard link).

In pratica, la differenza la fanno gli hard link, come in questo esempio:
Code:

cloc3@wlan1 ~/Desktop $ find .|wc -l
16
cloc3@wlan1 ~/Desktop $ du -al .|wc -l
16
cloc3@wlan1 ~/Desktop $ touch pippo
cloc3@wlan1 ~/Desktop $ ln pippo peppo
cloc3@wlan1 ~/Desktop $ find .|wc -l
18
cloc3@wlan1 ~/Desktop $ du -a .|wc -l
17
cloc3@wlan1 ~/Desktop $ du -al .|wc -l
18

Resta un dubbio amletico. Nella mia definizione, gli hard link sono da contarsi come file oppure no :?:

:roll: :roll:

Bu. quasi quasi metto risolto lo stesso.
:lol:
_________________
vu vu vu
gentù
mi piaci tu
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Forum italiano (Italian) Forum di discussione italiano All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum