1

I was using find to loop over some files ,the targets are the files that have this kind of structure:

EDI_2016-03-03_09-45-09_TARGET-TYPE_4830_453a2cbb-b8d4-4982_6549_6116_xazfzeg.PDF

the goal is to find the files that starts with EDI_ and contains TARGET-TYPE in the middle, using find the command was :

find . -name "EDI_*_TARGET-TYPE*"

And since i'm going to use the output with a loop i don't want to use find and use ls instead(i've had a lot of problem with files with spaces and find).

This works : ls EDI_

  • does not work: ls EDI_*_TARGET-TYPE*

  • and this does not work: ls "EDI_*_TARGET-TYPE*"

  • and this does not work: ls 'EDI_*_TARGET-TYPE*'

and I dont really know why, if anyone can translate the find command to me that would be great .

  • Find parametrs are in double quotes. Should work for ls as well if you enclosed in double quotes there – Gnudiff Oct 18 '17 at 13:37
  • ls: cannot access "EDI_*_TARGET-TYPE*": No such file or directory is the error i get – Kingofkech Oct 18 '17 at 13:39
  • And the same error is for fully unquoted ls? – Gnudiff Oct 18 '17 at 13:40
  • yes , you can try make a touch of the file and then test by your self – Kingofkech Oct 18 '17 at 13:41
  • can you use the ` to make it more clear ? – Kingofkech Oct 18 '17 at 13:46
2
$ touch EDI_2016-03-03_0945-09_TARGET-TYPE_4830_453a2cbb.pdf
$ touch EDI_2016-03-03_0945-09_TARGET-TYPE_4830hhh_453a2cbb.pdf
$ ls EDI_*_TARGET-TYPE*
EDI_2016-03-03_09-45-09_TARGET-TYPE_4830_453a2cbb.pdf
EDI_2016-03-03_09-45-09_TARGET-TYPE_4830hhh_453a2cbb.pdf

Works for me. Bash shell Ubuntu recent LTS.

4

What I would do :

for file in EDI_*_TARGET-TYPE*; do
    do_something "$file"
done

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.