Introduction
If you’re a frequent user of the command line, you know how tedious it can be to type out “cd ../../..” every time you want to quickly go back to a parent directory. Fortunately, there is a much simpler way to do this. In this article, we’ll discuss how to use the “bd” command to quickly go back to a parent directory instead of typing out “cd ../../..” redundantly. We’ll also discuss some of the other useful features of the “bd” command.
bd – Quickly Go Back to a Parent Directory Instead of Typing “cd ../../..” Redundantly
The command “cd ../../..” can be replaced with the command “cd ../..” or “cd ..”. This will take you back two levels in the directory tree.
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 repeatedly (cd ../../..
) until we land in 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, and therefore hope to discover shortcuts to ease their jobs while operating a system.
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 the 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
On Debian-based and Arch Linux distributions, you can install bd from the default repositories using your package manager as shown.
$ sudo apt install bd [On Debian, Ubuntu and Mint] $ sudo pacman -S bd [On Arch Linux]
On other distributions, run the following commands to download and install bd under /usr/bin/
using the wget command, make it executable and create the required alias in your ~/.bashrc
file:
$ wget --no-check-certificate -O /usr/local/bin/bd https://raw.github.com/vigneshwaranr/bd/master/bd $ chmod +rx /usr/local/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 you are currently in the following long directory path:
/media/aaronkilik/Data/Computer Science/Documents/Books/LEARN/Linux/Books/server
and you want to go to the Documents directory quickly, then simply type:
$ bd Documents
Then to go straight into the Data directory, you can type:
$ bd Data
Actually, bd makes it even more straightforward, all you need to do is just type bd <few starting letters> such as:
$ bd Doc $ bd Da
Important: In case there is more than one directory 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
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, echo, 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`
Find out more about the bd tool on Github: https://github.com/vigneshwaranr/bd
That’s all! In this article, we showed reviewed a handy way of quickly navigating the filesystem in Linux using the 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.
If You Appreciate What We Do Here On Jassweb, You Should Consider:
Jassweb is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit Jassweb! to search or browse the thousands of published articles available FREELY to all.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
We are thankful for your never ending support.
If you’re tired of typing out cd ../../..
to quickly go back to a parent directory, there’s a much easier way. All you need to do is type cd ..\
and you’ll be taken back to the parent directory. This is a much simpler and faster way to navigate your file system.
If you want to go back even further, you can just keep adding periods to the command. For example, cd ../../
will take you two directories back. You can also use this command to quickly jump to a specific directory. For example, if you want to go to the parent directory of the current directory, you can type cd ../
.
Using this command is a great way to quickly navigate your file system without having to type out long and redundant commands. Give it a try and see how much time you can save!