Bash Find All File Names With White Spaces

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, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Share this on (or read 2 comments/add one below):

2 comment

    Have a question? Post it on our forum!