我想从 txt 文件在桌面上创建快捷方式。我该怎么做?我使用 Ubuntu 19.10。谢谢。
尼克拉斯
答案1
假设您的文件路径为:/home/username/folder1/file.txt
并且您想要为该文件创建桌面快捷方式。
您需要打开终端并运行以下命令:
ln -s <absolute_path_of_the_file> <shortcut_path>
因此在这个例子中,它将是:
ln -s /home/username/folder1/file.txt /home/username/Desktop/
不要忘记包含文件的绝对路径,否则快捷方式将被破坏。
答案2
我发现通过 ubuntu 创建快捷方式太难了,所以我自己写了一个 shell 脚本。要将此 bash 脚本插入 bin 目录,请按照以下步骤操作:首先,打开终端。要启用桌面图标,必须先安装 gnome tweak 工具:
sudo apt-get install gnome-tweak-tool gnome-tweaks
在其中,搜索“图标”,然后进入桌面并启用名为“桌面符号”的选项。由于需要 aptitude,如果您尚未安装它,请通过终端安装它:
sudo apt-get install aptitude
通过终端中的 cd 命令导航到桌面创建一个新文件:
touch createshortcut.run
在文本编辑器中打开新创建的文件,并将“createshortcut.run”的源代码复制到其中。然后使用以下命令将文件移动到 /usr/bin:
sudo mv createshortcut.run /usr/bin/createshortcut
使文件可执行:
sudo chmod +x /usr/bin/createshortcut
至此所有事情都已完成!
要创建 .desktop 格式的快捷方式,您只需在终端的桌面文件夹中导航时执行 createshortcut(可以通过 cd 命令或右键单击桌面 -> “在此处打开终端”来完成),然后按照步骤操作!
创建快捷方式.运行:
#!/bin/bash
#set no results to false
nores=false
#get the name of the file to string
echo "Please enter the desired app name:"
read NAME
#empty line for overview
printf '\n'
#search for the name to get a package
echo "Packages found for ${NAME}:"
#search via aptitude
firstout=$(aptitude search '~i!~M '${NAME}'')
#get if the command returned empty string, if is so, search without the only user installed tag
if [[ $firstout ]]; then
#successfully, echo
echo $firstout
else
#search without these tags
secout=$(aptitude search ''${NAME}'')
if [[ $secout ]]; then
#echo the results
echo $secout
else
echo "No results"
#no res is true now
nores=true
fi
fi
#empty line for overview
printf '\n'
#chose one of them
echo "Enter one of the package names above"
echo "i.e. google-chrome-stable"
echo "If no result is shown, just enter the app name in lower case letters"
#get the command and icon to string
read COMM
#empty line for overview
printf '\n'
#if no result has been found, enter here path to an icon file
IMGP=${COMM}
if [ "$nores" = true ] ; then
echo "Please download an icon of the app and insert it in the folder /home/${USER}/icons"
echo "and enter the file's name"
echo "i.e. spotify.png"
#new empty line
printf "\n"
#create new direcory
mkdir /home/${USER}/icons
#list files in spotify
echo "All files in icons:"
ls /home/${USER}/icons
#read the image name
read IMGPL
#set imgp to new value
IMGP="/home/"${USER}"/icons/"${IMGPL}
fi
#set file name
FNAME=${NAME}.desktop
#create the new file
touch ${FNAME}
#write a desktop entry to the file
echo [Desktop Entry] >> ${FNAME}
echo Name=${NAME} >> ${FNAME}
echo Exec=${COMM} >> ${FNAME}
echo Icon=${IMGP} >> ${FNAME}
echo Type=Application >> ${FNAME}
echo "Categories=GTK;GNOME;" >> ${FNAME}
#file has been written
#now make the file executable with sudo
chmod +x ${FNAME}
#empty line for overview
printf '\n'
#last steps for the user
echo "Created new desktop shortcut for ${NAME}"
echo "Now right click ${FNAME} on the desktop and select:"
echo "Allow execution"
echo "Now your shortcut should be executable"
答案3
答案4
另一种方法是在桌面上设置快捷方式目录。
按住 Alt 键即可将文件从任何其他目录移动到快捷方式目录。这样就可以选择移动、复制或链接要移动的文件。
其中一个问题是,必须右键单击快捷方式并选择将打开该文件的软件。