首页 > 解决方案 > 在 bash 中获取新添加的文件

问题描述

我有一个将一些文件创建到文件夹中的过程。在运行该过程后,我需要确定添加了哪些文件。我在 Ubuntu 20 的 bash 中这样做

在 PowerShell 中,我可以这样做:

$filesBefore = (gci).Name    
# ... -> here I run my process
$filesAfter = (gci).Name
$filesAfter | ? {$filesBefore -notcontains $_} # This will compare both list

在 Bash 中做类似事情的最佳方法是什么?

标签: linuxbashubuntu

解决方案


查找进程创建的文件的一种方法是查找进程开始运行后修改时间的所有文件。

touch watch
# here you run your process
find . -newermm watch

touch watch将创建一个文件名watch

find . -newermm watch它将查找并打印创建文件后watch创建的所有文件


推荐阅读