translated

This commit is contained in:
geekpi 2017-05-05 09:54:10 +08:00
parent 284abf0658
commit 04be1b5285
2 changed files with 142 additions and 144 deletions

View File

@ -1,144 +0,0 @@
translating---geekpi
bd Quickly Go Back to a Parent Directory Instead of Typing “cd ../../..” Redundantly
============================================================
While navigating the file system via the command line on Linux systems, in order to move back into a parent directory (in a long path), we would normally issue the [cd command][1] repeatedly (`cd ../../..`) until we land into the directory of interest.
This can be so tedious and boring much of the time, especially for experienced Linux users or system administrators who carry out so many various tasks, therefore hope to discover shortcuts to ease their jobs while operating a system.
**Suggested Read:** [Autojump An Advanced cd Command to Quickly Navigate Linux Filesystem][2]
In this article, we will review a simple but helpful utility for quickly moving back into a parent directory in Linux with the help of bd tool.
bd is a handy utility for navigating the filesystem, it enables you to quickly go back to a parent directory without typing `cd ../../..` repeatedly. You can reliably combine it with other Linux commands to perform a few daily operations.
### How to Install bd in Linux Systems
Run the following commands to download and install bd under `/usr/bin/` using the [wget command][3], make it executable and create the required alias in your `~/.bashrc` file:
```
$ wget --no-check-certificate -O /usr/bin/bd https://raw.github.com/vigneshwaranr/bd/master/bd
$ chmod +rx /usr/bin/bd
$ echo 'alias bd=". bd -si" >> ~/.bashrc
$ source ~/.bashrc
```
Note: To enable case-sensitive directory name matching, set the `-s` flag instead of `-si` in the alias created above.
To enable autocomplete support, run these commands:
```
$ sudo wget -O /etc/bash_completion.d/bd https://raw.github.com/vigneshwaranr/bd/master/bash_completion.d/bd
$ sudo source /etc/bash_completion.d/bd
```
#### How to Use bd in Linux Systems
Assuming your currently in the top directory in this path:
```
/media/aaronkilik/Data/Computer Science/Documents/Books/LEARN/Linux/Books/server $
```
and you want to go to Documents directory quickly, then simply type:
```
$ bd Documents
```
Then to go straight into the Data directory, you can type:
```
$ bd Data
```
[
![Switch Between Directories Quickly](http://www.tecmint.com/wp-content/uploads/2017/03/Switch-Between-Directories-Quickly.png)
][4]
Switch Between Directories Quickly
Actually, bd makes it even more straight forward, all you need to do is just type bd <few starting letters>such as:
```
$ bd Doc
$ bd Da
```
[
![Quickly Switch Directories](http://www.tecmint.com/wp-content/uploads/2017/03/Quickly-Switch-Directories.png)
][5]
Quickly Switch Directories
Important: In case there are more than one directories with the same name up in the hierarchy, bd will move you into the closest without considering the immediate parent as explained in the example below.
For instance, in the path above, there are two directories with the same name Books, if you want to move into:
```
/media/aaronkilik/Data/ComputerScience/Documents/Books/LEARN/Linux/Books
```
Typing bd books will take you into:
```
/media/aaronkilik/Data/ComputerScience/Documents/Books
```
[
![Move to 'Books' Directory Quickly](http://www.tecmint.com/wp-content/uploads/2017/03/Move-to-Directory-Quickly.png)
][6]
Move to Books Directory Quickly
Additionally, using bd within backticks in the form ``bd <letter(s)>`` prints out the path minus changing the current directory, so you can use ``bd <letter(s)>`` with other common Linux commands such as [ls][7], [echo][8] etc..
In the example below, am currently in the directory, /var/www/html/internship/assets/filetree and to print the absolute path, long-list the contents and sum up the size of all files in the directory html without moving into it, I can just type:
```
$ echo `bd ht`
$ ls -l `bd ht`
$ du -cs `bd ht`
```
[
![Switch Directory with Listing](http://www.tecmint.com/wp-content/uploads/2017/03/Switch-Directory-with-Listing.png)
][9]
Switch Directory with Listing
Find out more about bd tool on Github: [https://github.com/vigneshwaranr/bd][10]
Thats all! In this article, we showed reviewed a handy way of [quickly navigating the filesystem in Linux][11]using bd utility.
Have your say via the feedback form below. Plus, do you know of any similar utilities out there, let us know in the comments as well.
--------------------------------------------------------------------------------
作者简介:
Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.
---------------
via: http://www.tecmint.com/bd-quickly-go-back-to-a-linux-parent-directory/
作者:[Aaron Kili ][a]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:http://www.tecmint.com/author/aaronkili/
[1]:http://www.tecmint.com/cd-command-in-linux/
[2]:http://www.tecmint.com/autojump-a-quickest-way-to-navigate-linux-filesystem/
[3]:http://www.tecmint.com/10-wget-command-examples-in-linux/
[4]:http://www.tecmint.com/wp-content/uploads/2017/03/Switch-Between-Directories-Quickly.png
[5]:http://www.tecmint.com/wp-content/uploads/2017/03/Quickly-Switch-Directories.png
[6]:http://www.tecmint.com/wp-content/uploads/2017/03/Move-to-Directory-Quickly.png
[7]:http://www.tecmint.com/tag/linux-ls-command/
[8]:http://www.tecmint.com/echo-command-in-linux/
[9]:http://www.tecmint.com/wp-content/uploads/2017/03/Switch-Directory-with-Listing.png
[10]:https://github.com/vigneshwaranr/bd
[11]:http://www.tecmint.com/autojump-a-quickest-way-to-navigate-linux-filesystem/
[12]:http://www.tecmint.com/author/aaronkili/
[13]:http://www.tecmint.com/10-useful-free-linux-ebooks-for-newbies-and-administrators/
[14]:http://www.tecmint.com/free-linux-shell-scripting-books/

View File

@ -0,0 +1,142 @@
bd - 快速返回到父目录而不用冗余地输入 “cd ../../ ..”
============================================================
在 Linux 系统上通过命令行切换文件夹时,为了回到父目录(长路径),我们通常会重复输入[ cd 命令][1]`cd ../../..`),直到进入感兴趣的目录。
对于经验丰富的 Linux 用户或需要进行各种不同任务的系统管理员而言,这可能非常乏味,因此希望在操作系统时有一个快捷方式来简化工作。
**建议阅读:** [Autojump - 一个快速浏览 Linux 文件系统的高级 “cd” 命令][2]
在本文中,我们将在 bd 工具的帮助下,用这个简单而有用的工具快速回到 Linux 中的父目录。
bd 是用于切换文件夹的便利工具,它可以使你快速返回到父目录,而不必重复键入 `cd ../../..` 。 你可以可靠地将其与其他 Linux 命令组合以执行几个日常操作。
### 如何在 Linux 中安装 bd
运行下面的命令,使用[ wget 命令][3]下载并安装 bd 到 `/usr/bin/` 中,添加执行权限,并在 `~/.bashrc` 中创建需要的别名:
```
$ wget --no-check-certificate -O /usr/bin/bd https://raw.github.com/vigneshwaranr/bd/master/bd
$ chmod +rx /usr/bin/bd
$ echo 'alias bd=". bd -si" >> ~/.bashrc
$ source ~/.bashrc
```
注意:要启用大小写敏感的目录名匹配,在上面创建的别名中,设置  `-s` 标志而不是 `-si` 标志。
要启用自动补全支持,运行这些命令:
```
$ sudo wget -O /etc/bash_completion.d/bd https://raw.github.com/vigneshwaranr/bd/master/bash_completion.d/bd
$ sudo source /etc/bash_completion.d/bd
```
#### 如何在 Linux 中使用 bd
假设你目前在这个路径的顶层目录:
```
/media/aaronkilik/Data/Computer Science/Documents/Books/LEARN/Linux/Books/server $
```
你想要快速进入 “Documents” 目录,只要输入:
```
$ bd Documents
```
接着直接进入到 Data 目录,你可以输入:
```
$ bd Data
```
[
![Switch Between Directories Quickly](http://www.tecmint.com/wp-content/uploads/2017/03/Switch-Between-Directories-Quickly.png)
][4]
目录间快速切换
实际上bd 让它变得更加直接,你要做的是输入 “bd <开头几个字母>”,比如:
```
$ bd Doc
$ bd Da
```
[
![Quickly Switch Directories](http://www.tecmint.com/wp-content/uploads/2017/03/Quickly-Switch-Directories.png)
][5]
快速切换目录
重要如果层次结构中有不止一个具有相同名称的目录bd 将会移动到最接近的目录,而不考虑最接近的父目录,如下面的例子那样。
例如,在上面的路径中,有两个名称相同的目录 Books如果你想移动到
```
/media/aaronkilik/Data/ComputerScience/Documents/Books/LEARN/Linux/Books
```
输入 “bd Books” 会进入:
```
/media/aaronkilik/Data/ComputerScience/Documents/Books
```
[
![Move to 'Books' Directory Quickly](http://www.tecmint.com/wp-content/uploads/2017/03/Move-to-Directory-Quickly.png)
][6]
快速进入 Books 目录
另外,在引号中使用 bd 如 ``bd <letter(s)>`` 会打印出路径而不更改当前目录,所以你可以与其他常见的 Linux 命令,如 [ls][7][echo][8] 等一起使用 ``bd <letter(s)>` 。
在下面的例子中,当前在 /var/www/html/internship/assets/filetree 目录中,要打印出绝对路径、详细列出内容、统计目录 html 中所有文件的大小,你不必进入它,只需要键入:
```
$ echo `bd ht`
$ ls -l `bd ht`
$ du -cs `bd ht`
```
[
![Switch Directory with Listing](http://www.tecmint.com/wp-content/uploads/2017/03/Switch-Directory-with-Listing.png)
][9]
列出切换的目录
要在 Github 上了解更多关于 bd 的信息:[https://github.com/vigneshwaranr/bd][10]
就是这样了!在本文中,我们展示了使用 bd 程序[在 Linux 中快速切换文件夹][11]的便捷方法。
通过下面的反馈栏单发表你的看法。此外,你还知道其他类似的工具么,在评论中让我们知道。
--------------------------------------------------------------------------------
作者简介:
Aaron Kili是一名 Linux 和 F.O.S.S 的爱好者,未来的 Linux 系统管理员、网站开发人员,目前是 TecMint 的内容创作者,他喜欢用电脑工作,并乐于分享知识。
---------------
via: http://www.tecmint.com/bd-quickly-go-back-to-a-linux-parent-directory/
作者:[Aaron Kili ][a]
译者:[geekpi](https://github.com/geekpi)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:http://www.tecmint.com/author/aaronkili/
[1]:http://www.tecmint.com/cd-command-in-linux/
[2]:http://www.tecmint.com/autojump-a-quickest-way-to-navigate-linux-filesystem/
[3]:http://www.tecmint.com/10-wget-command-examples-in-linux/
[4]:http://www.tecmint.com/wp-content/uploads/2017/03/Switch-Between-Directories-Quickly.png
[5]:http://www.tecmint.com/wp-content/uploads/2017/03/Quickly-Switch-Directories.png
[6]:http://www.tecmint.com/wp-content/uploads/2017/03/Move-to-Directory-Quickly.png
[7]:http://www.tecmint.com/tag/linux-ls-command/
[8]:http://www.tecmint.com/echo-command-in-linux/
[9]:http://www.tecmint.com/wp-content/uploads/2017/03/Switch-Directory-with-Listing.png
[10]:https://github.com/vigneshwaranr/bd
[11]:http://www.tecmint.com/autojump-a-quickest-way-to-navigate-linux-filesystem/
[12]:http://www.tecmint.com/author/aaronkili/
[13]:http://www.tecmint.com/10-useful-free-linux-ebooks-for-newbies-and-administrators/
[14]:http://www.tecmint.com/free-linux-shell-scripting-books/