Ubuntu is one of the most popular Linux distributions available today, praised for its stability, user-friendliness, and a vibrant community. Whether you’re a system administrator, a developer, or a curious enthusiast, mastering the command line in Ubuntu can significantly enhance your efficiency and productivity. In this article, we’ll uncover the 10 most useful Ubuntu commands and tips that are beneficial for both beginners and seasoned pros.
TL;DR
Ubuntu offers a rich set of terminal commands that streamline everything from installation and updates to user and file management. This article covers the essential commands like apt, grep, and top, along with practical usage tips. Whether you’re just starting or a Linux veteran, these tools can optimize your Ubuntu experience. Don’t miss the frequently asked questions at the end for quick reference.
1. apt-get and apt – Package Management Made Simple
One of the first tools every Ubuntu user encounters is apt (Advanced Package Tool), which makes it incredibly easy to install, update, and remove software packages.
sudo apt update– Updates the package list.sudo apt upgrade– Upgrades all installed packages.sudo apt install [package-name]– Installs new software.sudo apt remove [package-name]– Removes installed software.
Tip: Use apt instead of apt-get for a more user-friendly interface with progress bars and better messages.
2. cd, ls, pwd – Navigate the Filesystem
File navigation is fundamental. Knowing these simple yet powerful commands will help you move around the Linux filesystem with ease:
cd– Change directory. Example:cd /home/user/Documentsls– List directory contents. Usels -lfor long listing format.pwd– Print the current working directory.
Combine with tab-completion for faster navigation.
3. grep – Find Text Easily
grep is one of the most versatile commands in your toolbox. It helps you search for patterns or keywords inside files or outputs.
- Search in a file:
grep "keyword" filename.txt - Combine with other commands:
cat logfile.txt | grep "ERROR"
Tip: Use grep -r to search recursively through directories.

4. top and htop – Monitor System Resources
To manage system performance, monitoring CPU and memory usage is essential. Use:
top– Display running processes in real-time.htop– Enhanced version oftopwith a user-friendly interface (install it usingsudo apt install htop).
These commands help identify resource-hogging processes and allow you to stop them as needed.
5. chmod and chown – Manage File Permissions
Permissions are crucial for securing a Linux system. The chmod and chown commands help you control access to files and directories.
chmod 755 filename– Sets permission to read/write/execute for the owner, and read/execute for everyone else.chown user:group filename– Changes file ownership.
Tip: Use ls -l to view permission settings before making changes.
6. nano and vim – Command Line Text Editing
Editing text files directly in the terminal is often faster than opening a GUI editor. Ubuntu comes with nano, a simple and beginner-friendly editor.
nano filename.txt– Opens the file in nano.vim filename.txt– For pro users seeking powerful editing features (install if needed).
Tip: Learn basic nano commands like Ctrl+O (save) and Ctrl+X (exit) first.
7. df and du – Disk Usage Check
Running out of disk space? Use these commands to check usage:
df -h– Shows overall disk usage per filesystem in human-readable format.du -sh /path/to/directory– Shows the size of a specific directory.
Combine du with sort: du -sh * | sort -h to find the largest directories.
8. history – View Previously Used Commands
Want to reuse a previously typed command? Run:
history– Lists all past commands with a number index.!123– Executes the 123rd command from the history list.
Tip: Press the Up Arrow key to scroll through your recent commands.
9. man – Read Manual Pages
When in doubt, the manual pages are your best friend:
man [command]– Shows the manual for the specified command. Example:man ls
This command is essential for getting detailed usage information, options, and examples.
10. Customize the Terminal Prompt (PS1)
Power users often customize their terminal’s prompt to simplify their workflow or display important information.
Edit your PS1 variable in the .bashrc file:
nano ~/.bashrc
Then change the PS1 line to something like:
PS1='\u@\h:\w\$ '
This sets the prompt to display username, hostname, and current path. Reload with source ~/.bashrc.
Frequently Asked Questions (FAQ)
- Q: How do I update all packages on Ubuntu?
A: Runsudo apt update && sudo apt upgradeto refresh repositories and upgrade installed packages. - Q: Is it better to use
aptorapt-get?
A: Both work, butaptis more user-friendly and recommended for day-to-day use. - Q: What is the default text editor in Ubuntu?
A: Ubuntu typically comes withnanoas the default CLI text editor, but you can install and use others likevimoremacs. - Q: Can I undo a command in the terminal?
A: There’s no “undo” button in the terminal. You can usehistoryto view past commands, but always confirm before running destructive commands likerm. - Q: How do I make scripts executable?
A: Usechmod +x script.shto make a script executable, then run it using./script.sh.
Whether you’re just opening the terminal for the first
