取得檔案大小
如果要獲得檔案byte數的檔案名稱儲存在參數1裏面
方法1:
ls -l $1 | awk '{print $5}'
方法2:
du -b $1 | awk '{print $1}'
方法3:
stat -c "%s" $1
方法4:
wc -c $1| awk '{print $1}'
應用取得檔案大小產生git用的sha1雜湊值
#!/bin/bash
for var in "$@"
do
if [ -f "$var" ]; then
echo -en "$var" "\t"
wc -c "$var"| awk '{printf "blob " $1 "\0"}' | cat - "$var" | sha1sum - | awk '{print $1}'
else
echo "$var is not file"
fi
done
方法1:
ls -l $1 | awk '{print $5}'
方法2:
du -b $1 | awk '{print $1}'
方法3:
stat -c "%s" $1
方法4:
wc -c $1| awk '{print $1}'
應用取得檔案大小產生git用的sha1雜湊值
#!/bin/bash
for var in "$@"
do
if [ -f "$var" ]; then
echo -en "$var" "\t"
wc -c "$var"| awk '{printf "blob " $1 "\0"}' | cat - "$var" | sha1sum - | awk '{print $1}'
else
echo "$var is not file"
fi
done
留言