-2

I'm a root user sudo -i, now i want to execute the Downloads/my.sh from root. how do i do that?

1
  • try: bash ~/Downloads/my.sh, if it is under a different username Download folder, then try: bash ~username/Downloads/my.sh make sure you specify the right username. – NiteRain May 11 '20 at 21:07
2

Using sudo -i starts a new shell as root. Use sudo su, or sudo -s, which lets you switch users, so you are logged in as root. Then, you can just enter the Downloads directory with cd Downloads and run your script.

1
0

First you should know there are 2 ways:

First make your file executable just right click it, under permission tab check allow executing file as program

The Graphical way

A.1) Open your file manager as root(Assuming you are using Ubuntu gnome version if not, change nautilus for your file manager)

$ sudo nautilus

A.2) With your file manager is open as root, you should navigate to the folder containing your executable file

A.3) Now you just double click it, if didn't work you right click it and then click "open with" and in the new window select "list all" and now you can search for "execute program" or something similar

The Terminal Way

B.1) You open your Terminal Window and the you type(just to be sure you are at your home directory)

$ sudo cd

B.2) Now you type this

$ sudo ./Downloads/my.sh

alternate way is

$ cd the/route/to/the/folder/containing/the/file

and now you execute

$ sudo ./file.sh

if you want to execute something as root user, not just asking for permission try this

$ sudo su

and now you locate the file and execute it

$ ./usr/arghadip/downloads/file.sh

edited it for your needs as you commented it

5
  • but i want to call it as root /usr/arghadip/downloads/file.sh – Arghadip May 11 '20 at 21:28
  • could use {sudo su} and then type the route with cd, – Giovanni Rodríguez May 11 '20 at 21:32
  • can i copy the parent dir to the root? it's a 4 GB folder containing a lot of other files. So i could execute it directly inside root /Desktop/myfolder/myfile.sh if it's possible write me the copy command – Arghadip May 11 '20 at 21:36
  • I edited it with your last comment's needs and you just type cp -R /etc /home/Downloads/ <---- this will copy etc folder recursively with all the files and folders inside it to Downloads inside home – Giovanni Rodríguez May 11 '20 at 21:42
  • nevermind i got what i want – Arghadip May 11 '20 at 21:44
0
  • You need to use absolute path:
Ex:
/home/username/Download/my.sh
  • When you write command root -i you are the root user. So that, If you write command Download/my.sh it will be take as /root/Download/my.sh.

  • If your are simple user Download/my.sh is like /home/username/Download/my.sh. So, when you are the root user you need to give command form where you are (absolute path).

1
  • Download/my.sh will only behave like /Download/my.sh when the current directory is /. This is independent of what user account one is logged in as, and no more likely to occur when logged in as root. By simulating a full login, sudo -i causes the current directory to be root's home directory; but root's home directory is /root, not /. – Eliah Kagan May 30 '20 at 14:46
0

I was a real noob back then.

~/Downloads/my.sh

Thanks @NiteRain for your comment.

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.