简体   繁体   English

编写一个 shell 脚本来显示当前登录的用户数并将计数写入“count.txt”。 显示count.txt文件内容

[英]write a shell script to display count of users currently logged in and write the count in "count.txt". Display the count.txt file content

Display count of users currently logged in and write the count in count.txt .显示当前登录的用户数并将计数写入count.txt Display the count.txt file content.显示count.txt文件内容。

I used this but it's not giving the right answer.我用过这个,但它没有给出正确的答案。

ls -l | wc > count.txt
cat count.txt

As said by @Barmar ls -l is not a correct command to have the number of users logged in.正如@Barmar 所说, ls -l不是让登录用户数量正确的命令。

Try w command.尝试w命令。 So thi muse looks like this:所以 thi muse 看起来像这样:

w -h| wc > count.txt
cat count.txt

The -h argument is to remove headers line. -h参数是删除标题行。

who | wc -l > count.txt;
cat count.txt

This will work -这将工作 -

who |谁 | wc> count.txt wc> 计数.txt

cat count.txt猫数.txt

暂无
暂无

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

相关问题 如何编写awk脚本来列出当前正在使用系统的用户以及他们登录的次数计数? - How to write an awk script to list users currently using the system along with a count of the number of times they have logged in? 我正在尝试使用 Grep 命令在 txt 文件中查找命令字符串,然后编写脚本来计算每个文件中的行数 - I am trying to Grep a command to find a string of command in a txt file, then write a script to count the lines in each file 在Shell脚本中计数值 - Count value in shell script 在终端CLI或Shell Sciprt中,我要计算多个文件的行数,并将行数写在每个文件的第一行 - In terminal CLI or shell sciprt, I want count the lines of multiple files and write the lines count on the first line at each file 在Linux中删除* .txt文件之前如何计算和添加到文件? - how to count and add to file before delete *.txt files in linux? Shell脚本:计算文件数,删除最早的“ X”文件 - Shell script: Count files, delete 'X' oldest file Linux Shell脚本来计算文本文件中char序列的出现? - Linux shell script to count occurance of char sequence in a text file? 在带有txt文件的shell脚本中添加用户 - Add users in shell script with txt file 脚本计数文件的唯一记录 - Script count unique records of file 如何在Linux中对大于值的行进行计数并将计数写入文本文件 - How to count rows greater than a value and write the count to a text file in Linux
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM