I need to find size of a file abc.log which shows size as 1KB when I view it from WinSCP. These are my attempts so far -

  1. stat -c%s abc.log - output is 2 (giving size of file content which is 2 bytes)
  2. wc -c abc.log - output is 2
  3. ls -l abc.log - showing size as 2
  4. du -h abc.log - output is 4.0K (this means disk space occupied by abc.log, right?)
  5. du -b abc.log - output is 2
  6. du -k abc.log - output is 4

But what command would give me output as 1k or 1 at least as that is the size which is showing under the "Size" column in WinSCP? (On copying the file in Windows machine also it is showing 1KB)

I have tried find -name abc.log -size 1k and it gave me output as abc.log meaning that it has detected the size of abc.log as 1kB.

I am not understanding where 1k is appearing from because even commands like du are not showing 1k. But I need a command such that when I pass filename as input it would give me the file size exactly as shown in WinSCP and as detected by the find command.

  • 4
    So you want us to find a command that measures the size as incorrectly as WinSCP? Wouldn't it be better to find a setting in WinSCP that gives you an accurate size?
    – roaima
    Jun 18 at 18:44
  • 2
    find -name abc.log -size 1k doesn’t match files exactly 1k in size, because -size with a unit rounds up; so -size 1k matches files with sizes between 1 byte and 1024 bytes inclusive. Jun 18 at 18:48
  • winscp.net/tracker/1530 implements a requirement to round up to the next sized unit. Maybe find will indeed suffice
    – roaima
    Jun 18 at 18:50
  • Where does the value which appears in the Size column of the remote as viewed from WinSCP appear from and what is the linux command to get it? Does it show the size of the content present in the file or does it show the disk space usage? (it matches neither with the disk space usage nor with the file content size value). Even on copying the file to my Windows local it shows size as 1KB. Kindly let me know.
    – MVKXXX
    Jun 18 at 20:08
  • 1
    Use: echo $(( ( $( stat -c %s abc.log ) + 1023) / 1024 ))k. WinSCP just gives the size in 1k units rounded like this -- no connection to physical blocks. Jun 18 at 20:11


Your Answer

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

Browse other questions tagged or ask your own question.