簡體   English   中英

如何檢查linux用戶是否有.sh文件?

[英]How to check if linux user has .sh file?

我必須在 bash 中編寫腳本來檢查登錄的用戶是否有任何 .sh 文件。
檢查誰登錄很簡單,只需使用:

w| awk '{print $1}'

但我不知道如何檢查他們是否有 any.sh 文件

您需要閱讀who命令的 output 並在您的find命令中使用它。

由於同一用戶可以多次登錄,因此最好在循環之前刪除重復項。

#!/bin/bash
who| awk '{print $1}' | sort -u | while read -r username; do
    find /home/"$username" -name "*.sh"
done

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM