Bash script that returns the size of a file
how can I make a script that echoes the size of a file in human-readable format?
the file is $1 (the first parameter) Thank you! |
You want either the ls or wc command.
"wc filename" will tell you the number of lines, words, and characters. If you only want one of these attributes you can use "wc -l", "wc -w", or "wc -c". "ls -l filename" will tell you the number of characters, along with other stuff. |
yes wc -b filename returns me the size in bytes and the name of the file.
but for a dir? how can i get the size (include all its subfolders) ? |
Use 'du' if you want to know the size of a directory.
-twantrd |
use the following command.
du -sh |
Quote:
No script needed, it's already a built in command.. and if you just wanted to make it so there's no options to be passed, create an alias for 'du -sh' so it would be: $ aliasname <directory> |
solved that! thank you!
how can i print the first parameter using a variable. fo example i have x=1 and i want to print $1, x=2 -> $2 etc! |
All times are GMT -5. The time now is 05:43 PM. |