≡ Menu

Bash Find All File Names With White Spaces

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/
Tweet itFacebook itGoogle+ itPDF itFound an error/typo on this page?

{ 2 comments… add one }

  • Dan Lund June 11, 2013, 7:16 pm

    Thank you, this was very helpful.

  • raja October 15, 2014, 1:43 pm

    I need to replace the file names from white spaces to ‘_’.
    Please advise on this.

Leave a Comment