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

I have a question which is super simple, but I just can't wrap my head around it. Regarding the following command line:

for foo in *.dist; do cp $foo `basename $foo .dist`; done

I know it takes all files in the current directory which have .dist as an extension, copies them and in the same step removes the .dist extension (I have grapped it from a wiki post regarding the installation of OTRS under Ubuntu Server). I just want to understand WHY it is doing this.

Thank you very much.

share|improve this question
Have a look at the following link regarding basename – kingmilo Mar 21 '13 at 19:18
up vote 1 down vote accepted

from man basename

NAME basename - strip directory and suffix from filenames


DESCRIPTION Print NAME with any leading directory components removed. If speci‐ fied, also remove a trailing SUFFIX.

so, the command basename is doing this

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.