How to navigate using Terminal Window in Ubuntu and Linux

new terminal in Ubuntu

new terminal window in Ubuntu

Navigation is one of the first things you need to learn in Ubuntu if you want to start going beyond clicking and go beyond user interface. I will try to explain the most important uses and options of these basic commands in simple language here, please let me know in the comments if you need any clarification or just want to leave some feedback. CLI or Command Line Interface is the most important part of the Linux. First, open a terminal window and we will start learning how to navigate from one directory (folder) to another, do various actions on file and directory structure.

Now, these commands are pretty much standard across most Linux, even Unix distributions.

1) pwd command. Once you are in the Terminal, type pwd and press Enter key- it will show you where you are right now. pwd stands for “print working directory”. So, if I am in a home directory of the user hack, it will show /home/hack

So, any time you want to know where you are located, type pwd and press Enter. Now keep in mind that it may show you location as “~” in it. “~” symbol stands for home directory, so if you are user hack, it will show you “~” as the directory instead of /home/hack as it is your home directory. pwd command has two options, but they are irrelevant for you right now. Never the less, you can experiment. For reference, they are -L and -P. So, if you type pwd -L it will show the logical path, such as symbolic link. If you type in pwd -P, it will show the physical path and will not show the symbolic link if there is one. You can also do pwd –logical or pwd –physical which are the same commands but with more typing.  As with some other commands, it also has pwd –help and pwd –version. Type those in and see what they do. –help may give you even more information.

2) cd command. Just like in Windows command prompt window, cd changes the directories. Usually new terminal window takes you directly to your home directory. Use cd command to go somewhere else. Here are some examples that you can try:

cd Desk (now hit “tab” key to see autocomplete in action. It should auto-complete your directory for you and show “cd Desktop“). If not, perhaps you are not in your home directory now. Then try cd ~/Desktop . Press Enter key for the command to execute. Remember, “~” takes you to the home directory. To get back to your home directory simply type cd or cd ~ .

To navigate to root directory, type in cd / . This is the main directory. When you type “cd /“, you can try hitting tab twice. It will show you all of the folders located in the root directory. Start typing cd /va and press tab – it will autocomplete the folder for you and show cd /var . This may be not the best part for me to show how auto-completion works, but if you learn it early it will save you a lot of time down the road. :)

So browse around, look at the file structure, if you get lost just go back to home (cd ~) or root directory (cd /) and start all over.

You can also use relative paths. For instance, go to your Desktop directory (cd ~/Desktop). If you want to go back to your home directory, or just one directory down to /home/hack, you can just type in “cd ..” with no quotes. two dots represent one directory down. One dot represents current directory. So, typing cd . will just keep you where you are. What would you need to do to get to /home? either cd /home or cd ../.. from /home/hack/Desktop. you can go as many directories back as you need to. cd ../../.. would take you to the root folder in this case.

Now just remember cd command – c for change, d for directory. So to Change Directory use cd.

3) ls command. ls stands for list. It is the same command as “dir” in Windows Command Prompt window. It lists the content of the current folder. To see all of files and directories of the folder you are in simply type ls and press Enter. You don’t need to navigate to other folders in order to see the files. Just type ls /var to see the contents of the folder /var. ls /.. to see the files and directories in one folder down. It does come with a lot of options. I will list some here for reference, but the one you may use the most in the future is ls -l

ls -l stands for long list, it shows more information than the regular ls command. It shows things like the file/directory owner and permissions.

ls -r lists the files and folders in reverse order.

There are many options that you probably will not use right now or at all. To see the full list type in man ls . man command stands for manual. Whenever you need any information on the command and how to use it, just refer to the documentation. Say you need more information on how to use cd command. Just type in man cd and it will show you the information.

One last thing I will not for this command is something that I use a lot and usually it doesn’t get listed in many manuals. You can list just the files of a certain filetypes such as ls *.php with show all .php files in the folder. You can also mask for names and other things, such as ls a* will show you all the files and folders starting with letter a.

 

This is it for navigation. Now practice, look around the folders, not too much fun but at least you know how to do so now. I will try to cover the file and directory management commands some time soon. Such as creating and deleting, copying and moving, etc.


One Response to “How to navigate using Terminal Window in Ubuntu and Linux

Leave a Reply