如何提升 nautilus 权限以 root 身份移动或复制文件夹?

如何提升 nautilus 权限以 root 身份移动或复制文件夹?

假设我在 Nautilus 中打开了一个文件夹,它位于我的/home/user/temp目录中。我想将文件夹从那里移动到我的/opt目录中(它是一个程序)。有没有办法将复制命令提升到 a,sudo以便我可以复制文件夹,而不必从命令行启动新的 Nautilus 实例?

答案1

根据我所了解和经历过的情况,我可以说:

sudo用于命令行应用程序/命令,gksudo当您尝试使用运行应用程序按 Alt+F2。

我已读过,那gksudo只是的图形版本sudo

无论如何,你都可以放弃sudo nautilus和/或gksu nautilus 在终端目的是做你想做的事,两个命令具有相同的效果。但如果你想省略终端,并希望直接用“运行应用程序“对话窗口,只需按 Alt+F2 并写入gksu nautilus,之后系统将提示您输入密码,然后 nautilus 文件浏览器将以 root 权限打开。

此外,通过右键单击使用“以管理员身份打开”选项,您可以单击一下以 root 身份打开文件/文件夹。无论如何,这将为给定文件夹打开一个新的 nautilus 实例,并以 root 身份打开文件,这也可能以 root 身份打开/运行应用程序,但我还没有测试过。

在此处输入图片描述

您可以通过命令行安装 nautilus-gksu 在上下文菜单中获得“以管理身份打开”选项:sudo apt-get install nautilus-gksu或者通过使用 synaptic,如下图所示:

在此处输入图片描述

祝你好运!

答案2

您需要以 root 身份运行 Nautilus

在终端中输入

gksu nautilus

现在您可以使用 GUI 移动。

或者使用此命令

sudo mv -r /home/user/temp/<foldername>/ /opt/

答案3

这是我用来打开管理员(根)Nautilus 窗口的 nautilus 脚本:

#!/bin/bash
# This Nautilus script opens the current nautilus window in admin mode.
# Requires: perl, liburi-perl

ERROR_NEED_PERL="This script requires the liburi-perl package. Install it and try again."
GKSUDO_MESSAGE="Enter your password to open an admin window on: "
ERROR_BROKEN_LINK="Broken link."

## Check for liburi-perl (and hence perl)
let PERLOK=$(dpkg-query -W --showformat='${Status}\n' liburi-perl|grep "install ok installed")
if [ "" == "$PERLOK" ]; then
   zenity --error --text "$ERROR_NEED_PERL"
   exit 1
fi

let LEN_NSSFP=${#NAUTILUS_SCRIPT_SELECTED_FILE_PATHS}-1
[ $LEN_NSSFP -lt 0 ] && let LEN_NSSFP=0
let LEN_NSSU=${#NAUTILUS_SCRIPT_SELECTED_URIS}-1
[ $LEN_NSSU -lt 0 ] && let LEN_NSSU=0

## if clicking happens on the Desktop (or a file or folder on it),
## $1 will be a path (i.e. with "/" in it); otherwise (in a folder
## window) $1 will be just a file or folder name (without path).
## Note that selecting the home desktop namespace extension yields
## a $# of zero but NAUTILUS_SCRIPT_SELECTED_FILE_PATHS pointing to the
## target (in the computer (computer:///) and trash (trash:///) desktop
## namespace extension cases, ...PATHS is empty).

## Initially, we stripped the file:// prefix from NAUTILUS...CURRENT_URI,
## yielding the full path, and then retrofit spaces, like this:
#OBJECT="`echo -n $NAUTILUS_SCRIPT_CURRENT_URI | cut -d'/' -f3- | sed 's/%20/ /g'`"
## However, this fails if any special characters other than spaces are in the path,
## such as accented letters, etc. We need to convert not just spaces, but any
## UTF-8 embedded in there...The URI<->path conversion requires perl (and liburi-perl):
OBJECT=$( echo "$NAUTILUS_SCRIPT_CURRENT_URI" | perl -MURI -le 'print URI->new(<>)->dir' )
## ->file is to be used for file URIs instead of ->dir, which is for directory URIs

CONTEXT="$OBJECT"
## Add the selection to the path, if defined and unique
if [ $# -eq 1 ] ; then
   ## If a single Desktop object, override
   if echo $1 | grep -q "/" ; then ## Desktop (or object on desktop)
      OBJECT="$1"
      CONTEXT=""
   else ## $1 is a simple file or folder name, without a path
      ## The container could be root (/)
      OBJECT="${OBJECT%/}/$1"
   fi
# elif [ $# -eq 0 -a -n "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" ] ; then
elif [ $# -eq 0 ] ; then
   ## desktop name space extension selected?
   if [ -n "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" ] ; then ## Home
      OBJECT="${NAUTILUS_SCRIPT_SELECTED_FILE_PATHS:0:LEN_NSSFP}"
   elif [ -n "$NAUTILUS_SCRIPT_SELECTED_URIS" ] ; then ## Computer, Trash
      ## These typically map to root (/)
#     OBJECT="`echo ${NAUTILUS_SCRIPT_SELECTED_URIS:0:LEN_NSSU} | cut -d'/' -f3- | sed 's/%20/ /g'`"
      OBJECT="${NAUTILUS_SCRIPT_SELECTED_URIS:0:LEN_NSSU}"
      OBJECT=$( echo "$OBJECT" | perl -MURI -le 'print URI->new(<>)->dir' )
   fi
   CONTEXT=""
fi
## Note that a desktop shortcut (.desktop file) does not trip -h
if [ -h "$OBJECT" ] ; then ## symbolic link
   ## readlink has no "follow symlinks as far as they exist" option
   OBJECT=`readlink -e "$OBJECT"`
   if [ -z "$OBJECT" ] ; then
      zenity --error --text "$ERROR_BROKEN_LINK"
      exit 1
   fi
fi

# zenity --info --text "\$OBJECT is « $OBJECT »"
if [ -f "$OBJECT" ] ; then
   ## Regular file
   DIR=`dirname "$OBJECT"`
else
   ## Directory (or no object)
   DIR="$OBJECT"
fi

## If DIR is empty, gnome-open opens in the default (home) directory (i.e. "~") anyway
#if [ -z "$DIR" ] ; then
#   DIR=~
#fi

## At this point, the test [ ! "$CONTEXT" = "$DIR" ] serves to indicate
## that the target directory is not matched to the one the script was
## invoked from (if any).

gksudo --message "$GKSUDO_MESSAGE$DIR" gnome-open "$DIR"

exit $?

答案4

sudo mv /home/user/temp/[Filename] /opt

相反[Filename],请输入不带括号的文件名[]

相关内容