Connect with us
Introduction to Navigation Commands in Linux
With this tutorial, you’ll learn folder navigation with navigation commands in Linux (
ls) command line. To follow along with me you’ll need a Linux virtual machine ready to go. If you don’t have one, no worries, search for any tutorial on building an Ubuntu VM with Virtualbox. Before going to navigation commands in Linux you need to know the basics about Linux Terminal
Getting Started with Terminal
First, open up the terminal by searching it in the application list. To get oriented with which folder you’re currently in, type
pwd. “Pwd” stands for “Print Working Directory”.
We’re in the user’s home folder, which is shown by the tilde symbol ( ~ ). Tilde is a shortcut that always refers to the current user’s home directory. This section in blue will also show the path of whatever folder you’re currently in. The dollar sign prompt means the shell is ready to accept your typed commands. You can type
--help after almost any command to get usage info about it.
Bash Command Structure
In Bash, which is the default command-line shell for most Linux distributions the structure goes like this: you first have a command, with one or more flags that modify the command’s behavior, followed by one or more target files. Depending on the program, you can use individual flags or group them with a single hyphen. Sometimes you’ll see the structure shown like this.
Bash Command Structure
command -a -b -c <targets>
command -abc <targets>
command [OPTIONS]… [FILES]…
LS (List Command)
Let’s go over the
ls, or list command now. LS is very similar to expanding a folder in tree view in the file manager to see what’s inside without actually entering that folder.
There are many flags that change the output of this navigation commands in Linux.
ls -1shows one item per line
ls -lshows detailed permissions, file sizes, number of items, and timestamps
ls -ashows all files, including hidden ones that begin with a dot
If your screen is getting full of text, type
clear, or press
CTRL+L to clear it. You can chain flags together, such as
ls -1a, to combine the behaviors of both. Passing multiple folders, such as both Desktop and Documents will show the contents of them all.
System Manual for LS Command
The possibilities go on and on, which you can further learn by the reading the system manuals. You can type
man ls to see it for this navigation commands in Linux.
Navigate through the Manual page
To navigate through the manual pages, use the “arrow keys” to scroll up and down one line at a time, or “page down” and “page up” to scroll one page at a time.
This “R flag” says it lists subdirectories recursively.
Let’s open up a new tab with
Ctrl+Shift+T to check it out. You can see,
ls -R gives us all the subfolders and files in the directory we’re in. Now type
exit to close this shell.
To go back to the beginning of the manual page, type
1G to jump to line one of the manual.
How to search for a text
To search for text, type forward-slash ( / ) followed by the search query. If you search for a word with multiple occurrences, it’ll highlight them all. You can simply press
N to search forward, and
Shift+N, to search backward. Type
q to quit.
List Contents in Another Directory Using The Navigation Commands in Linux Command Line
If you wanna list the contents of another directory in the file manager, You have to click through several folders to get there in either tree or tile view. In the command line, you can pass
ls [relative path] and use the “tab key” to autocomplete the command. Autocompletion needs enough characters to differentiate between similar names.
Hitting tab a couple of times with just the letter “D” will suggest folders beginning with that letter. Feeding it more characters narrows it down to the one that you want.
You can also pass
ls [absolute path] to a directory that works no matter which folder you’re in. As you can see I’ve got an image on the Pictures called “Image.jpg”.
If there’s a file or folder with a long name, you can drag it from the file manager into the terminal to save some typing navigation commands in Linux.
Note: The spaces in this folder name are little important. If you type it as is, LS will think you’re trying to show two separate folders: “Linux” and “Tutorials”, which don’t exist. Use up arrow to go back and escape the space characters with back-slashes ( \ ), or by using quotes, but never both.
CD (Change Directory Command)
To go to a different folder, use
cd, or the change directory command with tab completion to get where you want. Notice that when you’re in a directory, you can use ls by itself. To jump back to the folder you just came from, type
cd -. What we just did is similar to entering this folder in a file manager, and clicking the back button. If you type
cd - again, you will wind up in the original folder again.
cd by itself will take you back to your home directory no matter where you are, which is the same as typing
If you wanna go up a directory, type
cd .. “Dot dot” is a special folder that points back to its parent. There’s also a special folder called “dot” that points to the current folder you’re in and doesn’t change your location. We can see them using the
-1a flag with
The following screenshot shows all CD navigation commands in Linux executed in the terminal.
You may wonder what the use of a single dot folder is, but that’s something I’ll show you in another tutorial. So that’s just about everything you need to know to navigation commands in Linux like a pro – I believe you have found them as reminders and helpful. In addition to the ones in this tutorial, if you have any other ideas you want to inform the Linux community, add a comment below and let us know what Linux commands you’d like to learn.
Follow us on:
Disclosure: Your support helps keep the site running! We earn a referral fee for some of the services we recommend on this page. Learn More
Contribute to Linux Talks
Do you have news that the Linux community should know about? Use the form below to submit your story. Our moderators review every submission.