How to find out the size of a file?
How to find out the size of a file?
Hi.
Title and description says it all.
Any hints?
Thanks
Title and description says it all.
Any hints?
Thanks
Fred has a script in Debian Dog that does it as a right click action. Should be in there someplace. it is /usr/local/bin/howbig
Code: Select all
#!/bin/bash
FILES="$@"
printf '%s\n' "$@" > /tmp/howbig
BASENAMES=$(while read f; do echo "$(basename "$f")"; done <<< "$(cat /tmp/howbig)")
DIRNAME="$(dirname "$(cat /tmp/howbig | head -1)")"
IFS=$'\n'
cd "$DIRNAME"
du -chs --apparent-size $BASENAMES | sort -h | yad --title="How Big?" --width=400 --height=400 --text-info --tail --center
rm -f /tmp/howbig
exit 0
Thanks.
I'm using:
to get the size of a single file, instead of all files in a directory.
I'm using:
Code: Select all
FSIZE1=`du -c -h --apparent-size "$PRJ"`
FSIZE=`echo $FSIZE1 | cut -d " " -f1`
- MochiMoppel
- Posts: 2084
- Joined: Wed 26 Jan 2011, 09:06
- Location: Japan
TryITSMERSH wrote:Thanks.
I'm using:to get the size of a single file, instead of all files in a directory.Code: Select all
FSIZE1=`du -c -h --apparent-size "$PRJ"` FSIZE=`echo $FSIZE1 | cut -d " " -f1`
Code: Select all
FSIZE=$(du -h --apparent-size "$PRJ" | cut -f1)
Slightly faster:
Code: Select all
FSIZE=$(stat -c %s "$PRJ")
Code: Select all
ls -al file.name | cut -d " " -f 5
@MochiMoppel, jafadmin,
thanks for the replies.
and wondered why it didn't cut everything after the first space.
Didn't know it is separated by tabs...
thanks for the replies.
I was trying and trying and tryingMochiMoppel wrote:TryITSMERSH wrote:Thanks.
I'm using:to get the size of a single file, instead of all files in a directory.Code: Select all
FSIZE1=`du -c -h --apparent-size "$PRJ"` FSIZE=`echo $FSIZE1 | cut -d " " -f1`
Note that du separates fields by Tab, not by Space. Your code works only because you echo an unquoted $FSIZE1. In this case echo changes Tabs to Spaces.Code: Select all
FSIZE=$(du -h --apparent-size "$PRJ" | cut -f1)
Slightly faster:Code: Select all
FSIZE=$(stat -c %s "$PRJ")
Code: Select all
FSIZE="`du -c -h --apparent-size "$PRJ" | cut -d " " -f1`"
Didn't know it is separated by tabs...
Hi.
With the help of awk:
Size at beginning followed by file name:or
size at end, file name at beginning:
Bye.
With the help of awk:
Size at beginning followed by file name:
Code: Select all
ls -Algo | awk '{ print $3"\t"$NF }'
size at end, file name at beginning:
Code: Select all
ls -Algo | awk '{ print $NF"\t"$3 }'
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)
Hello *RSH and all.
You can see file sizes directly in a ROX-Filer window.
Simply change the ROX-Filer's Options, like so:
Other file managers have similar settings that you can set or unset:
mc, wcm, muCommander, xfe, etc.
IHTH.
You can see file sizes directly in a ROX-Filer window.
Simply change the ROX-Filer's Options, like so:
- -- Open a ROX-Filer window (it does not matter which directory)
-- Right-click on en empty part of background. Then click on Options in
the middle of that menu: ROX's Options panel opens.
-- Click "Display", 2nd from top.
-- Go to 2nd sub-title there, named "Icons".
-- Now in the left colum, 2nd line, where is says "Details by Default",
there is a list menu: click on "Sizes" there, and then "Save". The next
time that you open ROX-Filer, it will display the size in bytes (if the file
is small) or Kb's of files next to the name of the files. Only of files, not
of directories, though.
Other file managers have similar settings that you can set or unset:
mc, wcm, muCommander, xfe, etc.
IHTH.
- Attachments
-
- Result-sizes_setting.jpg
- (97.23 KiB) Downloaded 194 times
-
- ROX-Filer-sizes_setting.jpg
- (106.47 KiB) Downloaded 192 times
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)
Yes, I know this. Thanks.You can see file sizes directly in a ROX-Filer window.
Though as mentioned in my opening post I wanted to do this in a shell script, as I need that information to display the file size along with file name and date of last edition of the file in the status bar or in a disabled entry field of a gtkdialog program I'm working on.
ITSMERSH,
I think "stat" will give you everything you need.
Cheers,
s
I think "stat" will give you everything you need.
Code: Select all
FN="/root/.bashrc"
bytes_and_last_change="$(stat --printf="%s ""%z" "$FN" | cut -d " " -f1,2)"
echo "$FN ""$bytes_and_last_change"
/root/.bashrc 1245 2017-02-10
s
Thanks seaside.
I didn't know one could do that!
Just having fun:More general:
BFN.
I didn't know one could do that!
Just having fun:
Code: Select all
Info="`stat -c "%n, %s b, %z" .bashrc`";echo "${Info:0:33}"
Code: Select all
Info="`stat -c "%n, %s b, %z" filename`";echo "${Info:0: -16}"
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)