The command line (also known as the terminal or shell) is a powerful tool that allows you to interact with your Linux operating system and perform tasks using commands. In this tutorial, we will cover the basics of navigating the command line in Linux.
Opening the terminal
To open the terminal in Linux, you can use the keyboard shortcut
Ctrl + Alt + T or search for “terminal” in your system’s app launcher. This will open a new terminal window where you can enter commands.
Here are some basic commands that you can use to navigate the command line in Linux:
pwd: This command displays the current directory (also known as the “working directory”) that you are in.
ls: This command lists the files and directories in the current directory.
cd: This command allows you to change the current directory. For example,
cd /home/user/documentswill change the current directory to the
documentsdirectory in the
mkdir: This command allows you to create a new directory. For example,
mkdir newdirwill create a new directory called
newdirin the current directory.
rmdir: This command allows you to delete an empty directory. For example,
rmdir olddirwill delete the directory called
olddirif it is empty.
touch: This command allows you to create a new empty file. For example,
touch newfile.txtwill create a new empty file called
newfile.txtin the current directory.
In Linux, there are several special directories that you can use to navigate the file system:
.: This refers to the current directory.
..: This refers to the parent directory of the current directory.
/: This refers to the root directory of the file system.
For example, to navigate to the root directory from any location, you can use the command
cd /. To navigate to the parent directory of the current directory, you can use the command
Linux supports tab completion, which allows you to type the first few letters of a command or file name and then press the
Tab key to automatically complete the rest. This can save time and reduce typing errors.
For example, if you type
cd do and then press
Tab, the terminal will automatically complete the command to
cd documents/ if there is a directory called
documents in the current directory. If there are multiple options, you can press
Tab multiple times to cycle through the options.
Linux supports wildcards, which are special characters that allow you to match multiple files or directories at once. The most common wildcards are
*, which matches any characters, and
?, which matches any single character.
Here are some examples of how you can use wildcards in the command line:
ls *.txt: This command will list all files with the
.txtextension in the current directory.
ls file?.txt: This command will list all files with names that start with
fileand have a single character followed by
.txtin the current directory. For example, it will match
rm *: This command will delete all files in the current directory. Be careful with this command as it cannot be undone!
There are many more commands and features available in the command line, and learning them can take time and practice. Here are some additional resources that can help you learn more about using the command line in Linux:
mancommand: This command allows you to view the manual pages for a command. For example,
man lswill show you the manual page for the
lscommand, including all of its options and usage examples.
--helpoption: Many commands support the
--helpoption, which displays a short summary of the command’s usage and options. For example,
ls --helpwill show you a summary of the options available for the
- The Linux documentation project: This website (https://www.tldp.org/) contains a wealth of documentation and tutorials on using the command line in Linux.
I hope this tutorial has helped you understand the basics of navigating the command line in Linux. With practice and exploration, you will become more comfortable and efficient at using this powerful tool.