Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find files with spaces in the bash

Tags:

find

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

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

like image 932
altralaser Avatar asked May 18 '17 14:05

altralaser


2 Answers

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

EDIT

To replace the spaces with underscores, try this

find . -type f -name "* *" | while read file; do mv "$file" ${file// /_}; done
like image 108
Rakesh Gupta Avatar answered Nov 15 '22 10:11

Rakesh Gupta


With find:

find "/vol1/apache2/application/current" -type f -name "*[[:space:]]*"
like image 38
beliy Avatar answered Nov 15 '22 10:11

beliy