Ech0 - 00 / 00 / 00

The Linux Terminal

Description:



This cheatsheet covers the vital comands of the Linux Terminal in a simple manner, along with a few tricks.

Part 1 : Basic Commands



Concepts : Directory Tree , Directory / Files

  • ls : List directory contents
  •   λ ech0 [ 93.22.150.211 ] [ ~/Desktop/Coding/Pentest ]
      → ls
      ipsweep.sh  python101.py
    
      λ ech0 [ 93.22.150.211 ] [ ~/Desktop/Coding/Pentest ]
      → ls -l
      total 8
      -rw-r--r-- 1 ech0 users 555 Sep  1 20:24 ipsweep.sh
      -rw-r--r-- 1 ech0 users 812 May 20  2019 python101.py
    
      λ ech0 [ 93.22.150.211 ] [ ~/Desktop/Coding/Pentest ]
      → ls -la
      total 16
      drwxr-xr-x  2 ech0 users 4096 Nov 17 09:17 .
      drwxr-xr-x 12 ech0 users 4096 Nov 17 09:17 ..
      -rw-r--r--  1 ech0 users  555 Sep  1 20:24 ipsweep.sh
      -rw-r--r--  1 ech0 users  812 May 20  2019 python101.py
    
    
  • cd : Change working directory
  •   λ ech0 [ 93.22.150.211 ] [ ~/Desktop ]
      → ls
      Clarity  Coding  CV  HTBnotes.ctb  progress.jpg  reseaux  SIO  steam.desktop  TeX  Tools  USBSAVEDDD
    
      λ ech0 [ 93.22.150.211 ] [ ~/Desktop ]
      → cd Coding/C++
    
      λ ech0 [ 93.22.150.211 ] [ ~/Desktop/Coding/C++ ]
      → cd ../../Coding/Python
    
      λ ech0 [ 93.22.150.211 ] [ ~/Desktop/Coding/Python ]
      → cd /home/ech0/Desktop/Coding/PHP
    
  • pwd : Print working directory
  •   λ ech0 [ 93.22.150.211 ] [ ~/Desktop/Coding/PHP ]
      → pwd
      /home/ech0/Desktop/Coding/PHP
    
      λ ech0 [ 93.22.150.211 ] [ ~/Desktop/Coding/PHP ]
      → cd ..
    
      λ ech0 [ 93.22.150.211 ] [ ~/Desktop/Coding ]
      → pwd
      /home/ech0/Desktop/Coding
    
      λ ech0 [ 93.22.150.211 ] [ ~/Desktop/Coding ]
      → cd Ruby
    
      λ ech0 [ 93.22.150.211 ] [ ~/Desktop/Coding/Ruby ]
      → pwd
      /home/ech0/Desktop/Coding/Ruby
    
  • mv : move files
  • λ ech0 [ 93.22.150.211 ] [ ~/Desktop/Coding/Pentest ]
    → ls
    ipsweep.sh  python101.py
    
    λ ech0 [ 93.22.150.211 ] [ ~/Desktop/Coding/Pentest ]
    → mv python101.py NEWFILE.py
    
    λ ech0 [ 93.22.150.211 ] [ ~/Desktop/Coding/Pentest ]
    → ls
    ipsweep.sh  NEWFILE.py
    
    λ ech0 [ 93.22.150.211 ] [ ~/Desktop/Coding/Pentest ]
    → mv NEWFILE.py ../Pentest/NEWFILE2.py
    
    λ ech0 [ 93.22.150.211 ] [ ~/Desktop/Coding/Pentest ]
    → ls
    ipsweep.sh  NEWFILE2.py
    
    λ ech0 [ 93.22.150.211 ] [ ~/Desktop/Coding/Pentest ]
    → mv ../Pentest/NEWFILE2.py /home/ech0/Desktop/Coding/Pentest/NEWFILE3.py
    
    λ ech0 [ 93.22.150.211 ] [ ~/Desktop/Coding/Pentest ]
    → ls
    ipsweep.sh  NEWFILE3.py
    
  • cp : copy files
  •   λ ech0 [ 93.22.150.211 ] [ ~/Desktop/Coding/Pentest ]
    → cp NEWFILE3.py NEWFILE4.py
    
    λ ech0 [ 93.22.150.211 ] [ ~/Desktop/Coding/Pentest ]
    → cp NEWFILE3.py NEWFILE5.py
    
    λ ech0 [ 93.22.150.211 ] [ ~/Desktop/Coding/Pentest ]
    → cp NEWFILE3.py NEWFILE6.py
    
    λ ech0 [ 93.22.150.211 ] [ ~/Desktop/Coding/Pentest ]
    → ls
    ipsweep.sh  NEWFILE3.py  NEWFILE4.py  NEWFILE5.py  NEWFILE6.py
    
  • rm : remove files
  •   λ ech0 [ 93.22.150.211 ] [ ~/Desktop/Coding/Pentest ]
    → ls
    ipsweep.sh  NEWFILE3.py  NEWFILE4.py  NEWFILE5.py  NEWFILE6.py
    
    λ ech0 [ 93.22.150.211 ] [ ~/Desktop/Coding/Pentest ]
    → rm NEWFILE3.py
    
    λ ech0 [ 93.22.150.211 ] [ ~/Desktop/Coding/Pentest ]
    → rm NEWFILE5.py
    
    λ ech0 [ 93.22.150.211 ] [ ~/Desktop/Coding/Pentest ]
    → rm NEWFILE6.py
    
    λ ech0 [ 93.22.150.211 ] [ ~/Desktop/Coding/Pentest ]
    → ls
    ipsweep.sh  NEWFILE4.py
    
  • cat : Concatenate File(s) to standard output
  •   λ ech0 [ 93.22.150.211 ] [ ~/Desktop/Coding/Pentest ]
    → cat file.txt
    MESSAGE 2
    MESSAGE 3
    MESSAGE 4
    
  • sudo : Execute command with administrating privileges
  •   λ ech0 [ 93.22.150.211 ] [ ~/Desktop/Coding/Pentest ]
    → cat file.txt
    cat: file.txt: Permission denied
    
    λ ech0 [ 93.22.150.211 ] [ ~/Desktop/Coding/Pentest ]
    → sudo cat file.txt
    [sudo] password for ech0:
    MESSAGE 2
    MESSAGE 3
    MESSAGE 4
    
    
  • su : Log into the root user account
  •   λ ech0 [ 93.22.150.211 ] [ ~/Desktop/Coding/Pentest ]
    → su
    Password:
    
    λ root [ 93.22.150.211 ] [Desktop/Coding/Pentest] → cat file.txt
    MESSAGE 2
    MESSAGE 3
    MESSAGE 4
    

Part 2 : The Linux Filesystem



Concepts : syntax highlighting, text editor, chmod

Part 3 : Multiple Commands



Concepts : Pipe Concatenation, stdin/stdout/stderr, && || , output to file

  • &&, and ||
  •   λ ech0 [ 93.22.150.211 ] [ ~/Desktop/Coding/Pentest ]
    → cat NEWFILE4.py || ls
    cat: NEWFILE4.py: Permission denied
    ipsweep.sh  NEWFILE4.py
    
    λ ech0 [ 93.22.150.211 ] [ ~/Desktop/Coding/Pentest ]
    → cat NEWFILE4.py && ls
    cat: NEWFILE4.py: Permission denied
    
  • > , < , 2 >
  •   λ ech0 [ 93.22.150.211 ] [ ~/Desktop/Coding/Pentest ]
    → cat NEWFILE4.py
    cat: NEWFILE4.py: Permission denied
    
    λ ech0 [ 93.22.150.211 ] [ ~/Desktop/Coding/Pentest ]
    → cat NEWFILE4.py > /dev/null
    cat: NEWFILE4.py: Permission denied
    
    λ ech0 [ 93.22.150.211 ] [ ~/Desktop/Coding/Pentest ]
    → cat NEWFILE4.py 2> /dev/null
    
  • Pipe | and grep example
  •   λ ech0 [ 93.22.150.211 ] [ ~/Desktop/Coding/Pentest ]
    → ifconfig
    enp1s0f1: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
            ether 80:fa:5b:5b:43:34  txqueuelen 1000  (Ethernet)
            RX packets 186078  bytes 263031096 (250.8 MiB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 79100  bytes 6063644 (5.7 MiB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
            inet 127.0.0.1  netmask 255.0.0.0
            inet6 ::1  prefixlen 128  scopeid 0x10<host>
            loop  txqueuelen 1000  (Local Loopback)
            RX packets 712  bytes 61348 (59.9 KiB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 712  bytes 61348 (59.9 KiB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet 192.168.43.96  netmask 255.255.255.0  broadcast 192.168.43.255
            inet6 fe80::fdb6:ab93:652b:bbf0  prefixlen 64  scopeid 0x20<link>
            ether 0c:54:15:a8:2c:30  txqueuelen 1000  (Ethernet)
            RX packets 94353  bytes 98938553 (94.3 MiB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 46512  bytes 4860172 (4.6 MiB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    
    λ ech0 [ 93.22.150.211 ] [ ~/Desktop/Coding/Pentest ]
    → ifconfig | grep "inet"
            inet 127.0.0.1  netmask 255.0.0.0
            inet6 ::1  prefixlen 128  scopeid 0x10<host>
            inet 192.168.43.96  netmask 255.255.255.0  broadcast 192.168.43.255
            inet6 fe80::fdb6:ab93:652b:bbf0  prefixlen 64  scopeid 0x20<link>
    
    λ ech0 [ 93.22.150.211 ] [ ~/Desktop/Coding/Pentest ]
    → ifconfig | grep "inet 127"
            inet 127.0.0.1  netmask 255.0.0.0
    
    
  • Redirecting output to a file
  •   λ ech0 [ 93.22.150.211 ] [ ~/Desktop/Coding/Pentest ]
      → ls
      ipsweep.sh  NEWFILE4.py
    
      λ ech0 [ 93.22.150.211 ] [ ~/Desktop/Coding/Pentest ]
      → echo "MESSAGE 1" > file.txt
    
      λ ech0 [ 93.22.150.211 ] [ ~/Desktop/Coding/Pentest ]
      → echo "MESSAGE 2" > file.txt
    
      λ ech0 [ 93.22.150.211 ] [ ~/Desktop/Coding/Pentest ]
      → cat file.txt
      MESSAGE 2
    
      λ ech0 [ 93.22.150.211 ] [ ~/Desktop/Coding/Pentest ]
      → echo "MESSAGE 3" >> file.txt
    
      λ ech0 [ 93.22.150.211 ] [ ~/Desktop/Coding/Pentest ]
      → echo "MESSAGE 4" >> file.txt
    
      λ ech0 [ 93.22.150.211 ] [ ~/Desktop/Coding/Pentest ]
      → cat file.txt
      MESSAGE 2
      MESSAGE 3
      MESSAGE 4
    
    

    Part 4 : Scripting



    Concepts : /bin/bash , .sh files