简体   繁体   English

如何在Unix和Linux中通过单个命令传递多个命令

[英]How to pipe multiple commands in a single command in Unix and Linux

I want the o/p as list of owner and their file names , file path and the file size. 我希望将o / p作为所有者及其文件名,文件路径和文件大小的列表。 I am using two commands to get the o/p. 我正在使用两个命令来获取o / p。 Can anyone suggest me how to get the o/p in a single command .The commands I am using are: 任何人都可以建议我如何在单个命令中获取o / p。我使用的命令是:

ls -l | awk '{print $3, $4 }' > test.txt 

This gives me the list of owner and the directory. 这给了我所有者列表和目录。

And the 2nd one is: 第二个是:

find . -size +100k -print0 | xargs -0 ls -sd >tets2.txt

This gives me the file name and size of the file . 这给了我文件名和文件大小。

Sort of don't understand, do you mean pipe them both or do each commmand in same line. 有点不明白,是指将它们都用管道传输还是将每个命令都放在同一行中。 To do the later, you can do 要稍后,您可以

ls -l | awk '{print $3, $4 }' > test.txt    ;   find . -size +100k -print0 | xargs -0 ls -sd >tets2.txt

The first command returns the owner and group, not the file name. 第一个命令返回所有者和组,而不是文件名。 It only works for the current directory. 它仅适用于当前目录。 The second command works for subdirectories also, but only for huge files. 第二个命令也适用于子目录,但仅适用于大文件。 Two unrelated commands are hard to glue together, but if your goal is to prevent calling stat two times for a file, you can modify the following Perl script to suit your needs: 两个不相关的命令很难融合在一起,但是如果您的目标是防止两次为文件调用stat ,则可以修改以下Perl脚本以适合您的需要:

use feature 'say';
while (my $file = glob '*') {
    my @stats = (stat $file)[4,5,7];
    say join "\t", $file,
                   (getpwuid $stats[0])[0],
                   (getgrgid $stats[1])[0],
                   $stats[2];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM