1

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.

1
  • Have a look at the following link regarding basename – kingmilo Mar 21 '13 at 19:18
1

from man basename

NAME basename - strip directory and suffix from filenames

SYNOPSIS basename NAME [SUFFIX] basename OPTION

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

so, the command basename is doing this

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.