查找bash中带有空格的文件 [英] Find files with spaces in the bash

查看:79
本文介绍了查找bash中带有空格的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要搜索文件夹中文件名带有空格的文件.

I want to search for files in a folder which have a space in its filenames, f.e.

/vol1/apache2/application/current/Test 1.pdf
/vol1/apache2/application/current/Test 2.pdf

我知道有一个find命令,但是我无法找出列出所有那些文件的正确参数.

I know there's a find command but I can't figure out the correct parameters to list all those files.

推荐答案

使用find命令,两个通配符之间有一个空格.它将匹配具有单个或多个空格的文件.找 ."将在当前文件夹和所有子文件夹中找到所有文件."-type f"将仅查找文件,而不是文件夹.

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 -name "* *"

编辑

要使用下划线替换空格,请尝试

To replace the spaces with underscores, try this

find . -type f -name "* *" | while read file; do mv "$file" ${file// /_}; done

这篇关于查找bash中带有空格的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆