- Published on
Basic Terminal Commands: ls, cd, and clear
- Authors
- Name
- Hieu Cao
Introduction
The terminal is a powerful tool for developers and system administrators, allowing precise control over the operating system. Among the essential commands for navigation and organization are ls
, cd
, and clear
. These commands help you list files, navigate directories, and maintain a clean workspace in the terminal.
This guide will introduce you to these basic commands, their options, and practical use cases to get you started.
ls
Command: List Directory Contents
The The ls
command displays the contents of a directory. It is one of the most commonly used commands to check files and directories.
Syntax
ls [options] [directory]
Common Usage
List Files in Current Directory
ls
Detailed List with File Permissions
ls -l
- Displays file details like permissions, ownership, size, and modification date.
Include Hidden Files
ls -a
- Lists files and directories, including hidden ones (starting with a dot
.
).
- Lists files and directories, including hidden ones (starting with a dot
Combine Options
ls -la
- Shows a detailed list, including hidden files.
Example
ls -lh
-h
: Displays file sizes in a human-readable format.
cd
Command: Change Directory
The The cd
command is used to navigate between directories in the terminal.
Syntax
cd [directory]
Common Usage
Navigate to a Directory
cd Documents
- Moves to the
Documents
directory.
- Moves to the
Go Back to Parent Directory
cd ..
- Moves up one directory level.
Go to the Home Directory
cd ~
Navigate to Root Directory
cd /
- Moves to the root directory.
Navigate Using Absolute Path
cd /usr/local/bin
Navigate Using Relative Path
cd ../Downloads
- Moves to the
Downloads
directory from the current directory.
- Moves to the
clear
Command: Clean Your Terminal
The The clear
command is a simple but useful tool to clean up your terminal screen.
Syntax
clear
Usage
Clear the Terminal
clear
- Removes all previous output and gives you a clean workspace.
Shortcut for Clearing On most terminals, you can also use the keyboard shortcut
Ctrl + L
to achieve the same result.
Practical Example
Let’s combine these commands to demonstrate a typical terminal workflow:
- List Files in the Current Directory
ls
- Navigate to a Specific Directory
cd Projects
- Check Contents of the New Directory
ls -l
- Clear the Terminal
clear
Conclusion
Mastering the ls
, cd
, and clear
commands is the first step in becoming proficient with the terminal. These commands are foundational and will help you navigate and manage your files more effectively. Practice using these commands in your daily workflow, and soon, they’ll become second nature.