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/

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 2 comments so far... add one


CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
2 comments… add one
  • Dan Lund Jun 11, 2013 @ 19:16

    Thank you, this was very helpful.

  • raja Oct 15, 2014 @ 13:43

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

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum