![如果我创建了一个文件夹的链接,那么如何在 Nautilus 中从该链接文件夹转到“真实”文件夹?](https://linux22.com/image/1039456/%E5%A6%82%E6%9E%9C%E6%88%91%E5%88%9B%E5%BB%BA%E4%BA%86%E4%B8%80%E4%B8%AA%E6%96%87%E4%BB%B6%E5%A4%B9%E7%9A%84%E9%93%BE%E6%8E%A5%EF%BC%8C%E9%82%A3%E4%B9%88%E5%A6%82%E4%BD%95%E5%9C%A8%20Nautilus%20%E4%B8%AD%E4%BB%8E%E8%AF%A5%E9%93%BE%E6%8E%A5%E6%96%87%E4%BB%B6%E5%A4%B9%E8%BD%AC%E5%88%B0%E2%80%9C%E7%9C%9F%E5%AE%9E%E2%80%9D%E6%96%87%E4%BB%B6%E5%A4%B9%EF%BC%9F.png)
假设我的文档文件夹中有一个文件夹,位于几层之下。我想从我的桌面轻松访问它。为此,我:
- 转到 Nautilus 中的父文件夹。
- 右键单击文件夹的图标并选择
Make Link
- 将新的“链接到...”文件夹剪切/粘贴到我的桌面上。
太棒了。而且对我来说,这基本上很管用。
但假设我想转到该文件夹的父级。我当然可以使用原始路径(Nautilus 称之为“链接路径”)到达那里,我可以在文件夹的属性中看到它。但这似乎比它应该的要难。
我怎样才能点击文件夹并直接转到链接路径?
答案1
到目前为止,似乎还没有正式实现此功能。我在 Ubuntu Brainstorm 上发现了一个功能请求,但是它已经开放了一段时间了。对其中提供的一项建议进行投票可能仍然是一个好主意。
与此同时,您可以添加 nautilus 脚本来执行此任务。只需复制下面的脚本并将其粘贴到一个空文件中,并使用您选择的名称~/.gnome2/nautilus-scripts/
(例如“打开链接目标”)。
#!/bin/bash
#Title=open-the-link-target-in-nautilus
#Title[fr]=ouvrir-le-repertoire-cible-dans-nautilus
#==============================================================================
# open-the-link-target-in-nautilus
#
# author : SLK
# version : v2011051501
# license : Distributed under the terms of GNU GPL version 2 or later
#
#==============================================================================
#
# description :
# nautilus-script :
# opens the target of a symbolic link of the selected object; if
# the target of the symbolic link is a file, opens the parent folder
#
# informations :
# - a script for use (only) with Nautilus.
# - to use, copy to your ${HOME}/.gnome2/nautilus-scripts/ directory.
#
# WARNINGS :
# - this script must be executable.
# - package "zenity" must be installed
#
#==============================================================================
#==============================================================================
# CONSTANTS
# 0 or 1 - 1: doesn't open but displays a message
DRY_RUN=0
#------> some labels used for zenity [en]
z_title='open the link target in nautilus'
z_err_bin_not_found='not found\nEXIT'
z_no_object='no object selected\nEXIT'
z_info_target='path of the target'
z_choice_open_nautilus='open target in nautilus'
z_choice_open_file='open file with default application'
z_choice_display_filepath='open a messagebox to copy filepath'
#------> some labels used for zenity [fr]
#z_title='ouvrir le repertoire cible dans nautilus'
#z_err_bin_not_found='introuvable\nEXIT'
#z_no_object='aucun objet selectionne\nEXIT'
#z_info_target='chemin de la cible'
#z_choice_open_nautilus='ouvrir la cible dans nautilus'
#z_choice_open_file='ouvrir le fichier avec le programme par defaut'
#z_choice_display_filepath='ouvrir une boite de dialogue affichant le chemin du fichier'
#==============================================================================
# INIT VARIABLES
# may depends of your system
DIRNAME='/usr/bin/dirname'
GREP='/bin/grep'
NAUTILUS='/usr/bin/nautilus'
PERL='/usr/bin/perl'
READLINK='/bin/readlink'
XDG_OPEN='/usr/bin/xdg-open'
ZENITY='/usr/bin/zenity'
#==============================================================================
# FUNCTIONS
function check_bin
{
err=0
for bin in $* ; do
if [ ! -x "$bin" ] ; then
$ZENITY --error --title "$z_title" \
--text="$bin $z_err_bin_not_found"
err=1
fi
done
[ $err -eq 1 ] && exit 1
}
#==============================================================================
# MAIN
# lets check for required binaries :
[ -x "$ZENITY" ] || {
echo "[ERROR] $ZENITY not found : EXIT"
exit 1
}
check_bin "$DIRNAME" "$GREP" "$NAUTILUS" "$PERL" "$READLINK"
# lets check if object is selected :
[ "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" == "" ] && {
$ZENITY --error --title "$z_title" \
--text="$z_no_object"
exit 1
}
# retrieve the first object selected :
first_object=`echo "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" \
| $PERL -ne 'print;exit'`
# lets check if local path :
[ `echo "$first_object" | $GREP -c "^/"` -eq 0 ] && {
$ZENITY --error --title "$z_title" \
--text="[ERROR] $first_object has not a valid path\nEXIT"
exit 1
}
# retrieve the target path :
if [ -L "$first_object" ] ; then
# symbolic link
target=`$READLINK -f "$first_object"`
else
# not a symbolic link :
target="$first_object"
fi
if [ -d "$target" ] ; then
# target is a directory
target_to_open_in_nautilus="$target"
else
# target is a file, let's take the parent directory
target_to_open_in_nautilus=`$DIRNAME "$target"`
fi
### DRY RUN : noop
[ $DRY_RUN -eq 1 ] && {
$ZENITY --info --title "$z_title" \
--text="<b>DRY RUN</b>
first_object: $first_object
target: $target
target_to_open_in_nautilus: $target_to_open_in_nautilus"
exit 0
}
### GO : let's open
choice=`$ZENITY --list --title="$z_title" --width="500" --height="200" \
--text="<b>$z_info_target</b>\n$target" \
--radiolist --column "" --column "action" \
TRUE "$z_choice_open_nautilus" \
FALSE "$z_choice_open_file" \
FALSE "$z_choice_display_filepath"`
case $choice in
"$z_choice_open_nautilus")
$NAUTILUS --no-desktop "$target_to_open_in_nautilus"
;;
"$z_choice_open_file")
$XDG_OPEN "$target"
;;
"$z_choice_display_filepath")
$ZENITY --entry --title="$z_title" --width="500" \
--text="$z_info_target" \
--entry-text="$target" &
;;
*)
exit 1
;;
esac
exit 0
### EOF
然后通过右键单击文件并转到Properties --> Permissions
并检查使脚本可执行Allow executing file as program
。
现在,脚本应该会作为新的菜单项出现在 nautilus 上下文菜单中。只需右键单击链接并选择 即可Scripts --> whatever-you-named-your-script
。
答案2
Glutanimate 的答案很棒。如果您不想要附加选项“使用默认应用程序打开文件”和“打开消息框以复制文件路径”(您可以通过右键单击链接并选择属性,然后在那里复制链接目标来执行此操作),请使用以下脚本。这有点像黑客行为,因为我只采用了原始脚本并删除了我不想要的内容。
分享以防对别人有帮助:
#!/bin/bash
#Title=open-the-link-target-in-nautilus
#Title[fr]=ouvrir-le-repertoire-cible-dans-nautilus
#==============================================================================
# open-the-link-target-in-nautilus
#
# revision: snowguy
# version : v2012091401
# author : SLK
# revision based on version : v2011051501
# license : Distributed under the terms of GNU GPL version 2 or later
#
#==============================================================================
#
# description :
# nautilus-script :
# opens the target of a symbolic link of the selected object; if
# the target of the symbolic link is a file, opens the parent folder
#
# informations :
# - a script for use (only) with Nautilus.
# - to use, copy to your ${HOME}/.gnome2/nautilus-scripts/ directory.
#
# WARNINGS :
# - this script must be executable.
# - package "zenity" must be installed
#
#==============================================================================
#==============================================================================
# CONSTANTS
# 0 or 1 - 1: doesn't open but displays a message
DRY_RUN=0
#------> some labels used for zenity [en]
z_title='open the link target in nautilus'
z_err_bin_not_found='not found\nEXIT'
z_no_object='no object selected\nEXIT'
z_info_target='path of the target'
z_choice_open_nautilus='open target in nautilus'
z_choice_open_file='open file with default application'
z_choice_display_filepath='open a messagebox to copy filepath'
#------> some labels used for zenity [fr]
#z_title='ouvrir le repertoire cible dans nautilus'
#z_err_bin_not_found='introuvable\nEXIT'
#z_no_object='aucun objet selectionne\nEXIT'
#z_info_target='chemin de la cible'
#z_choice_open_nautilus='ouvrir la cible dans nautilus'
#z_choice_open_file='ouvrir le fichier avec le programme par defaut'
#z_choice_display_filepath='ouvrir une boite de dialogue affichant le chemin du fichier'
#==============================================================================
# INIT VARIABLES
# may depends of your system
DIRNAME='/usr/bin/dirname'
GREP='/bin/grep'
NAUTILUS='/usr/bin/nautilus'
PERL='/usr/bin/perl'
READLINK='/bin/readlink'
XDG_OPEN='/usr/bin/xdg-open'
ZENITY='/usr/bin/zenity'
#==============================================================================
# FUNCTIONS
function check_bin
{
err=0
for bin in $* ; do
if [ ! -x "$bin" ] ; then
$ZENITY --error --title "$z_title" \
--text="$bin $z_err_bin_not_found"
err=1
fi
done
[ $err -eq 1 ] && exit 1
}
#==============================================================================
# MAIN
# lets check for required binaries :
[ -x "$ZENITY" ] || {
echo "[ERROR] $ZENITY not found : EXIT"
exit 1
}
check_bin "$DIRNAME" "$GREP" "$NAUTILUS" "$PERL" "$READLINK"
# lets check if object is selected :
[ "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" == "" ] && {
$ZENITY --error --title "$z_title" \
--text="$z_no_object"
exit 1
}
# retrieve the first object selected :
first_object=`echo "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" \
| $PERL -ne 'print;exit'`
# lets check if local path :
[ `echo "$first_object" | $GREP -c "^/"` -eq 0 ] && {
$ZENITY --error --title "$z_title" \
--text="[ERROR] $first_object has not a valid path\nEXIT"
exit 1
}
# retrieve the target path :
if [ -L "$first_object" ] ; then
# symbolic link
target=`$READLINK -f "$first_object"`
else
# not a symbolic link :
target="$first_object"
fi
if [ -d "$target" ] ; then
# target is a directory
target_to_open_in_nautilus="$target"
else
# target is a file, let's take the parent directory
target_to_open_in_nautilus=`$DIRNAME "$target"`
fi
### GO : let's open
$NAUTILUS --no-desktop "$target_to_open_in_nautilus"
exit 0
### EOF