Skip to content

Instantly share code, notes, and snippets.

@wewnumam
Last active December 19, 2022 01:29
Show Gist options
  • Save wewnumam/a3c081e3b43defaef336edd910777a21 to your computer and use it in GitHub Desktop.
Save wewnumam/a3c081e3b43defaef336edd910777a21 to your computer and use it in GitHub Desktop.
Command Line Notes

Command Line Notes

A reminder for me when I forget the command line I've used or the steps of a command I've done. This reminder is also my note when I have solved a problem. I hope this reminder can be useful for those of you who need it.

Table of Contents

🐧 Linux

Run in background

run command in background

YOURCOMMAND &

terminate background command

kill %1

Permission access

permission only root

chmod 755 FOLDERNAME

permission for all

chmod 777 FOLDERNAME

change owner

chown -R USERNAME FOLDERNAME

change group

chgrp -R USERNAME FOLDERNAME

open file manager as root

sudo su
gnome-opens .
sudo nautilus

Switch shell

change shell to bash

chsh -s $(which bash)

change shell to zsh

chsh -s $(which zsh)

System info

kernel version

uname -a
uname -r

linux release

lsb_release -a

Drive

mounted check

lsblk

mount drive

udisksctl mount -b /dev/sda5

ntfs read-only files error

sudo ntfsfix /dev/YOURSDALOCATION

Search files

search files by name

find /SEARCHLOCATION -type f -iname FILENAME.FILEEXTENSION

search files by extension

find /SEARCHLOCATION -type f -name '*.FILEEXTENSION'

search files by last modified

find /SEARCHLOCATION -name '*.*' -mtime -DAYS

Command history

print command history ~/.bash_history or ~/.zsh_history

history

delete command history

history -c 

search command history

CTRL + R

Edit date

touch -a -m -t 201512180130.00 FILENAME.FILEEXT
command description
a accessed
m modified
t timestamp
[[CC]YY]MMDDhhmm[.ss] format

for loop in terminal

for file in *.jpg; do convert $file -quality 50 ../convert/$file; done

Alias

alias graph="git log --all --decorate --oneline --graph"

Install .deb file

sudo dpkg -i /path/to/deb/file
sudo apt-get install -f

Systemctl

start service

systemctl start docker

DNS can't be reached

sudo rm /etc/resolv.conf  
echo 'nameserver 8.8.8.8' | sudo tee -a /etc/resolv.conf 

🛠 Utilities

Git

repository size check

git count-objects -vH

remote connection test

ssh -T git@github.com

push to different branch name

git push origin LOCALBRANCH:REMOTEBRANCH

push all branch

git push origin --all

delete remote branch

git push --delete origin REMOTEBRANCH

breaks the fast-forward rule (git refs error)

git push --force-with-lease 

SSH

create ssh

ssh-keygen

switch ssh

eval "$(ssh-agent -s)"
ls -al ~/.ssh
ssh-add ~/.ssh/id_rsa

connect ssh

ssh USER@HOST
ssh -i KEYFILE USER@HOST

wget (download webpage)

wget URL

Compress pdf (ghostscript)

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=OUTPUT.pdf INPUT.pdf
-dPDFSETTINGS Description
/screen Has a lower quality and smaller size. (72 dpi)
/ebook Has a better quality, but has a slightly larger size (150 dpi)
/prepress Output is of a higher size and quality (300 dpi)
/printer Output is of a printer type quality (300 dpi)
/default Selects the output which is useful for multiple purposes. Can cause large PDFS.

merge pdf

qpdf --empty --pages *.pdf -- OUTPUT.pdf

snap app permission denied

snap connect gimp:removable-media :removable-media

youtube-dl

show available format

youtube-dl -F URL

download by format

youtube-dl -f FORMATID URL

fix filename error

youtube-dl <url> -o './%(id)s.%(ext)s'

Imagemagick

convert INPUT.png OUTPUT.jpg

OptiPNG

optipng -o7 INPUT.png

FFMPEG

compress video file size

ffmpeg -i INPUT.mp4 -vcodec libx265 -crf 20 OUTPUT.mp4

merge video and audio

ffmpeg -i VIDEO.mp4 -i AUDIO.wav -c:v copy -c:a aac OUTPUT.mp4

Lame

compress audio file size

lame --mp3input -b 128 INPUT.mp3 OUTPUT.mp3

Public IP

curl ifconfig.me

Extract archive

7z x FILENAME.zip
tar -xvf FILENAME.tar.gz
unrar x FILENAME.rar

⚙️ Development

PHP

php server

php -S localhost:8000

·

see service running

sudo netstat -plnt

·

failed to listen on localhost:8080

ps -ef | grep php
kill -9 RUNTIMEID

XAMPP

sudo /opt/lampp/lampp start
sudo /opt/lampp/manager-linux-x64.run

mysql in command line

sudo /opt/lampp/lampp startmysql
sudo /opt/lampp/bin/mysql -u root

PostgreSQL

postgresql in command line

systemctl start postgresql
sudo -u postgres psql -U postgres

postgresql export

pg_dump -U postgres dbname > /PATH/FILENAME.sql

postgresql import

pgsql -U postgres dbname < /PATH/FILENAME.sql

postgresql import csv

psql -d dbname -c "COPY tablename (columnname) FROM stdin WITH DELIMITER AS ','" < /dir/file.csv

Update NodeJS

sudo npm cache clean -f
sudo n stable
sudo npm install -g n

Python virtual environment

make python virtual env

python3 -m venv FOLDERNAME

activate python virtual env

source FOLDERNAME/bin/activate

Dotnet

dotnet create new project

dotnet new console -n PROJECTNAME

Apache setup for C++ .cgi (Ubuntu)

Enable CGI module

sudo ln -s /etc/apache2/mods-available/cgi.load /etc/apache2/mods-enabled/

Add this configuration inside <Directory /var/www/> on /etc/apache2/apache2.conf

<Directory /var/www/>
Options +ExecCGI
AddHandler cgi-script .cgi
</Directory>

Restart Apache2

systemctl restart apache2

Compile your cpp file and put to /var/www/html/

sudo g++ FILENAME.cpp -o /var/www/html/FILENAME.cgi

Manjaro java set version

archlinux-java help
archlinux-java status
archlinux-java set VERSION

Docker

docker permission denied solution 1

sudo chmod 666 /var/run/docker.sock

solution 2 (only run when newgrp docker is activate)

sudo groupadd docker
sudo usermod -aG docker $USER
newgrp docker

·

docker list container

docker ps -a

docker remove images

docker rmi IMAGEID

docker build Dockerfile

docker build -t REPOSITORYNAME:TAGNAME .

dokcer run container with exposing port

docker run -d -p 8080:80 REPOSITORYNAME:TAGNAME

docker run and entering container

docker run -it alpine /bin/sh

docker entering a running container

docker start CONTAINER
docker exec -it CONTAINER YOURCOMMAND

docker run and attach file then remove container after execution

docker run -p 8080:8080 --rm -v $(pwd):$(pwd) php:latest php -S 0.0.0.0:8080 $(pwd)/index.php


🪄 Etc

GNU Grub menu

insmod part_gpt
insmod chain
set root=(hd0,gpt1)
chainloader /EFI/Microsoft/Boot/bootmgfw.efi
boot

adb

device list and usb debugging

adb devices

uninstall package

adb shell
pm list packages -s
pm uninstall --user 0 com.YOURPACKAGE.BLA.BLA.BLA

Setup Huion H640P (Ubuntu/Debian-based)

sudo apt-get install -y "linux-headers-$(uname -r)"
sudo apt-get install -y dkms

to setup buttons, add the following code in .bashrc or .zshrc

if xsetwacom list | grep -q "HUION"; then
  xsetwacom set "HUION Huion Tablet_H640P Pad pad" button 1 key Ctrl s
  xsetwacom set "HUION Huion Tablet_H640P Pad pad" button 2 key e
  xsetwacom set "HUION Huion Tablet_H640P Pad pad" button 3 key b
  xsetwacom set "HUION Huion Tablet_H640P Pad pad" button 8 key Shift
  xsetwacom set "HUION Huion Tablet_H640P Pad pad" button 9 key Ctrl
  xsetwacom set "HUION Huion Tablet_H640P Pad pad" button 10 key Ctrl z
fi

NOTE: open/restart terminal to activate the code


Nmap

search active host

nmap -sP 192.168.0.1/24

scanning all active host

nmap -v -A 192.168.1.1/24

geo location

nmap -p80 --script ip-geolocation-geoplugin TARGET

Gobuster dir view

./gobuster dir -u URL -w WORDLISTFILE.txt

Aircrack-ng

airmon-ng start wlp4s0
airodump-ng wlp4s0mon
airodump-ng -c CHANNEL --bssid BSSID --write FILENAME wlp4s0mon
aireplay-ng --deauth 50 -a BSSID wlp4s0mon
aircrack-ng FILENAME.cap -w WORDLISTFILE.txt
airmon-ng stop wlp4s0mon

Bitlocker

sudo fdisk -l
sudo dislocker -r -V /dev/sdb1 -u -/media/bitlocker
sudo mount -r -o loop /media/bitlocker/dislocker-file /media/mount

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment