A
A
AirFlare2021-07-12 18:37:22
bash
AirFlare, 2021-07-12 18:37:22

How to check the presence of files by mask in a condition?

Let there be a file Y , with the extension .abcdefg. Note that the file Y . If they are in folder X, output: Good. I found it!. If they are not in it - Sorry. I don't find them.
I know bash has conditions. As a result, if there is one file, something like this should come out:

myfile="/way/to/file/file.abcdefg"

if [ -f "$myfile" ]; then
  echo "Good. I fin'd it!"
else
  echo "Sorry. I don't find them."
fi

But the whole problem is (I repeat) that in my directory there can be several files with the .abcdefg extension, and I don’t know how to make a condition for such a task.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
hint000, 2021-07-12
@AirFlare

ls /way/to/file/*.abcdefg >/dev/null 2>&1 &&echo "Good. I found it!" ||echo "Sorry. I didn’t find it."

I took the liberty of correcting English.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question