3
# cat /proc/version
Linux version 2.6.18-308.8.2.el5.028stab101.1 (root@rhel5-build-x64) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-46)) #1 SMP Sun Jun 24 20:25:35 MSD 2012
# ls -l /proc/version
-r--r--r-- 1 root root 0 Aug 22 10:07 /proc/version

The file size is reported as 0, but it has contents. How does this work?

Is it because /proc is some kind of virtual file system?

Which command could show the exact size of files in /proc?

  • this question is not suitable to be there, it's not a shopping or buying recommendation one:( – hugemeow Aug 22 '12 at 2:38
  • 1
    but it's a linux related question, you know linux is a bit different from others, like windows, there are lots of topics in linux, but has nothing to do with digital equipment and shopping recommendation, also it have nothing to do with mobile phones, so it will be a fault to move this topic to superuser – hugemeow Aug 22 '12 at 2:46
  • 1
    For the last time! It's not a programming question. Superuser is for operating system questions, not just for shopping o0r mp3 questions. If you really insist, I can downvote this for being a poor programming question as well as vote to close it as off-topic. I think you misunderstand - users decide what's on-topic here and what isn't, and I've cast my vote as it not being appropriate. You're not going to convince me otherwise, so you may as well stop trying to do so. IMO, it's off-topic here. You obviously don't agree, since you posted it here in the first place. Discussion over. :-) – Ken White Aug 22 '12 at 3:04
  • 1
    Ken, procfs is a core part of the Linux ABI, and understanding how it works is an important part of linux programming. The question is simple, but not an inappropriate one to be asked by a beginning programmer. This absurdist flame war, on the other hand, is a disgrace and you should be ashamed of yourself. – Andy Ross Aug 22 '12 at 4:02
  • 1
    @AndyRoss: You are the one seeing a flame war. I see someone (rightly, no doubt about it) pointing out that the question is off-topic for Stack Overflow, and on-topic for Super User. hugemeow seems to have misunderstood what Super User is, and is technically at fault here, which is certainly OK for new users, but he/she should be modest enough to realize this as well when seeking help. – Daniel Andersson Aug 22 '12 at 10:08
8

It's because you're in the proc filesystem. See more info on what procfs is.

/proc/version, containing the Linux kernel version, distribution number, gcc version number (used to build the kernel) and any other pertinent information relating to the version of the kernel currently running

Those aren't real files. It's a convenient way to show process information as a file hierachy.


EDIT:

i know it's unreal, but what i should do if i want to know its size?

You're not getting it from ls, but you can try using wc:

# wc -c /proc/version
138 /proc/version
  • i know it's unreal, but what i should do if i want to know its size? – hugemeow Aug 22 '12 at 2:19
  • @hugemeow I've edited my answer – Jon Lin Aug 22 '12 at 2:21
  • i want a list which can tell me the size of files, not just a single one:( – hugemeow Aug 22 '12 at 2:34
  • @hugemeow then use find: find /proc/ -maxdepth 1 -type f -exec wc -c {} + – Jon Lin Aug 22 '12 at 2:39
  • 3
    @hugemeow write a script and call it a, that's real short. – Jon Lin Aug 22 '12 at 3:15

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.