Learn how to open a directory in terminal Linux and how to open a file in a directory in Linux terminal. Here is how to open file from terminal Ubuntu or open folder from terminal Ubuntu.
Open folder/directory from Ubuntu Terminal
You can open the folder/directory from Ubuntu terminal using cd command. The cd or change directory command allows you to change your directory, or in other words, open a new folder.
Note that when you open the Terminal, you are in your home directory. The following command will help you in opening the folder of your choice:
cd /path/to/file
To open a directory in a terminal, you use the cd command to change your current directory. This essentially opens that folder and places you in it.
Using cd command alone with no arguments, takes you back home (it takes you out from the folder).
It must be known to all that the tilde symbol (~) represents our home directory. You can use this symbol in the cd command to move to a folder in your /home/[user]/ directory.
You must note that the pwd command can be used to know the current directory. The pwd command stands for print working directory. If you want to know the exact directory path where you are currently. Simply run the pwd command to do so.
Using cd Command
- The / symbol with the cd command helps you in directly opening the root folder.
- The ‘..’ symbol with the cd command helps you in navigating up one directory level:
- The ‘-’ symbol with the cd command takes you in back to the previous folder you were in.
How To Open A File In Ubuntu Terminal
Once you have located the desired file to to open; to open a file in a directory in Linux terminal command, you can use any of the following commands:
- Using cat command.
- Using less command.
- Using more command.
- Open File Using cat Command
To open the file in terminal using cat command, execute the cat command as follows:
cat Filename
- Open File Using less Command
The less command also shows you the content of the file, but it allows you to view one page at a time. You can execute the less command as:
less Test.txt
It must be noted that when you execute the above command it will display the file content as a page at a time. To exit from the less command, press the ‘q’ key.
- Open File Using more Command
To display the display the file content as the width of the terminal, you can use the more command.The command can be executed in the following manner:
more Test.txt
Similarly, there are various other commands which can be used to display file content. For example, the nl command displays the file content with the line number.