DEV Community

Cover image for Mastering Linux Cmds: Comprehensive Guide to Essential Commands
Aadarsh Nagrath
Aadarsh Nagrath

Posted on

Mastering Linux Cmds: Comprehensive Guide to Essential Commands

Linux, with its robust command-line interface, offers a plethora of powerful tools and commands that can enhance productivity and efficiency for both beginners and advanced users. Understanding and mastering these commands can significantly improve your Linux experience. In this guide, we will explore various essential commands across different categories.

File Commands

Directory Listing

  • ls: Displays directory contents.
  • ls -al: Formats the listing to include hidden files.

Navigation

  • cd directory: Changes the current directory to the specified one.
  • cd: Changes the current directory to the home directory.
  • pwd: Shows the current directory.

File Manipulation

  • mkdir directory: Creates a new directory.
  • rm file: Deletes a file.
  • rm -r directory: Deletes a directory recursively.
  • cp file1 file2: Copies file1 to file2.
  • mv file1 file2: Renames or moves file1 to file2.
  • touch file: Updates the access and modification timestamps of a file.
  • cat > file: Redirects standard input into a file.
  • more file / less file: Displays file content page by page.
  • head file / tail file: Displays the first/last part of a file.
  • tail -f file: Outputs contents of a file as it grows.
  • grep -i pattern file: Searches for a pattern in a file, ignoring case.
    • find directory -name filename: Searches for files in a directory with a specific name.

SSH

Secure Shell (SSH) allows secure remote access to systems.

  • ssh user@host: Connects to a host as a specific user.
  • ssh -p port user@host: Connects using a specific port.
  • ssh -D port user@host: Sets up dynamic application-level port forwarding.

Installation

The process of installing software on Linux usually involves these steps:

  • ./configure: Configures the source code.
  • make: Compiles the source code.
  • make install: Installs the compiled software.

Networking

Various networking commands are essential for network troubleshooting and management:

  • ping host: Tests network connectivity to a host.
  • whois domain: Retrieves WHOIS information for a domain.
  • dig domain: Performs DNS queries.
  • wget file: Downloads files from the internet.
  • wget -c file: Continues a stopped download.
  • wget -r url: Recursively downloads files from a URL.
  • netstat: Displays network connections, routing tables, interface statistics, masquerade connections, and multicast memberships.
  • traceroute host: Traces the route that packets take to reach a host.

System Information

Understanding system status and configurations is crucial for system administrators:

  • date: Displays the current date and time.
  • cal: Shows the calendar for the current month.
  • uptime: Displays the system uptime.
  • w: Shows who is online.
  • uname -a: Displays kernel information.
  • df: Shows disk usage.
  • du: Shows directory space usage.
  • free: Shows memory and swap usage.
  • top: Displays real-time information about running processes, CPU, and memory usage.
  • htop: Interactive process viewer for system monitoring.

Searching

Efficiently search for files and patterns within files:

  • grep pattern files: Searches for a pattern in files.
  • grep -r pattern directory: Searches recursively for a pattern in a directory.
  • command | grep pattern: Searches for a pattern in the output of a command.
  • locate file: Finds all instances of a file.

Process Management

Control and manage running processes:

  • ps: Displays currently active processes.
  • kill PID: Terminates a process with a specific PID.
  • killall process_name: Terminates all processes with a specific name.
  • bg: Lists stopped or background jobs.
  • fg: Brings the most recent job to the foreground.

File Permissions

Manage file permissions:

  • chmod octal file: Changes the permission of a file.
  • 4 (read), 2 (write), 1 (execute).
  • 777 (rwx for everyone), 755 (rw for owner, rx for group/world).

Access Control Lists (ACL)

  • getfacl file: Displays the Access Control List (ACL) of a file.
  • setfacl -m u:user: permissions file: Modifies the ACL of a file to grant specific permissions to a user.

Compression

Compress and decompress files:

  • tar cf file.tar files: Creates a tar archive.
  • tar xf file.tar: Extracts a tar archive.
  • gzip file: Compresses a file.
  • gzip -d file.gz: Decompresses a file.
  • zip file.zip files: Creates a zip archive.
  • unzip file.zip: Extracts files from a zip archive.

Shortcuts

Useful keyboard shortcuts for the command line:

  • Ctrl+A: Moves the cursor to the beginning of the line.
  • Ctrl+E: Moves the cursor to the end of the line.
  • Ctrl+C: Halts the current command.
  • Ctrl+Z: Stops the current command, putting it in the background.
  • Ctrl+D: Logs out of the current session.
  • Ctrl+E: Erases one word in the current line.
  • Ctrl+U: Erases the entire line.
  • Ctrl+R: Reverse lookup of previous commands.
  • !!: Repeats the last command.

Mastering these commands will empower you to navigate and manipulate your Linux system efficiently, whether you are a beginner or an experienced user.

Experiment with these commands in a safe environment to gain familiarity and confidence. With practice, you'll become proficient in utilizing the power of the Linux command line to its fullest extent.

Feel free to add more in the comments, will Update.
Github | Twitter

Top comments (0)