开发者

Can this be printed on same line?

开发者 https://www.devze.com 2023-03-05 22:05 出处:网络
This command will count the number of files in the sub-directories. find . -maxdepth 1 -type d |while read dir;do echo \"$dir\";find \"$dir\" -type f|wc -l;done

This command will count the number of files in the sub-directories.

find . -maxdepth 1 -type d |while read dir;do echo "$dir";find "$dir" -type f|wc -l;done

Which looks like

./lib64
327
./bin
118

Would it be possible to ha开发者_高级运维ve it to look like

327 ./lib64
118 ./bin

instead?


There are a number of ways to do this... Here's something that doesn't change your code very much. (I've put it in multiple lines for readability.)

find . -maxdepth 1 -type d | while read dir; do
   echo `find "$dir" -type f | wc -l` "$dir"
done


pipe into tr to remove or replace newlines. I expect you want the newline to be turned into a tab character, like this:

find . -maxdepth 1 -type d |while read dir;do
   find "$dir" -type f|wc -l  | tr '\n' '\t';
   echo "$dir";
done

(Edit: I had them the wrong way around)


do echo -n "$dir "

The -n prevents echo from ending the line afterwards.

0

精彩评论

暂无评论...
验证码 换一张
取 消