Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Here is my problem. I want to store the directory of a specific file in a variable via terminal but in my folder there are many files let say one of them is test1432.config and the other is test1432-busybox.config and the other files whose extention are not .config. So I decided to write

fst_directory="%s" %(co_directory[3:])+ "/*.config"

But If I do that in this way, it also takes the test1432-busybox.config doesnt it ? How could I do that ? thanks in advance


The only differences between two file is the busybox part. I mean fileName-busybox.config and fileName.config. I always want to choose fileName.config


Since nobody share the solution. I created my own. In this case the busybox is not necessary file for me . So I decided to delete them and after that I can choose the true file easly. If the file is important and you could not delete it.You can move it somewhere else and move back after the operation.

share|improve this question
My problem was that. There are more than one file with .config extantion and I just want to get one of them. So I do it by this way. fst_directory="%s/%s"%(co_directory[3:],fst_firmware_name)+"/*%s.config"%(fst_fi‌​rmware_name) In this way, it takes only the "blablbla"fst_firmware_name.config file I hope I Could help @Braiam – caesar Aug 24 '13 at 11:58
Sorry for being vague, share your solution in the answers below. – Braiam Aug 24 '13 at 12:45
up vote 2 down vote accepted

Assuming you have two files, one you want to list/use and one you want to ignore with the one to ignore containing - in it's filename as in -busybox:

 ls *.config | grep -v '-'

From man page about grep -v option:

      -v, --invert-match
          Invert  the  sense  of matching, to select non-matching lines.  (-v is specified by

Which basically means list all files ending with .config, pipe to grep and exclude those containing -

Or something that gives more control over the selection:

 ls | grep ".*[^-busybox].config"

Which means:

List all files in directory pipe them to grep and using a regular expression filter them to include * for everything but not those in brackets [^-busybox], ending with .config

[^] excludes.

share|improve this answer

Your Answer


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.