linux的shell文件大小

我想获得文件的大小variables? 怎么做?

ls -l | grep testing.txt | cut -f6 -d' ' 

给的大小,但如何将其存储在shellvariables?

 filesize=$(stat -c '%s' testing.txt) 

你可以用ls这样做(检查-s的含义)

 $ var=$(ls -s1 testing.txt|awk '{print $1}') 

或者你可以使用stat-c '%s'

或者你可以使用find(GNU)

 $ var=$(find testing.txt -printf "%s") 
 size() { file="$1" if [ -b "$file" ]; then /sbin/blockdev --getsize64 "$file" else wc -c < "$file" # Handles pseudo files like /proc/cpuinfo # stat --format %s "$file" # find "$file" -printf '%s\n' # du -b "$file" | cut -f1 fi } fs=$(size testing.txt) 
 size=`ls -l | grep testing.txt | cut -f6 -d' '` 
  a=\`stat -c '%s' testing.txt\`; echo $a