0

Using thunar as my file manager. Sometimes I want to paste things in the directories that I don't own. Now, I know that I can use the terminal to make a new window with elevated privilages with sudo thunar. But seems too long a step. So I want to make a custom action which can be used with the context menu.

Trying the command with terminal first to try it out. Now as an example I will try to copy the opera.desktop file from my ~/Desktop to /opt/

Since gksudo is deprecated, I decided to use the new pkexec

Attempt 1: Use pkexec with the cp command

tim@timmy-Inspiron-3505:~/Desktop$ pkexec cp opera.desktop /opt/
/usr/bin/cp: cannot stat 'opera.desktop': No such file or directory

Attempt 2: Elevate privilege before copying

tim@timmy-Inspiron-3505:~/Desktop$ pkexec su && cp opera.desktop /opt/ && exit
root@timmy-Inspiron-3505:~# 

I don't know what else to try. Any suggestions ?

1 Answer 1

0

Don't ever run your GUI file manager as root!

You're on the right track using the cp command but your syntax is wrong.

If you are copying a single file you can use:

sudo cp /path/to/file /path/to/destination

If you are copying multiple files or a directory, you need to use the recursive flag:

sudo cp -r /path/to/dir /path/to/destination

Be very careful with these commands especially if you are copying into system directories. With that note, don't copy things to system directories unless you are absolutely sure that you really need to do that. It's easy to break things by overwrites or putting things where they don't belong.

Some tips for safer usage:

If you don't need sudo for a particular operation, don't use it.

If applicable, use relative paths instead of absolute paths.

1
  • I don't want to "run" the file manager as root. I just want to paste as root. It's just frustrating sometimes, when you're using gui for an hour and then in order to paste a file I have to open a terminal. Why isn't there a gui mode to paste in system directory. Normally I wouldn't say "Windows does it, why can't we ?" but sometimes it just makes sense. Have a pop-up to put in the password if you are pasting in a protected directory May 25, 2022 at 2:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .