Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Sometimes a file name is created from a couple of names and space between each name as the following:

   $ touch  "A B C"
   $ ls
   A B C      <-- one file but has three words !                        

How can I ignore (filter) the file that actually created from couple of names as "A B C"?

Expected output

     $ ls <filter>
share|improve this question
up vote 5 down vote accepted

If you do the following:

ls | grep -F -v ' '

You will not see any file with spaces in the names

( I used to have fgrep instead of grep -F in the example, but as Hauke Laging pointed out that is deprecated)

share|improve this answer
May I quote my documentation: "Direct invocation as fgrep is deprecated" – Hauke Laging Apr 28 '13 at 15:16
@HaukeLaging Of course, thanks for pointing out. After 29 years of using fgrep I need to change my habits, that will take a bit – Anthon Apr 28 '13 at 15:52
..though you may see parts of a filename that contains spaces, one or more newline characters, and at least one line not containing spaces. Remember grep works on lines and a filename can be made of several lines. – Stéphane Chazelas May 6 '13 at 20:20
@HaukeLaging @Anthon: I [sadly] must add that egrep is also deprecated and grep -E is now the standard. – erch May 6 '13 at 20:36

With GNU ls, i.e. under non-embedded Linux:

ls -I '* *'

Not that there's much of a reason to skip files whose name contains a space. If you're doing that because you have something like file_names=$(ls) or for f in $(ls) in a script, don't parse the output of ls, and your problem will probably go away.

share|improve this answer

Using KSH's extended globs, you can filter out filenames in a glob expansion:

ls -d -- !(A B C)
share|improve this answer

Maybe this is also helpful:

ls -l --quoting-style=literal:
-rw-r--r-- 1 hl hauke 0 28. Apr 16:55 A B C

ls -l --quoting-style=locale:
-rw-r--r-- 1 hl hauke 0 28. Apr 16:55 „A B C“

ls -l --quoting-style=shell:
-rw-r--r-- 1 hl hauke 0 28. Apr 16:55 'A B C'

ls -l --quoting-style=shell-always:
-rw-r--r-- 1 hl hauke 0 28. Apr 16:55 'A B C'

ls -l --quoting-style=c:
-rw-r--r-- 1 hl hauke 0 28. Apr 16:55 "A B C"

ls -l --quoting-style=escape:
-rw-r--r-- 1 hl hauke 0 28. Apr 16:55 A\ B\ C
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.