문제

I just wrote a bash script to print the size and the name of all the files in a directory. It's quite simple:

du -h *

It prints first the size of the file and then the name. But now I wonder how can I reverse the order of the output: print first the name and then the size of the file.

Any ideas?

도움이 되었습니까?

해결책

du -h * | awk -v FS='\t' '{ print $2, $1 }'

It works by taking the output from du and sending it to an inline awk script, which reads as follows: for every line given to awk in input, print the 2nd and then 1st column.

다른 팁

Here is a Perl based solution:

du -h *|perl -pe'/\s(.+)/&&{$_="$1\t$`\n"}'

It works properly for both spaces and tabs inside of file names.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top