Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
查找Linux中两个目录之间缺少的文件(缺少文件名,但没有扩展名)_Linux_Diff_Difference - Fatal编程技术网

查找Linux中两个目录之间缺少的文件(缺少文件名,但没有扩展名)

查找Linux中两个目录之间缺少的文件(缺少文件名,但没有扩展名),linux,diff,difference,Linux,Diff,Difference,假设我有dir1/有1.a2.a3.a5.a,dir2/有1.b2.b3.b4.b5.b 我想知道如何忽略扩展名,找到丢失的文件(本例中为4.b) 我假设diff命令不起作用,因为我没有看到相关的参数。您可以使用basename命令删除basename: find dir1 -type f -exec basename '{}' .a \; | sort > list1 find dir2 -type f -exec basename '{}' .b \; | sort > list

假设我有dir1/有1.a2.a3.a5.a,dir2/有1.b2.b3.b4.b5.b

我想知道如何忽略扩展名,找到丢失的文件(本例中为4.b)


我假设
diff
命令不起作用,因为我没有看到相关的参数。

您可以使用
basename
命令删除basename:

find dir1 -type f -exec basename '{}' .a \; | sort > list1
find dir2 -type f -exec basename '{}' .b \; | sort > list2
然后使用
diff list1 list2
比较两者。或者可以使用
comm
而不是
diff

作为basename的替代方案(需要明确指定
.a
.b
),您还可以使用
sed
去除最后一个点后的所有内容:

ls dir1 | sed -e 's,\.[^.]*$,,' | sort > list1
ls dir2 | sed -e 's,\.[^.]*$,,' | sort > list2