我想要这个命令:
sudo chown $USER -R ./
出现在我的鹦鹉螺上下文菜单,以便我可以快速获得文件的所有权。
这是可能的吗,因为这是一个 sudo 命令?如果可以,怎么做?
答案1
你的(简短)脚本似乎不能像 nautilus 脚本那样工作,但是这里在 Ubuntuforums 上,我发现了一个非常好用的版本。它有一些更高级的选项,如 Ubuntuforums 上的发帖人评论中所述:
“注意:默认情况下,这是非递归的,因此它只会对您选择的特定文件夹和文件进行操作。如果您想要递归行为 - 取消注释“#RECURSIVE=-R;”行。默认情况下不使用它,因为当这样的事情变得如此简单时,弄乱所有权的风险相当大。“
如何使用
以下脚本未经修改就被复制。将其粘贴到一个空文件中,然后保存在~/.local/share/nautilus/scripts
(脚本的注释中提到~/.gnome2/nautilus-scripts
,但似乎已经过时了),使其可执行,注销/登录后,它将在上下文菜单中可用(在下> scripts
)。
笔记:你需要安装 gksu 才能使用它
#!/bin/bash
#Title=Make owned by current user
#Title[se]=Gör nuvarande användare till ägare
# Make owned by current user - Makes the selected files owned by the current user with group
# being the user's primary group (the first in the output from the "groups" command)
# Installation:
# Put this script into the Nautilus script dir (~/.gnome2/nautilus-scripts) and make it executable.
#
# Usage:
# Right-click on files in Nautilus and choose Scripts -> Make owned by current user
#
# Notes:
# This operates non-recursively by default, so it will only operate on the specific folder and files that
# you have selected. If you want recursive behavior - uncomment the "#RECURSIVE=-R;" line further down.
# It is left out be default since the risk of messing up ownerships is pretty big when something
# like this gets so easy.
#
# Acknowledements and version history:
# v20080131 - Fredrik Wollsén
#
# License GPL v3
#
# Feel free to provide feedback on this script here:
# http://ubuntuforums.org/showthread.php?t=683945
#
# Suggestions for improvements:
# - Show a zenity dialogue box to dynamically decide whether or not the command
# should be run recursively or not.
# - Show a zenity progress bar for the execution of the command.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
USER=`whoami`;
GROUP=`groups | sed -r 's/ .*//g'`;
#RECURSIVE=-R; # Uncomment this to make the ownerships be implemented resursively
# default to a group name identical to the username if a group is not found (is this case even possible? this if-statement could be totally useless - but: better safe than sorry...)
if [ "$GROUP" == "" ] ; then
GROUP=$USER;
fi
gksudo -- chown -v $RECURSIVE $USER:$GROUP "$@"| zenity --text-info --height=100 --width=300;
exit 0;