1

In the Linux command line, how can I find all files exactly 158 kB in size? I was using the following command but it didn't work:

find /var/www/ -xdev -type f -size 158k
  • 1
    Are you sure the file you are seeking is exactly 158kB? That command line should work. I tested it with: dd if=/dev/zero bs=1 count=161792 of=/tmp/test1; dd if=/dev/zero bs=1 count=161793 of=/tmp/test2; find /tmp/ -size 158k. It found the file /tmp/test1, but not /tmp/test1. (161792=158kB) – Johnny Feb 15 '16 at 5:12
3

Find files of exact size

[me@localhost ~]$ dd if=/dev/zero bs=1024 count=158 of=/dev/shm/158k.txt
158+0 records in
158+0 records out
161792 bytes (162 kB) copied, 0.00120192 s, 135 MB/s

[me@localhost ~]$ find /dev/shm -type f -size 158k
/dev/shm/158k.txt

Your file that was not found is not likely 158 KB. To validate its size, use /bin/ls -al /path/to/file and stat /path/to/file

  • ok I used stat /path/to/file/filename.php and it returned "Size: 33770." It doesn't state the unit, though. How would I find a file exactly 33770 in size? – GTS Joe Feb 15 '16 at 5:23
  • 1
    find /path/to/file -type f -size 33770c One reference is here – Aaron Feb 15 '16 at 5:39
  • This works perfectly. Thank you so much for the help! – GTS Joe Feb 15 '16 at 6:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.