adduser [USER]
/ deluser [USER]
& rm -r /home/[USER]
adduser [USER] [GROUP]
/ groupdel [GROUP]
usermod -l [NEWUSER] [OLDUSER]
usermod -d /home/[NEWUSER] -m [NEWUSER]
groupmod -n [NEWUSER] [OLDUSER]
hostnamectl set-hostname [HOSTNAME]
sudo chown -R [USER]:[GROUP] [DIRECTORY]
sudo chmod [ugo+-rwx] / [664] [FILE/DIRECTORY]
sha256sum [FILE]
ln -s [SOURCE] [DEST]
sudo ps aux
sudo kill -9 [PROCESS_ID]
/ sudo killall -9 [PROCESS_NAME]
sudo apt remove --auto-remove [PACKAGE]
df -h --total
du -sh
/ du -h --max-depth=2 [DIRECTORY]
/ du -ha | grep -v "/sys/" | grep M
nohup [COMMAND] </dev/null >/dev/null 2>&1 &
+ Ctrl-Cssh-keygen -t ed25519 -C [COMMENT] -f [KEY_DEST]
ssh-keygen -o -p -f [KEY_FILE]
ssh-keygen -f [KEY_FILE] -y > [PUB_KEY_DEST]
df -Th
badblocks -wsv -b 4096
jobs -l
/ bg [JOB_ID]
zip -r [ZIPFILENAME] [DIRECTORY]
scp -rp user@example.com:"'web/tmp/Master File 13.xls'" ./
eval $(ssh-agent)
find ./ -type f -exec sudo chmod 644 {} \;
-kill -9 $$(ps aux | grep "[PROCESSNAME]" | grep -v "grep" | grep -oP '\d+' | head -n1)
rename -v -n "s/[SEARCH](.*)/[REPLACE]\1/" [WILDCARD]
who -a
, ps aux | egrep "sshd: [a-zA-Z]+@"
, kill [PID]
sudo strace -p <PID> -s9999 -e write
grep -RInwe <TEXT>
journalctl -b -1 -e
File copy hacks that track progress, from most GNU-compatible to least (i.e. need to install new libraries):
user:~$ curl -o [DST] file://[SRC] # does not copy permissions user:~$ dd if=[SRC] of=[DST] status=progress # does not copy permissions user:~$ rsync -ah --info=progress2 [SRC] [DST] user:~$ pv [SRC] > [DST] # does not copy permissions user:~$ cp [SRC] [DST]; progress -w # monitors existing, but needs tty
On BTRFS partitions, need to be careful to avoid double-counting of disk space, since there is shared memory. Typically interface disk commands through btrfs
utility.
sudo du --max-depth=1 -h /.snapshots/
sudo btrfs filesystem du -s /.snapshots/*
sudo btrfs fi usage /
For rescuing disk full problems, see here.
netstat -tuplen
curl --interface [INTERFACE] ifconfig.me
icanhazip.com
seems unstable as of Mar 24.lsof -nPi
ip addr
wget -o [FILENAME] [URL]
sudo ip link set dev [INTERFACE] down
sudo ip link set dev [INTERFACE] address [MAC]
nc -kls 10.10.10.3 -p 4444
echo "test" | nc 10.10.10.3 4444
sudo nginx -t
sudo systemctl reload nginx
cat /var/log/nginx/error.log | less / tail -n10
sudo vim /etc/php/[VER]/fpm/php.ini
sudo systemctl restart php[VER]-fpm
php -m | grep [MODULE_NAME]
sudo /etc/init.d/mysql start
sudo mysql -uroot -p
(no password as root)sudo certbot --nginx
openssl pkcs12 -export -out [P12_NAME] -inkey [KEY_FILE] -in [CA_CHAIN_FILE]
openssl s_server -key key.pem -cert cert.pem
sudo systemctl start docker
sudo systemctl status docker
docker ps
docker build --network host --no-cache --rm -t [AUTHOR]/[NAME]:[TAG] .
docker info
docker exec -it [CONTAINER] sh
docker logs -f [CONTAINER]
docker images -f "dangling=true" -q
docker rmi $(docker images -f "dangling=true" -q )
docker image tag [IMAGE_ID] [ORG]/[NAME]:[TAG]
docker system prune --volumes
docker volume prune -f
docker inspect [NAME] | grep "working_dir"
docker-compose up -d [CONTAINER...]
docker-compose down --rmi all
git config user.email [EMAIL]
or user.name [NAME]
git config --global core.editor vim
git commit --amend --reset-author --no-edit
git commit --amend --author "[NAME] <[EMAIL]>" --no-edit
git reset --hard && git clean -dfx
git diff > [FILE]
git apply --whitespace=fix --reject [FILE]
wiggle --replace [FILE] [FILE.rej]
git add -p .
git rebase -i [COMMIT/--root]
git rebase --continue
git commit --fixup=[COMMIT]
git stash
git rebase -i --autosquash [COMMIT]^
git stash pop
git config --global rebase.autoSquash true
By default, GPG keys are used for signing commits (manually using -S
flag).
As of Git 2.34 (Nov 2021), SSH keys can also be used to sign commits.
git config --global commit.gpgsign true
git config --global gpg.format ssh
git config --global user.signingkey [PUB_KEY]
git log --show-signature
("No signature" for SSH)git config --global alias.adog "log --all --decorate --oneline --graph"
git branch -a --sort=-committerdate
git reflog expire --expire-unreachable=now --all && git gc --prune=now
apt install git-svn
gitk
[core] autocrlf = false [alias] adog = log --all --decorate --oneline --graph
openssl rand -hex 12
time dd if=/dev/zero of=/path/to/nfs/testfile bs=16k count=64k
sudo visudo -f [USER]
Defaults timestamp_timeout 15
sudo dpkg-reconfigure console-setup
setfont latarcyrheb-sun32
, listed in /usr/share/kbd/consolefonts/
head -c [NUM_BYTES] [FILENAME]
sudo apt-mark showmanual
ufw show added
Create PDF pages:
# Create blank page using Ghostscript # '/etc/ImageMagick-6/policy.xml' contains a policy setting rights # to "none" for pattern "PDF" under the coder domain. This should be disabled # (by commenting out) in order to use ghostscript for pdf. Note security concerns. user:~$ convert xc:none -page A4 blank.pdf user:~$ convert xc:none -page 842x595 blank.pdf # horizontal # Create blank page using 'ps2pdf' user:~$ echo "" | ps2pdf -sPAPERSIZE=a4 - blank.pdf # Append blank page, uses 'pdftk' # Converts 'file.pdf' -> 'notes_file.pdf' user:~$ export FILE=file.pdf user:~$ pdftk A=$FILE B=blank.pdf cat A1-end B output notes_$FILE.pdf # Interleave blank pages, uses 'pdftk' user:~$ export FILE=file.pdf user:~$ export NUM=`pdftk $FILE dump_data | grep NumberOfPages | awk '{print $2}'` user:~$ pdftk blank.pdf cat $(printf '1 %.0s' $(seq $NUM)) output multiblank.pdf user:~$ pdftk A=$FILE B=multiblank.pdf shuffle A B output notes_$FILE
> time dd if=/dev/zero of=/path/to/nfs/testfile bs=16k count=64k 65536+0 records in 65536+0 records out 1073741824 bytes (1.1 GB, 1.0 GiB) copied, 91.903 s, 11.7 MB/s real 1m31.907s user 0m0.035s sys 0m1.307s > time dd if=/path/to/nfs/testfile of=/dev/null bs=16k count=64k 65536+0 records in 65536+0 records out 1073741824 bytes (1.1 GB, 1.0 GiB) copied, 91.6337 s, 11.7 MB/s real 1m31.639s user 0m0.075s sys 0m1.196s
[Unit] Description={{DESCRIPTION HERE}} Wants=network-online.target After=network-online.target [Service] User=root Group=root Type=simple ExecStart={{PROGRAM HERE}} [Install] WantedBy=multi-user.target
Keeping pipes open while writing:
mkfifo mypipe exec 3>mypipe # open file descriptor with writes piped to mypipe echo "stuff" >> mypipe echo "morestuff" >> mypipe exec 3>&- # close file descriptor, which closes mypipe
Use Ctrl-R
to invoke command searching (as opposed to the bang-expansion method that immediately invokes the command). Other controls:
Ctrl-A
and Ctrl-E
to move to front / backCtrl-K
to delete from cursor onwards# ~/.bashrc: executed by bash(1) for non-login shells. # If not running interactively, don't do anything case $- in *i*) ;; *) return;; esac # don't put duplicate lines or lines starting with space in the history. # See bash(1) for more options HISTCONTROL=ignoreboth # append to the history file, don't overwrite it shopt -s histappend # for setting history length see HISTSIZE and HISTFILESIZE in bash(1) HISTSIZE=1000 HISTFILESIZE=-1 # enable color support of ls and also add handy aliases if [ -x /usr/bin/dircolors ]; then test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" alias ls='ls --color=auto' #alias dir='dir --color=auto' #alias vdir='vdir --color=auto' alias grep='grep --color=auto' alias fgrep='fgrep --color=auto' alias egrep='egrep --color=auto' fi # colored GCC warnings and errors export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01' # some more ls aliases alias ll='ls -alF' alias la='ls -A' alias l='ls -CF' alias ..='cd ..' # Add timestamps to 'history' command HISTTIMEFORMAT="%F %T " # Allow alias execution in sudo, e.g. "sudo ll" # see https://askubuntu.com/a/22043 # If the last character of the alias value is a space or tab character, # then the next command word following the alias is also checked for # alias expansion. alias sudo='sudo ' # Go to latest directory cdl() { cd "$(\ls -1dt ./*/ | head -n 1)" && ls -rt }
# Enables better *-wildcard completion set show-all-if-ambiguous on "\t": glob-complete-word
" Load internal configuration as well, if exists " To see what was loaded, use :script runtime defaults.vim " Enable the FileType plugin filetype plugin indent on " Defaults for unknown files set tabstop=4 " ts: show existing tab with 4 spaces width set softtabstop=4 " sts: Sets the number of columns for a TAB set shiftwidth=4 " sw: when indenting with '>', use 4 spaces width set expandtab " On pressing tab, insert 4 spaces " Use :retab to convert existing tabs to space " EXCEPTIONS " To see list of filetypes available, type ':setfiletype ' and Ctrl-D " yaml, especially for docker-compose autocmd FileType yaml setlocal ts=2 sts=2 sw=2 expandtab " Enable relative line numbers set relativenumber " rnu: add left-margin with line numbers relative to cursor set number " replace cursor line number from 0 to absolute number " Optional: Set vim colorscheme colorscheme codedark " Highlight git merge conflicts " Adapted from: <https://vi.stackexchange.com/a/19760> function! ConflictsHighlight() abort syn region conflictStart start=/^<<<<<<< .*$/ end=/^\ze\(=======$\||||||||\)/ syn region conflictMiddle start=/^||||||| .*$/ end=/^\ze=======$/ syn region conflictEnd start=/^\(=======$\||||||| |\)/ end=/^>>>>>>> .*$/ highlight conflictStart ctermbg=red ctermfg=black highlight conflictMiddle ctermbg=blue ctermfg=black highlight conflictEnd ctermbg=green cterm=bold ctermfg=black endfunction augroup MyColors autocmd! autocmd BufEnter * call ConflictsHighlight() augroup END
:%s/\s\+$//e
cd "$(dirname "$0")"
For VSCode dark mode color scheme:
# User colorscheme mkdir -p ~/.vim/pack/themes/start git clone https://github.com/tomasiser/vim-code-dark ~/.vim/pack/themes/start/vim-code-dark # System colorscheme # Use the target location: "/usr/share/vim/vim{{VERSION}}/pack/themes/start" sudo mkdir -p /usr/share/vim/vim82/pack/themes/start git clone https://github.com/tomasiser/vim-code-dark /usr/share/vim/vim82/pack/themes/start/vim-code-dark
Other color schemes.