Linux Commands

Admin, Student's Library
0

Mastering Linux Commands: Your Essential Guide to the Command Line

Linux Terminal Commands

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 files
  • pwd – Print current directory
  • cd /path/to/dir – Change directory
  • mkdir new_folder – Create a new directory
  • rmdir empty_folder – Remove an empty directory
  • rm -r folder – Delete directory and contents
  • touch file.txt – Create an empty file
  • cp src dest – Copy files or directories
  • mv src dest – Move or rename files
  • rm file.txt – Delete a file
  • find /path -name "pattern" – Search for files
  • tree – View directory structure (may need to install)

📄 File Viewing and Editing

  • cat, less, more – View contents of files
  • head, tail – View first or last 10 lines
  • nano file, vim file – Edit files in terminal
  • echo "text" – Print text
  • echo "text" > file – Overwrite file
  • echo "text" >> file – Append to file

👤 User Management

  • whoami – Show current user
  • id – Show UID, GID
  • adduser newuser – Add a new user
  • passwd username – Change password
  • su user – Switch to another user
  • sudo command – Execute as superuser
  • logout – Log out of session
  • export FLINK_HOME=/opt/flink/flink-2.0.0 Setting Environment Variables:
  • export PATH=/opt/flink/flink-2.0.0/bin:$PATHUpdate the path variable with additional value
  • echo $PATH Printing Variable on console.
  • echo $FLINK_HOME Prin Variable on console.

📦 Package Management

  • Debian/Ubuntu: apt based
    sudo apt update – Update repo
    sudo apt install curl – Install a package
    sudo apt remove nano – Remove a package
  • RHEL/CentOS: yum or dnf
    sudo yum install httpd
    sudo dnf install git

⚙️ System Information

  • uname -a – System details
  • top, htop – View running processes
  • df -h – Disk usage
  • free -h – Memory usage
  • uptime – System uptime
  • who – Who is logged in

📂 Permissions and Ownership

  • ls -l – View file permissions
  • chmod 755 file.sh – Set file permissions
  • chmod +x file.sh – Make a file executable
  • chown 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 file
  • grep -r "pattern" /dir – Recursive search
  • find /path -name "*.sh" – Locate by name
  • locate filename – Search indexed files

🧰 Networking Commands

  • ping example.com – Check connectivity
  • ip a or ifconfig – Network details
  • netstat -tulpn – Listening ports
  • curl http://example.com – Fetch page content
  • wget https://url/file.zip – Download file
  • hostname – Display hostname

💻 Process Management

  • ps, ps aux – Show processes
  • kill 1234 – Terminate process by PID
  • kill -9 1234 – Force kill
  • xkill – Click to kill window (GUI)

🧪 Archive and Compression

  • tar -czvf archive.tar.gz folder/ – Compress folder
  • tar -xvf archive.tar.gz – Extract archive
  • unzip file.zip – Unzip file
  • gzip file – Compress file
  • gunzip file.gz – Decompress

🧮 Disk and Mounting

  • mount /dev/sdX /mnt – Mount device
  • umount /mnt – Unmount device
  • lsblk – List block devices
  • fdisk -l – View partitions

⛔ Shutdown and Reboot

  • shutdown now – Immediate shutdown
  • reboot – Restart system
  • shutdown -r now – Reboot now
  • halt – Halt system

Example Workflow for Create/Edit File

  • vi notes.txt – Step 1: open/create file
  • i – Step 2: enter insert mode
  • Type your text... – Step 3: edit text
  • Esc. – 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)
✅ 3. Enter Insert Mode to Type or Edit. Press i to go into Insert Mode, Other ways to enter Insert Mode:
  • i – insert at cursor
  • I – insert at beginning of line
  • a – append after cursor
  • A – append at end of line
  • o – open new line below
  • O – 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).

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.
Post a Comment (0)
Our website uses cookies to enhance your experience. Learn More
Accept !