문제

I need to make a shell command that lists all file names and their sizes in a directory. I wrote this:

ls -l | awk ' {print $9, $5} '

the problem is that with $9 it only prints the first word of the name of the file. Any tips to make it print the whole name?

도움이 되었습니까?

해결책

Instead of parsing ls, use find:

find . -type f -printf "%s\t%f\n"

The %f directive prints the filename with leading directories removed. %s produces the file size in bytes.

For restricting the listing to the current directory, use -maxdepth:

find . -maxdepth 1 -type f -printf "%s\t%f\n"

You could also use stat:

stat --printf "%s\t%n\n" *
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top