Bash Find All File Names With White Spaces

Posted on in Categories , , , , , , , , , last updated August 14, 2009

How do I find all files with one ore more blank space (while spaces) in their name under UNIX like operating systems?

Simple use ls command along with egrep to list only file names with white spaces

ls | egrep '. '

Sample Outputs:

Find the memory used by a program.doc
Keep moving forward.doc

You can copy all such files to other directories using xargs:

ls  | egrep '. ' | xargs -I{} cp -v {} /tmp/

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

2 comment

Leave a Comment