bash 在bash中查找带空格的文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44050676/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Find files with spaces in the bash
提问by altralaser
I want to search for files in a folder which have a space in its filenames, f.e.
我想在文件夹中搜索文件名中有空格的文件,fe
/vol1/apache2/application/current/Test 1.pdf
/vol1/apache2/application/current/Test 2.pdf
I know there's a find command but I can't figure out the correct parameters to list all those files.
我知道有一个 find 命令,但我无法找出列出所有这些文件的正确参数。
回答by beliy
With find
:
与find
:
find "/vol1/apache2/application/current" -type f -name "*[[:space:]]*"
回答by Rakesh Gupta
Use find command with a space between two wildcards. It will match files with single or multiple spaces. "find ." will find all files in current folder and all the sub-folders. "-type f" will only look for files and not folders.
使用 find 命令,在两个通配符之间有一个空格。它将匹配具有单个或多个空格的文件。“找 。” 将查找当前文件夹和所有子文件夹中的所有文件。“-type f”只会查找文件而不是文件夹。
find . -type f -name "* *"
EDIT
编辑
To replace the spaces with underscores, try this
要用下划线替换空格,试试这个
find . -type f -name "* *" | while read file; do mv "$file" ${file// /_}; done