Navigate in linux

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.

Basic 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/documents will change the current directory to the documents directory in the user home directory.
  • mkdir: This command allows you to create a new directory. For example, mkdir newdir will create a new directory called newdir in the current directory.
  • rmdir: This command allows you to delete an empty directory. For example, rmdir olddir will delete the directory called olddir if it is empty.
  • touch: This command allows you to create a new empty file. For example, touch newfile.txt will create a new empty file called newfile.txt in the current directory.

Special directories

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 cd ...

Tab completion

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.

Wildcards

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 .txt extension in the current directory.
  • ls file?.txt: This command will list all files with names that start with file and have a single character followed by .txt in the current directory. For example, it will match file1.txt but not file11.txt.
  • rm *: This command will delete all files in the current directory. Be careful with this command as it cannot be undone!

Additional resources

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:

  • The man command: This command allows you to view the manual pages for a command. For example, man ls will show you the manual page for the ls command, including all of its options and usage examples.
  • The --help option: Many commands support the --help option, which displays a short summary of the command’s usage and options. For example, ls --help will show you a summary of the options available for the ls command.
  • 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.