Which command returns all files that end with a single digit and have the TXT extension ?
Unix Command to return all files that end with single digit and TXT extension
fileslswildcards
Related Question
- Fastest way to read last line within pattern of multiple files with the same extension
- Bash – list all files with extension .log except one
- Shell – Matching all files ending with a certain extension with a shell glob (say, all files ending with .sh)
- Linux – Using ls to Find Files Ending in a Character, Ignoring Extension
Best Answer
One of the most basic tools for locating files (or other kinds of nodes) is the
find
utility.This will search:
./
). You could change this to another path or even leave it off since this is the default value for most versions offind
.-type f
). You could leave this off if you wanted to find other types too.-name '*[0-9].txt'
)If there are files whose name is only a digit followed by
.txt
, the command above will miss them, because it requires one non-digit before the digit. The following equivalent commands use boolean operators to include file names with just a digit as well (-o
is “or” and!
is “not”):Note that this will be case sensitive. If you would like an insensitive match, you can use
-iname
instead of-name
to match things likefile4.TXT
as well. Also be aware that just because a file claims to be a text file with that extention does not mean it is. On linux any file can be any type no matter the name. There might also be text files with other extentions or with no extention at all.