Here are some basic Linux commands that will allow you to navigate easier within the terminal. These commands include
This is probably one of the most known commands since you really can’t get around a Linux terminal without it. There are some pretty neat tricks you can use to more quickly navigate directories. These include:
- Change current working directory (
pwd) to /path/to/dir
- Change back one directory level
- Change to your home directory at /home/username/
- Change to the directory you were in last
In order to talk about the next commands, you need to understand what a stack is. Imagine a spring-loaded plate holder like the ones you’d find at an all you can eat buffet (this is
dirs). The employees fill this plate holder by pushing a plate onto the plate holder. Then another plate is pushed onto the top of that plate (this is
pushd). This is repeated again and again and then soon, you have a full stack of plates. In order to get to any of the plates in the middle, you must pull the plate on top off, and then the next, and then the next until you get to the plate you want (this is
popd). This can continue until the stack is empty. This example is known as a Last In First Out (LIFO) or First In Last Out (FILO) data structure and that’s exactly what we’re dealing with here.
Now that you have an understanding of what a stack is, let’s chat about the next three commands:
This is the command you use to display the stack of currently remembered directories.
- View all directories on the stack with numbers
dirs +N OR dirs -N
- Display Nth directory counting left to right, OR right to left
cd `dirs +N`
- Change directory to dirs stack number N
This command will push a given directory to the top of the stack of remembered directories.
- Push the current directory onto the stack
- Push the /path/to/dir onto the stack
This command will pull the top directory off the stack of remembered directories.
- Pull the top direcotry (0) off of the stack, resulting in changing directory to (1)