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.

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? (This happens to be equivalent)

Thanks!

share|improve this question
add comment

2 Answers

up vote 2 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
1  
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
add comment

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
add comment

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.