About Bookmarks Contact Library Map Photos Search Talks
June
9
2005
9:50 am
Tags:
Post Meta :

Today I learned a new command: stat. I never fail to enjoy learning a new unix command. Even after 10 years of being a I still find useful commands that I have never used.

The stat command is similar to the ls command in that they both give you information about files and filesystems. However, stat is more useful in automated scripts. For example if you wanted to get just the filesize of a file with ls you would have to do this:


ls -la myfile | tr -s '[:space:]‘ | cut -s -d ‘ ‘ -f 5

But “tr” and “cut” behave differently on different systems so this will not always work. On the other hand GNU stat is simpler and works well across systems:


stat -c '%s' "users1.txt"

Comments
Participate! Leave your comment.