The Linux Command Line
History Management
Execute the last command with sudo
sudo !!
Recall the last argument of the previous command
!$
Recall all arguments of the previous command
!*
Execute the last command that started with grep
!grep
Quick find-and-replace in the last command
^foo^bar
Global find-and-replace in the last command
!!:gs/foo/bar/
Reverse search your command history
Ctrl+R
Built-in variables
Prints the Process ID (PID) of the current shell
echo $$
Prints the PID of the last command you sent to the background
echo $!
Prints the exit status of the last command.
echo $?
Prints the last argument of the previous command.
echo $_
Prints a random integer between 0 and 32767
echo $RANDOM
Navigation
Go back to the previous directory you were in
cd -
Push the current directory onto a stack
pushd .
Pop a directory from the stack and cd into it
popd
cd into the path of the last argument
cd $_
Networking & Localhost
Pings localhost
ping 0
ping localhost
IPv6
ping ::1
Connect to a local web server on port 8080
curl 0:8080
Process & Job Control
Suspend (pause) the currently running foreground process.
Ctrl+Z
Resume the most recently suspended job in the background
bg
Bring the most recent backgrounded or suspended job to the foreground
fg
List all suspended and backgrounded jobs.
jobs
Kill job number 1
kill %1
base64
Generate MD5 hash
md5sum <file>
Generates a SHA256 hash
sha256sum file.txt
Encoding
Encoding
Encode File + Redirect Output
base64 file.txt > hash.txt
Encode String + Redirect Output
echo "your_string_here" | base64 > encoded_file.txt
In
Base64
encoding, by default, some implementations add line breaks every 76 characters (following theRFC 2045 standard
).
Encode File Without line break
base64 -w 0 <file>
Encode String without line breaks
echo -n "your_string_here" | base64 -w 0
Safe URL encoding
base64 -w 0 <file> | tr '+/' '-_' > url_safe_encoded.txt
Decoding
Decoding
Decode String + Output to a file
echo <string> | base64 -d > <file>
Decode File + Output to a file
base64 -d -i <file> > <decoded_file>
Decode File without line breaks
base64 -d -w 0 file.txt > decoded_output.bin
Chroot
Decrypt the system
Decrypt partition
sudo cryptsetup luksOpen /dev/sda3 cryptdisk
Mounts the decrypted device
sudo mount /dev/mapper/cryptdisk /mnt
Mounts the boot partion
sudo mount /dev/sda1 /mnt/boot
chroot into a mounted partition
sudo arch-chroot /mnt
Connect using WPA
Connect using WPA
Shows connection status
wpa_cli status
Creates the passphrase
sudo wpa_passphrase "MyWiFi" "mypassword123" | sudo tee /etc/wpa_supplicant/wpa_supplicant.conf
Connect using passphrase
sudo wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf
Boot/UEFI Management
Boot/UEFI Management
Displays the current boot entries in the UEFI firmware
efibootmgr
deletes the boot entry "0"
sudo efibootmgr --delete-bootnum --bootnum 0
Last updated