Home > Net >  Getting permission denied while creating a directory and how to add suffix to .exe to each files in
Getting permission denied while creating a directory and how to add suffix to .exe to each files in

Time:03-28

I want to create a directory say source_dir and add few dummy files without content into this directory like file1.txt, file2.sh, etc

Now I want to create another directory say destination_dir and move all the files from source_dir to destination_dir but all the files that got moved from source_dir should be suffixed by .exe

Example:

source_dir

file1.txt file2.sh

destination_dir should have output as

file1.txt.exe file2.sh.exe

What I have tried :

  1. I used mkdir source_dir -> But getting error cannot create directory. Permission denied.
  2. touch file1.txt file2.sh -> I thought to use this command to create the files without content but not able to create a directory itself.
  3. Once error is resolved and files are created in source_dir then I will use mv .* source_dir destination_dir -> To move all the files at once but for this command I am not sure whether this will work or not
  4. Then how to suffix all the files with .exe is also challenging to me and got stuck.

Can someone help me resolving the error of create directory and how to add suffix to each files?

CodePudding user response:

I used mkdir source_dir -> But getting error cannot create directory. Permission denied.

It seems you do not have permission to create a fodler here. You might use sudo mkdir source_dir, but is likely a better idea to make the folder in a directory where you have write access EG. $HOME.

Once error is resolved and files are created in source_dir then I will use mv .* source_dir destination_dir -> To move all the files at once but for this command I am not sure whether this will work or not

For moving use mv .* destination_dir from withing the source_dir. (IE, first cd source_dir then run the move command from above)

Then how to suffix all the files with .exe is also challenging to me and got stuck.

You will have to loop over the files and move them one by one.

for i in * ; do mv "$i" "${i}.exe" ; done 
  • Related