Mastering Essential Linux Commands

Jul 31, 2024

Essential Linux Commands for Cybersecurity

Introduction

  • Goal: Master essential Linux commands before advancing to tools like Metasploit, nmap, Hydra, etc.
  • Importance: Foundational knowledge for ethical hacking and cybersecurity.

Navigation Commands

LS Command

  • Basic: ls lists directory contents.
  • Flags:
    • -l: Long listing format (file type, permissions, owner, size, modification date).
    • -a: Includes hidden files.
    • -t: Sorts by modification time.
    • -h: Human-readable sizes.
    • Combined: ls -lath.

CD Command

  • Basic: cd changes directories.
  • Usage:
    • cd ..: Move up one directory level.
    • cd -: Return to the previous directory.
    • cd ~: Go to the home directory.
    • Tab completion helps navigate directories.

CLEAR Command

  • Usage: clear clears the terminal screen.

PWD Command

  • Usage: pwd prints the current working directory.

File Manipulation Commands

TOUCH Command

  • Usage: touch filename creates a blank text file.

MKDIR Command

  • Usage: mkdir directory_name creates a directory.
  • Flags:
    • -p: Creates parent directories as needed.
    • -m: Sets permissions at creation.

CP Command

  • Basic: cp source destination copies files.
  • Flags:
    • -r: Copies directories recursively.
    • -f: Forces the copy, overwriting existing files.

MV Command

  • Usage: mv source destination moves or renames files/directories.

RM Command

  • Basic: rm filename removes files.
  • Flags:
    • -r: Removes directories recursively.
    • -f: Forces removal without prompt.

CHMOD Command

  • Usage: chmod mode filename changes file permissions.
  • Modes: r (read), w (write), x (execute). Numeric: chmod 777 filename.

CHOWN Command

  • Usage: chown owner:group filename changes file ownership.

Viewing File Contents

CAT Command

  • Usage: cat filename displays file contents.
  • Combining: cat file1 file2 > newfile.
  • Appending: cat file3 >> newfile.

TAIL Command

  • Usage: tail filename displays the last 10 lines of a file.
  • Flags: -n for number of lines. -f for continuous updates.

HEAD Command

  • Usage: head filename displays the first 10 lines of a file.
  • Flags: -n for number of lines.

LESS and MORE Commands

  • Usage: less filename or more filename to view large files one page at a time.
  • Search: Within less, use /pattern to search.

Text Editors

VI Editor

  • Usage: vi filename opens VI editor.
  • Modes: i for insert, Esc to exit insert, :wq to save and quit.

NANO Editor

  • Usage: nano filename opens Nano editor.

Process Management

PS Command

  • Usage: ps lists processes for the current user.
  • Flags: aux for detailed process list.

TOP Command

  • Usage: top shows real-time process information.
  • Interactive: u for user-specific processes, p for specific PID.

KILL Command

  • Usage: kill PID to terminate processes.
  • Flags: -9 for forceful termination, -2 for interrupt.

JOBS and FG Commands

  • Usage: jobs lists background jobs. fg %1 brings job to the foreground.

Networking Commands

IP Command

  • Usage: ip a shows IP addresses. ip route show shows routing table.
  • Add route: ip route add subnet via gateway dev device.
  • Add IP: ip addr add address dev device. Remove: ip addr del.

NETSTAT Command

  • Usage: netstat -l for listening ports.
  • SS Command: ss -t for TCP sockets.

SSH Command

  • Usage: ssh user@hostname to connect via SSH.
  • SCP Command: scp source destination for secure copy.

RSYNC Command

  • Usage: rsync options source destination for file synchronization.

System Information

UNAME Command

  • Usage: uname -a for detailed system information.

DF Command

  • Usage: df -h shows disk space in human-readable format.

File Search Commands

FIND Command

  • Usage: find directory -name pattern to search for files.
  • Flags: -size to find by size, -mtime to find by modification time.

GREP Command

  • Usage: grep pattern files to search within files.

TAR and GZIP Commands

  • TAR:
    • tar czf archive.tar.gz files to create an archive.
    • tar xvf archive.tar.gz to extract.
    • tar rf archive.tar file to add to archive.
  • GZIP:
    • gzip file to compress.
    • gunzip file.gz to decompress.

User Management

ADDUSER Command

  • Usage: useradd username to add user.
  • Flags: -m to create home directory, -g to add to group, -e to set expiration.

DELUSER Command

  • Usage: userdel username to delete user.
  • Flags: -r to remove home directory.

GROUPADD Command

  • Usage: groupadd groupname to add group.

GROUPDEL Command

  • Usage: groupdel groupname to delete group.

Conclusion

  • Summary: Master these commands as a foundation for Linux system administration and cybersecurity roles.
  • Encouragement: Practice regularly to build proficiency.