简体   繁体   English

linux找不到这样的文件或目录,但是存在

[英]linux find no such file or directory but exists

Then i trying to use this script 然后我尝试使用此脚本

for line in `cat dirs.txt`; 
do 
find "$line" -type f \( -name '*good*' -o -exec grep -F "badbad" {} \; \) -exec echo {} \;; 
done

I get error on each existing dirs and match the find criteria 我在每个现有目录上都出错并匹配查找条件

 find: /home/goods/ : No such file or directory find: /home/bads/ : No such file or directory find: /home/fill/ : No such file or directory 

But then i look manualy this dirs exist and i can read them all Why this happens? 但是然后我手动查看这个目录存在,并且我可以阅读所有目录为什么会发生这种情况?

Issue is that you have dos ( ^M ) line endings, in the file. 问题是您在文件中有dos( ^M )行结尾。 Running dos2unix dirs.txt dirs.txt should solve the problem. 运行dos2unix dirs.txt dirs.txt应该可以解决问题。 Ideally, you also shouldn't use for line in $(cat ... , but something like 理想情况下,您也不应该for line in $(cat ...使用for line in $(cat ... ,而是类似

while IFS= read -r line; do
  find "$line" -type f \( -name '*good*' -o -exec grep -F "badbad" {} \; \) -exec echo {} \; 
done < dirs.txt

You must check in file for ^M$ 您必须检入文件中的^ M $

You can do that with command cat dirs.txt -vET 您可以使用cat dirs.txt -vET

Then you must trim them all with command cat dirs.txt|tr -d "\\r" >1.txt 然后,必须使用命令cat dirs.txt|tr -d "\\r" >1.txt修剪它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM