DEV Community

Cover image for Command Line Navigation For Beginners
Sello Moneatse
Sello Moneatse

Posted on

Command Line Navigation For Beginners

Some commands in use on a local machine

Navigating the command line, or "shell" is the process of navigating and manipulating the file system of a Unix-based operating system through the command line interface.

This can be a bit intimidating for beginners, but with a little bit of practice and understanding, it becomes a powerful tool for managing your computer and automating tasks.
In this article, I'll share with you, some basic shell navigation concepts and commands that can help you get started.

Before diving into the commands, it's important to understand a few basic concepts. The file system in a Unix-based operating system is organized into a hierarchical tree structure, with the root directory (/) at the top. Directories can contain other directories (subdirectories) and files and so on.

1. pwd

The pwd command stands for "print working directory". It tells you the directory that you are currently in. For example:

Command Line Input: pwd
Command Line Output: /Users/username/documents

Enter fullscreen mode Exit fullscreen mode

2. ls

The ls command lists the files and directories in the current directory. For example:

Command Line Input: ls
Command Line Output: file1.txt file2.txt folder1/ folder2/
Enter fullscreen mode Exit fullscreen mode

You can also use ls -l to see more detailed information about the files and directories, such as permissions and timestamps.

Command Line Input: ls -l
Command Line Output: -rw-r--r-- 1 username staff 0 Jan 1 12:00 file1.txt
Enter fullscreen mode Exit fullscreen mode

3. cd

The cd command stands for "change directory". It allows you to navigate to different directories on your computer. For example:

Command Line Input: cd Documents/
Command Line Output: (no output, but now you are in the Documents directory)
Enter fullscreen mode Exit fullscreen mode

You can also use the cd command to navigate to different directories with the use of .. for the parent directory and ~ for the home directory.

Command Line Input: cd ..
Command Line Output: (no output, but now you are in the parent directory of where you were)
Command Line Input: cd ~
Command Line Output: (no output, but now you are in the home directory)
Enter fullscreen mode Exit fullscreen mode

4. mkdir

The mkdir command stands for "make directory". It allows you to create new directories. For example:

Command Line Input: mkdir newfolder
Command Line Output: (no output, but a new folder named "newfolder" is created in the current directory)
Enter fullscreen mode Exit fullscreen mode

5. touch

The touch command allows you to create new empty files. For example:

Command Line Input: touch newfile.txt
Command Line Output: (no output, but a new file named "newfile.txt" is created in the current directory)
Enter fullscreen mode Exit fullscreen mode

6. cp

The cp command stands for "copy". It allows you to copy files or directories from one location to another. For example:

Command Line Input: cp file1.txt /path/to/destination
Command Line Output: (no output, but a copy of "file1.txt" is now in the specified destination)
Enter fullscreen mode Exit fullscreen mode

7. mv

The mv command stands for "move". It allows you to move files or directories from one location to another. For example:

Command Line Input: mv file1.txt /path/to/destination
Command Line Output: (no output, but "file1.txt" is now in the specified destination)
Enter fullscreen mode Exit fullscreen mode

8. rm

The rm command stands for "remove". It allows you to delete files. For example:

Command Line Input: rm file1.txt
Command Line Output: (no output, but the file "new_file.txt" is deleted from the current directory)
Enter fullscreen mode Exit fullscreen mode

9. clear

The clear command is used to clear the terminal screen including its scrollback buffer.

Command line input: clear
Command line output: (no output, but the terminal screen is cleared)
Enter fullscreen mode Exit fullscreen mode

10. rmdir

The rmdir (remove directory) command is used to delete an empty directory.

 Command line input: rmdir directory1
Command line output: (no output, but directory1 is removed from the current directory)
Enter fullscreen mode Exit fullscreen mode

11. echo

The echo command is used to display a message on the screen. For example, to display the message "Hello, World!", you would use the command echo "Hello, World!".

Command Line Input: echo "Hello, World!"
Command Line Output: Hello, World!
Enter fullscreen mode Exit fullscreen mode

12. cat

The cat command is used to display the contents of a file on the screen. For example, to display the contents of the file "example.txt", you would use the command cat example.txt.

Command Line Input: cat example.txt
Command Line Output: This is the contents of the file example.txt
Enter fullscreen mode Exit fullscreen mode

13. whoami

The whoami command is used to display the current user.

Command Line Input: whoami
Command Line Output: sellocodes

Enter fullscreen mode Exit fullscreen mode

And that brings us to the end of the article guys,
these are just a few of the many commands available for shell navigation that one can use to to accomplish even more advanced tasks. Remember to always be careful when using shell commands, as they can potentially cause irreversible changes to your file system if used improperly. If you found this article helpful please leave a like, comment and don't forget to share and follow for more content. On to the next one.
Happy DevLife 😎

Oldest comments (0)