Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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

For example, how can I replicate:

ls *.txt

when my text files are missing the .txt ending, and as far as extensions go appear the same as many other types of file?

Alternatively, is it possible to list specifically just the files which have NO file extension?

share|improve this question
up vote 5 down vote accepted

To match files that do not have an extension at all, you can use the command

ls | grep -v '\.'

To match files that do not have a .txt extension, you can use the command

ls | grep -v '\.txt'

This will pass the list of files in the current directory to grep, which will remove all file names that have a . (or .txt for the second command) in them.

share|improve this answer
Thankyou! This answered my question. Additionally, is it possible to use the same grep tool with other commands? For instance, with todos? (to convert line endings) – user82212 Jan 22 '13 at 20:31
Yes, grep can be used with any command. The | symbol is used to pass output from one command to another, and grep will match lines that have (or don't have) specific text. But if you want to modify the text (other than just printing matching lines), you should take a look at the sed command. – iBelieve Jan 22 '13 at 20:38
To find only text files (excluding directories and binaries) use: ls --classify | grep -v '/'.'*' – chaskes Jan 22 '13 at 20:53

With ls -ignore="PATTERN" you can exclude files from a ls result.

For example, ls --ignore="*.txt" to ignore txt files.

share|improve this answer

Simply negate your pattern (note: shopt -s extglob is required).

To display all files without extension:

ls !(*.*)

To show non-txt files, try:

ls !(*.txt)
share|improve this answer

The command ls -SX1|less will sort by extension in a single column and files without one will be moved to the top. Piping through less as in the example is suggested for directories with more than a few files to limit output to a screen full at a time.

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.