3

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
GTS Joe
  • 199
  • 2
  • 10
  • 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 05:12

1 Answers1

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

Aaron
  • 2,859
  • 2
  • 12
  • 30
  • 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 05:23
  • 2
    `find /path/to/file -type f -size 33770c` One reference is [here](http://linux.die.net/man/1/find) – Aaron Feb 15 '16 at 05:39
  • This works perfectly. Thank you so much for the help! – GTS Joe Feb 15 '16 at 06:20