2010-10-28 23:09:03 +0000 2010-10-28 23:09:03 +0000
241
241
Advertisement

Jak mogę znaleźć pliki większe/mniejsze niż x bajtów?

Advertisement

W terminalu, jak mogę znaleźć pliki większe lub mniejsze niż x bajtów?

Przypuszczam, że mogę zrobić coś takiego jak

find . -exec ls -l {} \;

, a następnie przesłać wynik do awk aby filtrować według rozmiaru pliku. Ale czy nie powinno być prostszego sposobu?

Advertisement
Advertisement

Odpowiedzi (4)

386
386
386
2010-10-28 23:37:50 +0000

Use:

find . -type f -size +4096c

to find files larger than 4096 bytes.

And :

find . -type f -size -4096c

to find files smaller than 4096 bytes.

Zwróć uwagę na + i - różnicę po przełączniku rozmiaru.

Przełącznik -size wyjaśnił:

-size n[cwbkMG]

    File uses n units of space. The following suffixes can be used:

    `b' for 512-byte blocks (this is the default if no suffix is
                                used)

    `c' for bytes

    `w' for two-byte words

    `k' for Kilobytes (units of 1024 bytes)

    `M' for Megabytes (units of 1048576 bytes)

    `G' for Gigabytes (units of 1073741824 bytes)

    The size does not count indirect blocks, but it does count
    blocks in sparse files that are not actually allocated. Bear in
    mind that the `%k' and `%b' format specifiers of -printf handle
    sparse files differently. The `b' suffix always denotes
    512-byte blocks and never 1 Kilobyte blocks, which is different
    to the behaviour of -ls.
8
8
8
2015-10-25 22:03:31 +0000

Myślę, że find może być użyteczny sam w sobie bez orurowania do AWK. Na przykład,

find ~ -type f -size +2k -exec ls -sh {} \;

Tylda wskazuje, gdzie chcesz rozpocząć wyszukiwanie, a wynik powinien wyświetlać tylko pliki większe niż 2 kilobajty.

Aby uzyskać więcej informacji, możesz użyć opcji -exec, aby wykonać inną komendę, która wyświetli listę tych katalogów z ich rozmiarami.

Aby uzyskać więcej informacji, przeczytaj stronę man page for find .

5
Advertisement
5
5
2010-10-29 00:01:20 +0000
Advertisement

AWK naprawdę jest dość łatwe do tego typu rzeczy. Oto kilka rzeczy, które możesz z nim zrobić w odniesieniu do sprawdzania wielkości plików, jak zapytałeś:

List files more than 200 bytes:

ls -l | awk '{if ($5 > 200) print $8}'

List files less than 200 bytes and write the list to a file:

ls -l | awk '{if ($5 < 200) print $8}' | tee -a filelog

List files of 0 bytes, record the list to a file and delete the empty files:

ls -l | awk '{if ($5 == 0) print $8}' | tee -a deletelog | xargs rm
3
3
3
2010-10-28 23:27:11 +0000

Większa niż 2000 bajtów:

du -a . | awk '$1*512 > 2000 {print $2}'

Mniej niż 2000 bajtów:

du -a . | awk '$1*512 < 2000 {print $2} '
Advertisement

Pytania pokrewne

10
37
7
14
9
Advertisement
Advertisement