변수의 파일 크기를 가져 오시겠습니까? 그렇게하는 방법?linux 쉘 파일 크기
ls -l | grep testing.txt | cut -f6 -d' '
셸 변수에 크기를 저장하는 방법은 무엇입니까?
변수의 파일 크기를 가져 오시겠습니까? 그렇게하는 방법?linux 쉘 파일 크기
ls -l | grep testing.txt | cut -f6 -d' '
셸 변수에 크기를 저장하는 방법은 무엇입니까?
size=`ls -l | grep testing.txt | cut -f6 -d' '`
크기가 공백으로 구분 된 경우 필드 6에있을 것이라는 보장은 없습니다. –
'ls'을'grep'으로 파이핑하면 디렉토리의 * 모든 * 파일이 나열되고 이름이 정렬되므로 (수천 개의 파일이있는 디렉토리에서 상당한 시간이 걸릴 수 있기 때문에) 또한 비효율적이기 때문에 또한 비효율적입니다. 'grep testing.txt'는'not_testingatxt_file'과 같은 이름의 파일을 반환합니다 (regex에서 match-any-character를 의미하는'.'). –
당신은
$ var=$(ls -s1 testing.txt|awk '{print $1}')
(-s의 의미에 대한 man 페이지를 확인) 아니면 -c '%s'
와 stat
를 사용하거나 사용할 수 ls
으로이 방법을 수행 할 수 있습니다 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)
a=\`stat -c '%s' testing.txt\`;
echo $a
배쉬 나는 추정하나요? – ziya
예. bash 쉘입니다. 감사합니다. –
[파일 크기를 확인하는 방법?] (http://stackoverflow.com/questions/5920333/how-to-check-size-of-a-file) –