如何在Linux中将终端打开到特定目录

By default, new Terminal windows open to your Home directory. However, if there’s another directory you use often that you want immediate access to when you open the Terminal, there’s an easy way to set this up.

默认情况下,新的终端窗口会打开到您的主目录。 但是,如果打开终端时经常使用另一个要立即访问的目录,则有一种简便的方法来进行设置。

The .bashrc file in your Home directory contains commands that run when you open a Terminal window. So, we can add a cd command to change to a specific directory as soon as the Terminal window opens. To do this, press Ctrl+Alt+T to open a Terminal window. As we mentioned, you are in your Home directory by default, which is where you want to be right now.

主目录中的.bashrc文件包含打开“终端”窗口时运行的命令。 因此,一旦“终端”窗口打开,我们可以添加cd命令以更改到特定目录。 为此,请按Ctrl + Alt + T打开“终端”窗口。 如前所述,默认情况下,您位于主目录中,该目录现在是您想要的位置。

We’re going to edit the .bashrc file, so type the following command to open it. You can use whichever text editor you want to use, but we’re going to use gedit in our example.

我们将编辑.bashrc文件,因此键入以下命令将其打开。 您可以使用任何想要使用的文本编辑器,但是在示例中我们将使用gedit。

gedit .bashrc

01_opening_bashrc_file

Scroll to the bottom of the .bashrc file and add the following command.

滚动到.bashrc文件的底部,然后添加以下命令。

cd ~/HTGArticles

The tilde character (~) is a shortcut for your Home directory, which in our example, is /home/lori. So, the full path for the directory in the above command is /home/lori/HTGArticles.

代字号(〜)是主目录的快捷方式,在我们的示例中为/home/lori 。 因此,以上命令中目录的完整路径为/home/lori/HTGArticles 。

Replace ~/HTGArticles with the directory you want to open when you open a Terminal window.

在打开“终端”窗口时,将~/HTGArticles替换为您要打开的目录。

The following line is a comment we added above the cd command, explaining what the command is doing. You don’t have to add a comment, but it helps make the .bashrc file easier to understand. The pound sign (#) at the beginning of a line indicates that line is a comment.

下一行是我们在cd命令上方添加的注释,解释了该命令正在执行的操作。 您无需添加注释,但是它有助于使.bashrc文件更易于理解。 行首的井号(#)表示该行是注释。

# Open to HTGArticles directory

Once you’ve added the command to the file, click “Save” in the upper-right corner of the window to save the file.

将命令添加到文件后,单击窗口右上角的“保存”以保存文件。

02_adding_cd_command_to_bashrc

Close the .bashrc file by clicking the “X” button in the upper-left corner of the window.

单击窗口左上角的“ X”按钮,关闭.bashrc文件。

03_closing_gedit

You must restart the Terminal window for this change to take effect. To close the Terminal window, either type exit at the prompt and press Enter, or click the “X” button in the upper-left corner of the window.

您必须重新启动终端窗口,此更改才能生效。 要关闭“终端”窗口,请在提示符下键入exit并按Enter,或单击窗口左上角的“ X”按钮。

04_closing_terminal_window

Now, press Ctrl+Alt+T to open the Terminal again. You are immediately in the directory you specified in the .bashrc file. You can still navigate to any other directory, but this is helpful if you work in this directory the most.

现在,按Ctrl + Alt + T再次打开终端。 您将立即在.bashrc文件中指定的目录中。 您仍然可以导航到任何其他目录,但是如果您最经常在此目录中工作,这将很有帮助。

05_terminal_window_open_to_specific_directory

If you use both Nautilus and the Terminal to work with files, you can open a specific directory in Nautilus from the Terminal as well as open a Terminal window to a specific directory from Nautilus.

如果同时使用Nautilus和Terminal来处理文件,则可以从Terminal在Nautilus中打开特定目录,也可以从Nautilus打开到特定目录的Terminal窗口

参考资料

在特定目录启动终端

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: Linux可以使用su命令来切换用户,例如:su username,其中username是要切换到的用户的用户名。如果要切换到root用户,可以使用su命令,不过需要输入root用户的密码。另外,还可以使用sudo命令来以其他用户的身份执行命令,例如:sudo command。 ### 回答2: 在Linux系统中,可以使用`su`命令来切换用户。 `su`命令用于切换到指定的用户身份,语法为:`su [选项] [用户名]`。其中,`用户名`表示要切换到的用户账户名称。 如果不指定用户名,默认切换到root用户。在切换用户时,需要输入目标用户的密码进行验证。 若要切换到root用户,可以直接输入`su`命令并按Enter键,然后输入root用户的密码进行验证即可。 若要切换到其他用户,可使用命令`su 用户名`,将`用户名`替换为要切换到的用户账户名称,然后按Enter键,再输入目标用户的密码进行验证。 在切换用户后,当前所在的工作目录会保持不变。若需要切换到目标用户的主目录,可使用`su - 用户名`命令。 如果要以其他用户的身份运行特定的命令,可以使用`sudo`命令。`sudo`命令可在不切换用户身份的情况下,使用其他用户的权限运行指定的命令。 要使用`sudo`命令,需要在用户账户中将该用户添加到sudo用户组中,并且需要输入当前用户的密码进行验证。使用`sudo`执行命令时,不用输入目标用户的密码。 总之,Linux系统中通过`su`命令可以切换到指定的用户身份,而`sudo`命令可以以其他用户的身份运行特定命令。 ### 回答3: 在Linux系统中,切换用户是一种非常常见的操作。我们可以使用命令行或者图形界面来切换用户。 在命令行中,切换用户的命令是"su"。我们可以通过以下步骤切换用户: 1. 打开终端或者命令行窗口。 2. 输入"su"命令,然后敲击回车键。 3. 系统会提示输入要切换到的用户的密码。输入正确的密码后,再次敲击回车键。 4. 如果密码正确,系统会切换到指定的用户,并且命令行提示符会相应地改变为新用户的用户名。 例如,如果我们想切换到用户"john",可以在命令行中输入"su john",然后输入密码进行验证。 另外,我们也可以使用"sudo"命令以其他用户或者管理员的身份执行特定命令。例如,如果我们想以root用户的身份执行一个需要管理员权限的命令,可以在命令行中输入"sudo 命令",然后输入当前用户的密码进行验证。 在图形界面中,切换用户的过程相对简单。我们可以通过以下步骤切换用户: 1. 如果当前用户处于登录状态,点击桌面右上角的用户图标。 2. 在弹出的菜单中,选择要切换到的用户。 3. 输入选择的用户的密码进行验证。 4. 系统会注销当前用户,并且登录到新用户的账户。 这种方式适用于多用户登录的情况,可以方便地切换不同的用户账户。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值