Regularly working with Ubuntu/Linux commands? Today, we’re diving into the most important Ubuntu commands you should know.
These are some of the most practical and commonly used commands that every Linux user can benefit from. So if you are seasoned veteran in the Linux world or a fresh beginner with diapers on, you will find these commands useful.
What Are Ubuntu Commands?
Ubuntu commands are text-based instructions you type into the terminal to control your system without relying on a mouse or trackpad. Instead of clicking around, you simply type commands to tell your computer exactly what to do.
Here’s how Ubuntu/Linux commands work:
- Case-sensitive: Commands are sensitive to uppercase and lowercase letters. For example,
ls
and LS
are not the same.
- Specific format: Commands usually follow a structure like
command -options arguments
.
- Combine for power: You can link commands together to handle more complex tasks using tools like pipelines and redirection.
- Ultimate control: They give you precise control over your system, beyond what’s possible with graphical interfaces.
- Automate tasks: You can use commands to create scripts for automating repetitive tasks.
- Access system resources: Commands can manage files, networks, memory, and CPU directly.
- Essential for servers: They are the backbone of how Linux servers and systems are managed.
Before you dive in, open the command-line interface on your Linux desktop or virtual private server (VPS). If you’re working on a remote system, use an SSH client like PuTTY or your system’s Terminal to connect.
Don’t have a Linux machine yet? Consider setting up a VPS. Check out my guide on some of the best Ubuntu VPS service providers and explore Linux courses with certificates to get started.
Top Ubuntu Commands
Let’s explore some of the most commonly used Ubuntu/Linux commands with examples, perfect for system administration tasks.
To make it easier, we’ve grouped them into categories such as file management, system monitoring, network operations, user management, and more.
pwd – Print Working Directory
The pwd command displays the absolute path of the current working directory, helping you know where you are in the file system.
Syntax:
Example:
This will output something like /home/username, indicating your current directory.
ls – List Directory Contents
The ls command lists all files and directories in the current directory, providing a quick overview of its contents.
Syntax:
Example:
This command shows all files, including hidden ones, in long format with detailed information.
cd – Change Directory
The cd command changes the current directory to another specified directory.
Syntax:
Example:
This will navigate to the “Documents” folder within your home directory.
mkdir – Create A New Directory
The mkdir command allows you to create a new folder in the file system.
Syntax:
mkdir [options] <directory>
Example:
This creates a new directory called “newproject” in the current working directory.
rmdir – Remove Empty Directory
The rmdir command deletes an empty directory from the file system.
Syntax:
Example:
This removes the “oldfolder” if it is empty.
touch – Create an Empty File
The touch command creates an empty file or updates the timestamp of an existing file.
Syntax:
Example:
This creates an empty file named “newfile.txt”.
cat – Concatenate and Display File Content
The cat command is used to display the contents of a file or concatenate multiple files together.
Syntax:
Example:
This displays the content of “file.txt” on the terminal.
cp – Copy Files or Directories
The cp command copies files or directories from one location to another.
Syntax:
cp [options] <source> <destination>
Example:
cp file.txt backup_file.txt
This copies “file.txt” to “backup_file.txt”.
mv – Move or Rename Files and Directories
The mv command moves files or directories, or renames them if the source and destination are in the same location.
Syntax:
mv <source> <destination>
Example:
mv oldname.txt newname.txt
This renames “oldname.txt” to “newname.txt”.
rm – Remove Files or Directories
The rm command deletes files or directories from the file system.
Syntax:
Example:
This removes “oldfolder” and its contents recursively.
echo – Display Text or Variable Values
The echo command prints text or variable values to the terminal.
Syntax:
Example:
This outputs “Hello World” to the terminal.
nano – Simple Text Editor
The nano command opens a simple text editor for creating and editing text files directly in the terminal.
Syntax:
Example:
This opens “notes.txt” for editing in Nano.
vi – Powerful Text Editor
The vi command opens a powerful text editor used for editing text files with more advanced features than Nano.
Syntax:
Example:
This opens “script.sh” in the vi editor for editing.
chmod – Change File Permissions
The chmod command changes the permissions of a file or directory, defining who can read, write, or execute it.
Syntax:
chmod [options] <mode> <file>
Example:
This sets the permissions of “script.sh” so that the owner can read, write, and execute it, while others can only read and execute it.
chown – Change File Owner and Group
The chown command changes the owner and group of a file or directory.
Syntax:
chown [owner][:group] <file>
Example:
This changes both the owner and group of “file.txt” to “user”.
find – Search for Files and Directories
The find command searches for files and directories based on specified criteria within a directory hierarchy.
Syntax:
Example:
find /home/user -name "*.txt"
This finds all text files in “/home/user”.
grep – Search Text Using Patterns
The grep command searches for specific patterns within files, displaying matching lines.
Syntax:
grep [options] <pattern> <file>
Example:
grep "search term" file.txt
This searches for “search term” within “file.txt”.
man – Display Manual for Commands
The man command displays the manual pages for other commands, providing detailed information about their usage.
Syntax:
Example:
This shows the manual page for the ls command.
ps – Display Running Processes
The ps command provides information about currently running processes on your system at a specific point in time.
Syntax:
Example:
This displays detailed information about all running processes.
top – Real-time System Monitoring Tool
The top command displays real-time information about system processes, including CPU and memory usage statistics.
Syntax:
Example:
Running this will show an interactive view of system performance metrics.
df – Report File System Disk Space Usage
The df command reports disk space usage for all mounted filesystems, showing total space, used space, and available space.
Syntax:
Example:
This shows disk usage in human-readable format (e.g., MBs and GBs).
du – Estimate File Space Usage
The du command estimates disk space used by files and directories, providing insights into storage consumption.
Syntax:
Example:
du -sh /path/to/directory
This shows total size of specified directory in human-readable format.
free – Display Memory Usage Statistics
The free command displays information about total, used, free, shared, buffer/cache memory on your system.
Syntax:
Example:
This shows memory usage statistics in megabytes (MB).
uname – Print System Information
The uname command prints detailed information about your Linux system including kernel name and version.
Syntax:
Example:
This outputs all available system information including kernel version and architecture details.
uptime – Show How Long System Has Been Running
The uptime command tells you how long your system has been running along with load averages over time periods.
Syntax:
Example:
Running this will display how long your system has been up since last boot along with load averages for past 1, 5, and 15 minutes.
whoami – Display Current User Name
The whoami command shows you which user account is currently logged into the terminal session.
Syntax:
Example:
This simply outputs your username.
sudo – Execute Command as Another User (Superuser)
The sudo command allows permitted users to run commands as another user (usually root) while providing authentication.
Syntax:
Example:
This runs the package update as a superuser.
apt-get – Package Handling Utility for Debian-based Systems
The apt-get tool is used to handle packages on Debian-based systems like Ubuntu; it can install, update, or remove software packages.
Syntax:
apt-get [options] <command>
Example:
sudo apt-get install package-name
This installs a specified package using APT.
yum – Package Manager for RPM-based Distributions
Similar to apt-get but used primarily on Red Hat-based distributions; it manages packages via RPM.
Syntax:
Example:
sudo yum install package-name
This installs a specified package using YUM.
tar – Archive Files into a Single File or Extract Files from Archive
The tar command is used to create compressed archive files or extract them.
Syntax:
tar [options] <archive-file>
Example (to create):
tar -cvf archive.tar /path/to/directory
This creates an archive named “archive.tar” containing all files from specified directory.
zip – Package and Compress Files into Zip Format
The zip command compresses files into zip format which is widely used for file storage and transfer.
Syntax:
zip [options] <zip-file> <files>
Example:
zip archive.zip file1.txt file2.txt
This compresses “file1.txt” and “file2.txt” into “archive.zip”.
unzip – Extract Compressed Zip Files
The unzip command extracts contents from zip archives.
Syntax:
Example:
This extracts all contents from “archive.zip”.
wget – Download Files from Web via HTTP/HTTPS/FTP Protocols
The wget command retrieves content from web servers using various protocols like HTTP and FTP.
Syntax:
Example:
wget https://example.com/file.zip
This downloads “file.zip” from example.com.
curl – Transfer Data from/to Server Using Various Protocols
Similar to wget but more versatile; it can send data as well as retrieve it using various protocols.
Syntax:
Example:
curl -O https://example.com/file.zip
This downloads “file.zip” using curl.
ssh – OpenSSH Client (Remote Login Program)
The ssh command allows secure remote login to another machine over a network.
Syntax:
Example:
This connects you securely to another machine with IP address “192.168.x.x”.
scp – Secure Copy (Remote File Copy Program)
The scp command securely copies files between hosts over SSH protocol.
Syntax:
scp [options] <source> <destination>
Example:
scp localfile.txt user@remote_host:/path/to/destination
This copies “localfile.txt” to a remote host securely.
rsync – Remote File Synchronization Tool
Rsync synchronizes files/directories between two locations efficiently using delta encoding.
Syntax:
rsync [options] <source> <destination>
Example:
rsync -avz /local/dir/ user@remote_host:/remote/dir/
This synchronizes local directory with remote one while preserving attributes.
hostname – Show or Set System’s Host Name
Displays or sets the name of your computer within a network context.
Syntax:
Example (to view):
This outputs your current hostname.
history – Show Command History List
Displays previously executed commands within your terminal session allowing easy recall.
Syntax:
Example (to view):
This shows a list of all commands run in this session with their respective numbers.
clear – Clear Terminal Screen
Clears all previous commands from view in terminal window providing a clean slate.
Syntax:
Example (to use):
Running this will wipe previous output from your terminal screen making it easier to read new commands/results.
cron – Schedule Automated Tasks
Automates repetitive tasks by scheduling them at specific intervals using cron jobs.
Syntax:
Post Views: 2,312