在我的桌面上我创建了一个名为“Files”的文件夹,我想知道如何通过 shell 脚本访问该文件夹
在 Linux 文件系统中使用 bash 时,您可以通过多种方式导航到主目录:
到达主目录后,一切都很容易,包括到达桌面。
The ~
or $HOME
reference: In Linux based systems the keyword ~
or $HOME
refers to the home directory of the computer.
例如,假设您当前位于 /bin
,如果您知道您的用户名,则导航到主页:
$ cd /home/yourusername
#The directory is now switched to :
$ pwd #This command stands for print working directory
'/home/yourusername'
现在您可以通过以下方式进行选择:(再次假设您位于 /bin
中)
$ cd $HOME
$ pwd
'/home/yourusername'
#Alternatively
$ cd /bin
$ cd ~
$ pwd
'/home/yourusername'
这些快捷方式让您无需编写太多内容即可回家,甚至值得推荐。
现在,对于您的问题,您可以通过以下方式轻松导航到您的文件夹:
cd ~/Desktop/Files/
我是一名优秀的程序员,十分优秀!