Skip to content

aperlini/cmds-snippets

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 

Repository files navigation

Commands Snippets

commands history : things I tend to forget and look for afterward

Archives

Extract compressed archives with correct options

tar -xjf  comp-archive-123.tar.bz2 # -j (bzip2)
tar -xvzf comp-archive-123.tar.gz  # -z (gzip)
tar -xf   comp-archive-123.tar.xz

Assembly

x86_64

Using nasm to assemble and GNU linker to generate executable

nasm -f elf64 <prog>.asm -g # -f = format
ld <prog>.o -o <prog>

Compilation

Saving intermediate files from compilation (.i, .s, .o) using gcc

gcc main.c --save-temps -o main

Compile and link program w/ static library

gcc main.c -o main -I libs -L libs -labcd
# .
# ├── libs
# │   ├── libabcd.a
# │   └── libabcd.h
# └── main.c

Databases

sqlite3 usage

sqlite3 dbname.sqlite
.schema # display database schema
.exit

Debugging

GDB

Using GNU debugger to inspect code in asm

gcc prog.c -o prog -g # compile source using debugging options
gdb ./prog # start gdb
(gdb) b main # set breakpoint at main entry point
(gdb) run # start program
(gdb) layout asm # apply the asm layout for inspection

disassembly style

(gdb) show disassembly-flavor
(gdb) set disassembly-flavor intel
(gdb) set disassembly-flavor att

Docker

MySQL container

Connect to MySQL container

docker exec -it <container_name> mysql -u<user> -p<pass>

Export database

docker exec -i <container_name> mysqldump --no-tablespaces -u<user> -p<pass> <db_name> > <backup_name>.sql

File manipulations

Rename and remove underscore from files in current folder

for f in _*; do mv -v "$f" $(echo "$f" | tr -d '_'); done

Generate html file from RTF files based on their basename and content

for f in *.rtf; do echo -E "$(basename -s .rtf "## $f") $(unrtf --quiet "$f")" >> index.html; done

Create the same file in all subdirectories

for d in ./*/; do cd "$d" && touch file.txt && cd ..; done

Find and print all files starting with ".DS_"

find -type f -name ".DS_*" -print

Find all file occurences starting with "._" and delete them

find -type f -name "._*" -delete

Find folder and delete its content

find -type d -name "foldername" -exec rm -rf {} \;

Find modified files at a certain date

find -type f -name "*.cpp" -newermt yyyy-mm-dd

Copy output of command to clipboard

pwd | xclip -i 

Display file permission bits in octal

stat -c "%a %n" <filename>

Display lines (range) in file

sed -n 1,10p file.txt

Delete lines (range) in file

sed -i 1,10d file.txt # option -i : --in-place

Git

Remove remote origin of git repository

git remote remove origin

Change remote origin of git repository

git remote add origin git@github.com:User/repo.git

Changing commit message that hasn't been pushed

git commit --amend -m "modified commit msg"

ImageMagick

Resize image while keeping (height or width) ratio

mogrify -resize x450 my_img.jpg # preserve height
mogrify -resize 850x my_img.jpg # preserve width

Crop image

mogrify -crop 100x100+0+0 my_img.jpg # crop 100x100px from x=0, y=0

Convert format

mogrify -format jpeg image.ppm # from .ppm to .jpeg

Display image size infos

identify -format "%wx%h" img.jpg

Vertically stack images

convert <img-1> <img-2> -append <result-img>

+append : to concatenate images horizontally

Network

iproute2

Display current available network interfaces

ip -c -br link

Display IPv4 addresses

ip -c -br -4 a

OpenSSL

Generate new private key

openssl genpkey -out <pri_key> \ 
-algorithm RSA \
-pkeyopt rsa_keygen_bits:<key-size> \
-aes-256-cbc

key is protected with passphrase using AES-256

Derive public key

openssl rsa -in <pri_key> -pubout -out <pub_key>

Key structure information

openssl rsa -in <pri_key> -text -noout

add -pubin params to specify public key

Python

Setup environment and install project dependencies w/ pip

python3 -m venv venv # will create target dir 'venv' for virtual env
source venv/bin/activate
pip install -r requirements.txt

Save current state of virtual environment in requirements.txt :

pip freeze >> requirements.txt

Resolution

Display current screen resolution

xdpyinfo | grep "dimensions"

Scripts

Adding custom commands (from bash scripts)

Add new script inside /home/user/ dedicated directory

├── scripts
└────── custom.sh

add execution / read permissions

chmod u+rx custom.sh

create symlink from .local/bin folder to make script available from the command line :

ln -s /home/user/scripts/custom.sh custom.sh

declare function inside /home/user/.bash_functions:

function call_script {
	~/.local/bin/custom.sh
}

then source :

source .bash_functions

SSH pubkey

copy (rsa) public key content to clipboard

xclip -sel clip < ~/.ssh/id_rsa.pub # shorthand for : -select clipboard

Tmux

Basic usage

ctrl + b : default prefix

Panel split

prefix + % : vertical split

prefix + " : horizontal split

prefix + q : panel number

prefix + o : switch between panels

prefix+ alt + ↑ ↓ ← → : to increase / decrease panel size

prefix + z : zoom / de-zoom

prefix + x : close panel

Plugins

to install new plugins, edit .tmux.conf :

set -g @plugin 'plugin/path'

then prefix + I to fetch the plugin

Vim

search and replace pattern (all occurences)

:%s/{find}/{replace}/g

Wget

Saving remote file in specified directory

wget https://.../resource.jpg -P /to/directory/path

About

Commands history

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published