Mastering the Linux Command Line: A Comprehensive Guide to Essential Commands and Utilities

 5 min read

YouTube video ID: Byx4sgLR88E

Source: YouTube video by M PrashantWatch original video

PDF

Introduction

This article distills a full‑length video tutorial on Linux command‑line fundamentals into a concise, step‑by‑step guide. Whether you are a newcomer or need a quick refresher, the content below covers the most frequently used commands, file manipulation techniques, system monitoring, networking tools, package management, user administration, and scripting basics.

1. Navigating the Shell

  • pwd – Prints the current working directory.
  • whoami – Shows the logged‑in user.
  • cd – Change directory (absolute vs. relative paths, cd .., cd -, cd /path/to/dir).
  • clear / Ctrl+L – Clears the terminal screen.

2. Working with Dates and Times

  • date – Displays date/time. Use format specifiers (date +%Y-%m-%d, date +%H:%M).
  • cal – Shows a calendar for a given month or year.

3. Listing Files and Directories

  • ls – Basic listing.
  • ls -l – Long format (permissions, owner, size, modification date).
  • ls -lh – Human‑readable sizes.
  • ls -ltr – Sort by modification time, newest last.
  • ls -ltR – Recursive reverse‑time sort.
  • Color cues: directories (blue), executables (green), symlinks (cyan).

4. Viewing File Contents

  • cat – Concatenate and display whole files.
  • less / more – Paginated view; navigation keys (Space, b, g, G).
  • head – Show first n lines (head -n 5 file).
  • tail – Show last n lines (tail -n 5 file).
  • grep – Search patterns, case‑sensitive (grep "word" file) or case‑insensitive (grep -i).
  • grep -E – Extended regex; combine multiple words (grep -E "word1|word2").
  • find – Locate files by name, path, or type (find . -name "*.csv").
  • locate – Fast database‑based search (run updatedb first).

5. Editing Files

  • vi / vim – Modal editor.
  • i to insert, Esc to exit insert mode.
  • :wq to write and quit, :q! to quit without saving.
  • nano – Simpler editor (Ctrl+O to save, Ctrl+X to exit).

6. Creating and Deleting Files & Directories

  • touch filename – Create an empty file or update timestamps.
  • rm filename – Remove a file.
  • rm -r dirname – Recursively delete a directory.
  • mkdir dirname – Create a new directory.
  • rmdir dirname – Remove an empty directory.

7. Copying, Moving, and Renaming

  • cp source dest – Copy files; add -r for directories.
  • mv source dest – Move or rename.
  • rename – Batch rename using patterns.

8. Sorting, Uniquing, and Cutting Data

  • sort file – Alphabetical sort; -r for reverse.
  • uniq – Remove duplicate adjacent lines (often used after sort).
  • cut -d',' -f2 file – Extract the 2nd column from a CSV.
  • awk – Powerful column handling (awk -F',' '{print $2}' file).

9. Splitting Files

  • split -l 3 bigfile prefix_ – Split into chunks of 3 lines each.
  • split -b 1M bigfile part_ – Split by size.

10. Compression & Archiving

  • gzip file / gunzip file.gz – Compress/decompress a single file.
  • tar -czf archive.tar.gz dir/ – Create a gzipped tarball.
  • tar -xzf archive.tar.gz – Extract.
  • zip / unzip – Alternative archive format.

11. Wildcards & Brace Expansion

  • *.csv – All CSV files.
  • file{1..10}.txt – Generates file1.txtfile10.txt.
  • Useful for bulk operations (e.g., touch file{1..5}.log).

12. Managing Packages

  • apt (Debian/Ubuntu) – apt update, apt install package, apt list --installed.
  • yum / dnf (RHEL/CentOS) – dnf install package.
  • Check if a package is installed: dpkg -l | grep package or rpm -qa | grep package.

13. Service Control (systemd)

  • systemctl status service – View status.
  • systemctl start/stop/restart service – Control a service.
  • systemctl enable/disable service – Auto‑start on boot.
  • systemctl list-units --type=service – List all services.

14. System Monitoring

  • free -h – Memory usage (total, used, free, swap).
  • top / htop – Real‑time process view.
  • df -h – Disk space per filesystem.
  • du -sh /path – Size of a directory.
  • ps aux – Snapshot of running processes.
  • ps -ef | grep name – Filter by name.
  • kill PID – Terminate a process; kill -9 PID for force.
  • jobs, bg, fg, Ctrl+Z – Job control (background/foreground).
  • nohup command & – Run a command immune to hang‑ups.

15. Networking Essentials

  • ip addr – Show IP addresses.
  • ping host – Test connectivity.
  • netstat -tuln or ss -tuln – List listening ports.
  • nc (netcat) – Port scanning / simple client/server.
  • wget URL / curl -O URL – Download files.
  • traceroute host – Trace route to a remote host.

16. User & Group Management

  • adduser username – Create a new user.
  • deluser username – Remove a user.
  • usermod -aG group username – Add user to a group.
  • groupadd groupname, groupdel groupname – Manage groups.
  • passwd username – Set or change a password.
  • su - username – Switch user (requires password).
  • sudo command – Execute a command with root privileges (configured via /etc/sudoers).

17. Permissions & Ownership

  • chmod – Change mode (chmod u+rwx,g+rx,o-r file).
  • chown – Change owner (chown user:group file).
  • chmod -R – Apply recursively.
  • Permission notation: r (read), w (write), x (execute); displayed as rwxr-xr--.

18. Environment Variables

  • export VAR=value – Set for current session.
  • Add permanent variables to ~/.bashrc or /etc/profile.
  • Example: export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64.

19. Getting Help

  • command --help – Quick usage.
  • man command – Full manual page.
  • command -h or command -? – Shortcut help.
  • history – List previously executed commands; pipe to grep for search.

20. Miscellaneous Tips

  • alias ll='ls -lah' – Create shortcuts for long commands.
  • Use Ctrl+R for reverse search in the shell history.
  • tee – Write output to both screen and a file (command | tee logfile).
  • sed – Stream editor for in‑place text replacement (sed -i 's/old/new/g' file).
  • cut, paste, awk, tr – Text processing utilities.

Conclusion

By mastering these commands, you can navigate the filesystem, manipulate data, monitor system health, manage users and services, and automate tasks—all without leaving the terminal. This knowledge forms a solid foundation for deeper Linux administration, scripting, and DevOps work.

The Linux command line equips you with powerful, scriptable tools for every aspect of system administration; mastering the basics covered here eliminates the need to rely on graphical interfaces and prepares you for advanced automation and troubleshooting.

Frequently Asked Questions

Who is M Prashant on YouTube?

M Prashant is a YouTube channel that publishes videos on a range of topics. Browse more summaries from this channel below.

Does this page include the full transcript of the video?

Yes, the full transcript for this video is available on this page. Click 'Show transcript' in the sidebar to read it.

Helpful resources related to this video

If you want to practice or explore the concepts discussed in the video, these commonly used tools may help.

Links may be affiliate links. We only include resources that are genuinely relevant to the topic.

PDF