Thursday, May 2, 2024
23
rated 0 times [  23] [ 0]  / answers: 1 / hits: 30236  / 1 Year ago, sun, december 11, 2022, 7:20:59

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?


More From » command-line

 Answers
4
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.


[#29744] Sunday, December 11, 2022, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
heathree

Total Points: 157
Total Questions: 132
Total Answers: 108

Location: Honduras
Member since Mon, Apr 5, 2021
3 Years ago
;