我有一些目录具有以下结构:grep的用于两个模式独立地(在不同的行)
DAY1/ # Files under this directory should have DAY1 in the name.
|-- Date
| |-- dir1 # Something wrong here, there are files with DAY2 and files with DAY1.
| |-- dir2
| |-- dir3
| |-- dir4
DAY2/ # Files under this directory should all have DAY2 in the name.
|-- Date
| |-- dir1
| |-- dir2 # Something wrong here, there are files with DAY2, and files with DAY1.
| |-- dir3
| |-- dir4
在每dir
有文件数十万用含有DAY
名称,例如0.0000.DAY1.01927492
。名称上只有DAY1
的文件应该只出现在父目录DAY1
下。
复制文件时发生错误,所以我现在在dir
的某些目录中有DAY1
和DAY2
的混合文件。
我写了一个脚本来查找包含混合文件的文件夹,因此我可以更仔细地查看它们。我的脚本如下:
for directory in */; do
if ls $directory | grep -q DAY2 ; then
if ls $directory | grep -q DAY1; then
echo "mixed files in $directory";
fi ;
fi;
done
这里的问题是,我经历的所有文件两次,这是没有意义的考虑,我想只有通过文件看一次。
什么是更有效的方式来实现我想要的?
如果你只是用'find'获取文件并删除他们,如果他们不这样做属于他们应该在哪里? '找到DAY2/-name“* dir2”-delete“ – fedorqui
我无法删除它们。之后我必须把它们放在正确的位置。事情是我想明白为什么,什么时候发生,以及混合了多少个文件。 – dangom
然后你可以用'man find'来尝试打印你喜欢的任何东西。您可以选择文件名等 – fedorqui