如何在linux中组合两个命令?

时间:2022-10-31 03:38:31

I would like to know how to combine two commands. For example if I need to return the number of lines and number of words, how can I use a single command to get the data?

我想知道如何组合两个命令。例如,如果我需要返回行数和字数,我如何使用单个命令来获取数据?

When I do I am using two commands separately. Here is the way how I have used.

当我这样做时,我分别使用两个命令。这是我使用的方式。

wc -l filename (this is to get the number of lines)
wc -w filename (this is to get the number of words)

wc -l filename(这是获取行数)wc -w filename(这是获取单词数)

Is there any way to get both using a single command?

有没有办法让两个使用单个命令?

Thanks in advance

提前致谢

1 个解决方案

#1


1  

Try this:

尝试这个:

wc -l -w filename

It uses both flags and returns both numbers.

它使用两个标志并返回两个数字。

Example input:

示例输入:

wc -l -w /home/administrator/Desktop/myFile.txt

Example output:

输出示例:

9 13 /home/administrator/Desktop/myFile.txt

#1


1  

Try this:

尝试这个:

wc -l -w filename

It uses both flags and returns both numbers.

它使用两个标志并返回两个数字。

Example input:

示例输入:

wc -l -w /home/administrator/Desktop/myFile.txt

Example output:

输出示例:

9 13 /home/administrator/Desktop/myFile.txt