我试图在/foo保留列出目录中的空格的同时回显所有文件。目前,名为目录"bar1 bar2"将回声出作为/path/to/foo/bar1/然后/bar2再file.txt全部上新的生产线。我需要它来 echo/path/to/foo/bar1 bar2/file.txt或/path/to/foo/bar1\ bar2/file.txt.
for file in $(find /path/to/foo/ -type f); do
if [[ ... ]]; then
echo "${file}"
fi
done
Run Code Online (Sandbox Code Playgroud)
还试过:
for file in $(find /path/to/foo/ -type f | sed 's/ /\ /g'); do
if [[ ... ]]; then
echo "${file}"
echo "$file" # variations i've tried
echo $file # variations i've tried
echo ${file}
otherCommand "${file}"
fi
done
Run Code Online (Sandbox Code Playgroud) 如何find列出每个文件但从搜索中排除少数目录?
find / -type f -not -path "./foo*" -not -path "/bar*" -print
Run Code Online (Sandbox Code Playgroud)
我在其他 stackexchanges 上看到过示例,例如./,但我尝试过的似乎都不起作用。
这有点有效:
find / -type f -not -path "*foo*" -not -path "*bar*" -print
Run Code Online (Sandbox Code Playgroud)
但事实并非如此;它还从搜索结果中排除名为“foo”和“bar”的文件。