bash 列出今天由单个用户更改/修改的文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18801808/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 06:33:41  来源:igfitidea点击:

List files that is changed/modified today by single user

linuxbashshellunix

提问by user2496520

I need to list all files that is changed(modified) today from single users.

我需要列出今天从单个用户更改(修改)的所有文件。

I tried this: find -mtime -1but output is wrong. Can you guys/girls please tell me is there a way to list all files that is chanfed today from single user?

我试过这个:find -mtime -1但输出是错误的。你们可以告诉我有没有办法列出今天从单个用户更改的所有文件?

回答by mnagel

find . -mtime -1 -printf "%u %p\n" | sort

will recursively list all files (and the owner's name) in the current directory -- grouped by owner -- that have been modified today.

将递归列出当前目录中所有今天修改过的文件(和所有者的名字)——按所有者分组。

回答by mnagel

if you want to group by the owner of the file, you could add -user $userand loop over all relevant users. if you want to group by the user modifying the file, that is not possible as this information is not stored in the filesystem or elsewhere.

如果您想按文件的所有者分组,您可以添加-user $user并遍历所有相关用户。如果您想按用户修改文件进行分组,这是不可能的,因为此信息未存储在文件系统或其他地方。

回答by user1502952

Though not the best solution, but this script can be used.

虽然不是最好的解决方案,但是可以使用这个脚本。

# Check for files modified within past 24 hrs.

modifiedfiles=`find . -mtime -0`
username=`pwd | cut -d'/' -f2` # pwd is your current directory /home/user/

for i in $modifiedfiles
  do 
    check=`grep  $i /home/user/.bash_history`
      if [ "$check" != " " ] 
      then 
        echo "file $i modified by $username "
      fi
  done

where user in path /home/useris a particular user. .bash_historyfile contents are compared with the modifiedfileslist.

其中路径 /home/user 中的用户是特定用户。 .bash_history文件内容与modifiedfiles列表进行比较。