欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

linux查看单个目录大小_如何在Linux中使用单个命令创建新目录并对其进行更改...

程序员文章站 2022-06-15 17:14:11
...
linux查看单个目录大小_如何在Linux中使用单个命令创建新目录并对其进行更改...

linux查看单个目录大小

linux查看单个目录大小_如何在Linux中使用单个命令创建新目录并对其进行更改...

If you spend any time in the Terminal at all, you probably use the mkdir command to create a directory, and then the cd command to change to that directory right after. However, there is a way to do both of those actions with one command.

如果您根本mkdir终端上花费任何时间,则可能使用mkdir命令创建目录,然后使用cd命令立即更改为该目录。 但是,有一种方法可以通过一个命令来完成这两项操作。

You can run two commands at once on the command line manually, but we’ll show you how to add a line to the .bashrc file that will combine the mkdir command and the cd command into one custom command you can type with a directory name.

您可以手动在命令行上一次运行两个命令,但是我们将向您展示如何向.bashrc文件中添加一行,该行将把mkdir命令和cd命令组合为一个您可以使用目录名称键入的自定义命令。

The .bashrc file is a script that runs every time you open a Terminal window by pressing Ctrl+Alt+T or open a new tab in a Terminal window. You can add commands to the .bashrc file that you want to run automatically every time you open a Terminal window.

.bashrc文件是一个脚本,每次您通过按Ctrl + Alt + T或在“终端”窗口中打开新选项卡打开“终端”窗口时运行。 您可以将命令添加到要在每次打开“终端”窗口时自动运行的.bashrc文件。

To edit the .bashrc file, we’re going to use gedit. Type the following command at the prompt.

要编辑.bashrc文件,我们将使用gedit。 在提示符下键入以下命令。

gedit ~/.bashrc

You can use any text editor you’re comfortable with, like vi or nano. Simply replace “gedit” in the above command with the command to run your chosen text editor.

您可以使用任何您喜欢的文本编辑器,例如vinano 。 只需将上述命令中的“ gedit”替换为运行所选文本编辑器的命令即可。

linux查看单个目录大小_如何在Linux中使用单个命令创建新目录并对其进行更改...

Scroll to the bottom of the .bashrc file and add the following line to the end of the file. We recommend you copy the line below and paste it into the .bashrc file.

滚动到.bashrc文件的底部,并将以下行添加到文件末尾。 我们建议您复制下面的行并将其粘贴到.bashrc文件中。

mkdircd(){ mkdir "$1" && cd "$1" ; }

This is essentially a function that will run the two commands one right after the other. The new custom command in our example is called mkdircd (you can actually name the command whatever you want) and it will run the mkdir command and then the cd command. The "$1" on both commands indicates that the commands will accept one value to operate on. In this case, it’s the name of the new directory.

从本质上讲,这是一个函数,它将一个接一个地运行两个命令。 在我们的示例中,新的自定义命令称为mkdircd (实际上您可以根据需要命名该命令),它将先运行mkdir命令,然后运行cd命令。 两个命令上的"$1"表示命令将接受一个值进行操作。 在这种情况下,它是新目录的名称。

You can add a comment above the command so you remember what the command does. Simply put a pound sign (#) at the beginning of the line, and then any description you want to add.

您可以在命令上方添加注释,以便记住命令的作用。 只需在行首添加一个井号(#),然后添加要添加的任何描述。

Click “Save”.

点击“保存”。

linux查看单个目录大小_如何在Linux中使用单个命令创建新目录并对其进行更改...

Close gedit (or other text editor) by clicking the “X” in the upper-left corner of the window.

单击窗口左上角的“ X”,关闭gedit(或其他文本编辑器)。

linux查看单个目录大小_如何在Linux中使用单个命令创建新目录并对其进行更改...

The setting you just added to the .bashrc file will not affect the current Terminal window session. You must close the Terminal window and log out and back in for the change to take affect. So, type exit at the prompt and press Enter or click the “X” button in the upper-left corner of the window. Then, log out and back in.

您刚刚添加到.bashrc文件中的设置不会影响当前的“终端”窗口会话。 您必须关闭“终端”窗口,然后注销并重新登录,以使更改生效。 因此,在提示符下键入exit,然后按Enter或单击窗口左上角的“ X”按钮。 然后,注销并重新登录。

linux查看单个目录大小_如何在Linux中使用单个命令创建新目录并对其进行更改...

Now, when you type the new command followed by a new directory name, the mkdircd function you created in the .bashrc file is called and the directory name “Test\ Directory” is passed to the two commands ( mkdir and cd ). The “Test Directory” directory will be created and you will be immediately taken to it.

现在,当您键入新命令后跟新的目录名时,将mkdircd在.bashrc文件中创建的mkdircd函数,并将目录名“ Test \ Directory”传递给两个命令( mkdircd )。 将创建“测试目录”目录,您将立即进入该目录。

linux查看单个目录大小_如何在Linux中使用单个命令创建新目录并对其进行更改...

If you manage your directories using the command line, this trick can save you some time.

如果使用命令行管理目录,此技巧可以为您节省一些时间。

翻译自: https://www.howtogeek.com/273304/how-to-make-a-new-directory-and-change-to-it-with-a-single-command-in-linux/

linux查看单个目录大小