1

I want a create a file with a specific extension(.done). I am using the command touch. Something Like:

touch `basename $UNZIPFILE`".done" 

It's creating the file but in current directory. I want to create this file in a specific directory. Is there a option to provide the directory ?

I checked : http://ss64.com/bash/touch.html , but could not figure out.

I can think of one option is before this command I can do a cd requiredDIR

Is there any other way, I can specify the Directory on the same command, so that I dont have to change the Directory?

1
2

basename remove the directory part. You may get it back with command dirname

touch "$(dirname "$UNZIPFILE")/$(basename "$UNZIPFILE").done"
0

Maybe try

touch ./directoryYouWantFileIn/Whateveryouwantfilenamed.whateverExtension

I think you need full path of where you want it made.

1
  • Welcome to the site, and thank you for your contribution. Please note, however, that your answer is essentially the same as the accepted answer, only with a hard-coded filename. – AdminBee Oct 1 '20 at 8:16

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.