I made the script in my home folder, and it works perfectly, but I want to move it to another directory, for example to folder called "my scripts". How can I do it?
I tried different ways with chmod +x
and ln -s
, for example:
/home/user/downloads/my scripts/script.sh /usr/bin
I want to have the chance to copy and paste it anywhere on my Ubuntu folders, and execute it by clicking.
A script essentially is a simple text file. You can copy it anywhere in the same way as you copy regular files.
If you want to copy using the terminal, you use the
cp
command as incp "/home/user/downloads/my scripts/script.sh" "/home/user/scripts/"
"/home/user/scripts/"
in this example is the destination folder. It must exist for thecp
command to proceed. If it does not exist, create the folder first.`mkdir /home/user/scripts/'
You are mentioning
/usr/bin
This is a system folder, which would be a suitable folder for placing custom executable files that should be available for all users. You only can copy files into system folders if you have administrator (in Linux also known as 'super user' or 'root') rights. In that case, you can precede the command withsudo
, i.e., "act as super user", as insudo cp "/home/user/downloads/my scripts/script.sh" "/usr/bin"
The
sudo
command will request your login password. If your account has root privileges, the command will be executed after you successfully entered your password.That said, only change system files if you are absolutely sure what you want to achieve. If you want to use your custom scripts only for your self, it is a much better approach to create a "bin" folder in your own home folder. Whenever you open a terminal, Ubuntu automatically will include your private bin folder in the program path. As a result, you, but only you, will be able to execute the script simply by typing its name in the terminal. This eliminates any risk of you breaking the system by working in system folders.
I'm not completely sure I understand your question... If using a GUI file manager, just copy and paste to your new folder and set permissions accordingly. If you're using the command line
Then give your script executable permissions.