Trying to come out with a 1 line command in linux to output all files in current directory which matches this criteria:
- the extension “.csv”
- a filename that includes “b”
- a filename that ends with “a” (immediately before the file extension)
I'm aware of how to use find when searching for 1 criterion but unable to make it work with multiple criteria, especially in one line.
CodePudding user response:
You can use a glob expression with find. In fact, you're looking for file names that have zero or more characters, then a "b", then another sequence of zero or more characters, then an "a" and then the extension ".csv", i.e.:
find . -name '*b*a.csv'
CodePudding user response:
You don't even need find
, say you want to loop over the files. Then you could save the file names in a bash array like this:
files=(*b*a.csv)
for f in ${files[@]}; do
echo "$f" # place holder for whatever command you want to run
done
However if you really just want to use find
, the answer by @Mureinik is sufficient.