Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I want to list all files in a directory that don't have extensions.

For example:

$ ls
a.txt    b      c.pdf     d     e.png
$ ls -someOption
b       d

What command I can use instead of ls -someOption?

share|improve this question
    
Ususally if you want to know the options for a command, read its man page by typing "man <command>" in the terminal. man stands for manual (help).for example- man ls –  Aaditya Bagga Aug 27 '13 at 16:25
    
@AadityaBagga In this case, the answer is not found in the manual. –  wisbucky Dec 19 '13 at 23:43

3 Answers 3

up vote 9 down vote accepted
shopt -s extglob ## enables extended globbing
ls !(*.*) ## matches every file except those containing a dot

You will find that doing this will show you the contents of every directory in the working directory. If you don't want this, use:

ls -d !(*.*)

You can put shopt -s extglob in your ~/.bashrc to have it activated whenever you open a terminal. There is already a line in the default Ubuntu ~/.bashrc (line 29 for me on 13.04) that you can uncomment to enable this (and globstar).

See Greg's wiki for more information on the shell's various globbing options. Note that this is a property of the bash shell rather than the ls command, so you can use it with other commands.

Alternatively, you can use

ls --ignore='*.*'

or

ls -I '*.*'

...which is an internal ls option, but extglob can be applied to any arbitrary command & so is more useful in my opinion.

share|improve this answer
    
OP didn't mention which shell, though I guess bash is assumed. If it were ksh, no extglob required. By default, just: ls !(*.*) –  runrig Aug 27 '13 at 23:30
1  
@runrig You're quite correct, but given the basic nature of the question I assumed the OP is using the default bash shell. –  evilsoup Aug 27 '13 at 23:55

Both ls | grep -v \\. and ls | grep -v "\." works.

share|improve this answer

Because the OP didn't specified clear if he wants to be listed only files (without directories), in addition for the previous answers, I would like to add:

ls -pI*.* | grep -v /

or

ls -p | grep -Ev '\.|/'

which will list only files without directories. The -p option append / indicator to directories and with the help of grep we can exclude the files (in fact directories) that contain that indicator.

share|improve this answer

Your Answer

 
discard

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.