Mastering Linux Commands: Your Essential Guide to the Command Line
Topic: Linux CLI Basics | Skills Covered: File Management, Process Handling, Networking, Permissions | Level: Beginner to Intermediate
Linux offers a powerful Command Line Interface (CLI) that provides direct access to system operations and configurations. This guide covers everything from basic file commands to user management and networking. Whether you're a beginner or brushing up your skills, these commands will sharpen your terminal prowess. Explore Advanced Linux Tutorials for deeper insights.
📁 File and Directory Commands
ls, ls -l, ls -a– List contents, long format, show hidden filespwd– Print current directorycd /path/to/dir– Change directorymkdir new_folder– Create a new directoryrmdir empty_folder– Remove an empty directoryrm -r folder– Delete directory and contentstouch file.txt– Create an empty filecp src dest– Copy files or directoriesmv src dest– Move or rename filesrm file.txt– Delete a filefind /path -name "pattern"– Search for filestree– View directory structure (may need to install)
📄 File Viewing and Editing
cat, less, more– View contents of fileshead, tail– View first or last 10 linesnano file,vim file– Edit files in terminalecho "text"– Print textecho "text" > file– Overwrite fileecho "text" >> file– Append to file
👤 User Management
whoami– Show current userid– Show UID, GIDadduser newuser– Add a new userpasswd username– Change passwordsu user– Switch to another usersudo command– Execute as superuserlogout– Log out of sessionexport FLINK_HOME=/opt/flink/flink-2.0.0Setting Environment Variables:export PATH=/opt/flink/flink-2.0.0/bin:$PATHUpdate the path variable with additional valueecho $PATHPrinting Variable on console.echo $FLINK_HOMEPrin Variable on console.
📦 Package Management
- Debian/Ubuntu:
aptbased
sudo apt update– Update repo
sudo apt install curl– Install a package
sudo apt remove nano– Remove a package - RHEL/CentOS:
yumordnf
sudo yum install httpd
sudo dnf install git
⚙️ System Information
uname -a– System detailstop,htop– View running processesdf -h– Disk usagefree -h– Memory usageuptime– System uptimewho– Who is logged in
📂 Permissions and Ownership
ls -l– View file permissionschmod 755 file.sh– Set file permissionschmod +x file.sh– Make a file executablechown user:group file– Change file owner
Warning: Use chmod and sudo cautiously. Incorrect permissions can break your system or create security holes.
🔍 Searching and Filtering
grep "text" file– Find text in a filegrep -r "pattern" /dir– Recursive searchfind /path -name "*.sh"– Locate by namelocate filename– Search indexed files
🧰 Networking Commands
ping example.com– Check connectivityip aorifconfig– Network detailsnetstat -tulpn– Listening portscurl http://example.com– Fetch page contentwget https://url/file.zip– Download filehostname– Display hostname
💻 Process Management
ps,ps aux– Show processeskill 1234– Terminate process by PIDkill -9 1234– Force killxkill– Click to kill window (GUI)
🧪 Archive and Compression
tar -czvf archive.tar.gz folder/– Compress foldertar -xvf archive.tar.gz– Extract archiveunzip file.zip– Unzip filegzip file– Compress filegunzip file.gz– Decompress
🧮 Disk and Mounting
mount /dev/sdX /mnt– Mount deviceumount /mnt– Unmount devicelsblk– List block devicesfdisk -l– View partitions
⛔ Shutdown and Reboot
shutdown now– Immediate shutdownreboot– Restart systemshutdown -r now– Reboot nowhalt– Halt system
Example Workflow for Create/Edit File
vi notes.txt– Step 1: open/create filei– Step 2: enter insert modeType your text...– Step 3: edit textEsc.– Step 4: go back to normal mode:wq or ZZ– Step 5: save and exit:w– save the file:q– quit (only if no changes):q!– Quit without saving (force exit)
i – insert at cursorI – insert at beginning of linea – append after cursorA – append at end of lineo – open new line belowO – open new line above
Ready for more? Explore Our Advanced Linux Guide | Practice safely in a VM first!
📘 Linux Command FAQs
Q1. How do I undo a command in Linux?
A: There's no built-in undo. Use rm -i and double-check commands.
Q2. What's the difference between sudo and su?
A: sudo runs a single command as superuser. su changes your session to another user (often root).

