From CP1252 to UTF-8:
$ iconv -f CP1252 -t UTF8 inputfile.txt -o outputfile.txtOr$ enconv -x UTF8 somefile.txt
Check:
$ enconv -d somefile.txtOr$ file -i somefile.txt
Remove ANSI escape codes:
$ awk '{ gsub("\\x1B\\[[0-?]*[ -/]*[@-~]", ""); print }' somefile.txt
input.txt: ASCII textVSinput.txt: ASCII text, with CRLF line terminators
From Win to Unix:
$ awk '{ sub("\r$", ""); print }' input.txt > output.txtOr$ dos2unix input.txt
From Unix to Win:
$ awk 'sub("$", "\r")' input.txt > output.txtOr$ unix2dos input.txt
$ netstat -anlp | grep LIST$ ss -nlpt | grep LIST
$ wget -q -O - https://ipinfo.io/ip
Start:CTRL + ALT + F1-6Stop:ALT + F8
$ ps aux | grep firefoxOr$ pidof firefox$ kill -15 <PID>Or$ kill -SIGTERM <PID>Or$ kill <PID>If -15 signal didn't help, use stronger -9 signal:$ kill -9 <PID>Or$ kill -SIGKILL <PID>
$ openssl enc -e -aes-128-ecb -in file.txt -out file.txt.ecb -K 10101010$ openssl enc -d -aes-128-ecb -in file.txt.ecb -out file.txt.ecb_dec -K 10101010$ echo 'secret_data1 + secret_data2 + secret_data3' | openssl enc -e -aes-256-cbc -a -salt -md sha256 -iv 10101010 -pass pass:qwerty$ echo 'U2FsdGVkX1+d1qH1M3nhYFKscrg5QYt+AlTSBPHgdB4JEP8YSy1FX+xYdrfJ5cZgfoGrW+2On7lMxRIhKCUmWQ==' | openssl enc -d -aes-256-cbc -a -salt -md sha256 -iv 10101010 -pass pass:qwerty
$ ssh-keygen -t rsa -b 4096 -N 's3cr3t_p4ssw0rd' -C '[email protected]' -f rsa_key$ mv rsa_key rsa_key.old$ openssl pkcs8 -topk8 -v2 des3 \-in rsa_key.old -passin 'pass:s3cr3t_p4ssw0rd' \-out rsa_key -passout 'pass:s3cr3t_p4ssw0rd'$ chmod 600 rsa_key$ openssl rsa -text -in rsa_key -passin 'pass:s3cr3t_p4ssw0rd'$ openssl asn1parse -in rsa_key$ ssh-keygen -o -a 100 -t ed25519 -f ~/.ssh/id_ed25519
List keychain:
$ gpg --list-keys
Gen key:
$ gpg --full-generate-key [--expert]
Gen revoke cert:
$ gpg --output revoke.asc --gen-revoke [email protected]revoke.asc
Export user's public key:
$ gpg --armor --output user.pub --export [email protected]user.pub
Import recipient's public key:
$ gpg --import recipient.pub
Sign and encrypt:
$ gpg -o/--output encrypted.txt.gpg -e/--encrypt -s/--sign -u/--local-user [email protected] -r/--recipient [email protected] plaintext.txtencrypted.txt.gpg
List recipients:
$ gpg --list-only -v -d/--decrypt encrypted.txt.gpg
Verify signature:
$ gpg --verify signed.txt.gpg$ gpg --verify signed.txt.sig signed.txt
Decrypt and verify:
$ gpg -o/--output decrypted.txt -d/--decrypt --try-secret-key [email protected] encrypted.txt.gpg$ gpg -o/--output decrypted.txt -d/--decrypt -u/--local-user [email protected] -r/--recipient [email protected] encrypted.txt.gpg
$ > logfileOr$ cat /dev/null > logfileOr$ dd if=/dev/null of=logfileOr$ truncate logfile --size 0
$ cat /dev/null > ~/.bash_history && history -c && exit
$ shred -zvu -n7 /path/to/file$ find /path/to/dir -type f -exec shred -zvu -n7 {} \\;$ shred -zv -n0 /dev/sdc1
List devices:
$ lsblk$ sudo fdisk -l$ df -h
Manage partitions:
$ sudo fdisk /dev/sd??
Format:
$ sudo umount /dev/sd??$ sudo mkfs.<type> -F 32 -I /dev/sd?? -n VOLUME-NAMEtype: 'msdos' (=fat32), 'ntfs'
$ mcopy -i floppy.img 123.txt ::123.txt$ mdel -i floppy.img 123.TXT
Compare file hashes:
$ md5sum /path/to/abc.txt | awk '{print $1, "/path/to/cba.txt"}' > /tmp/checksum.txt$ md5sum -c /tmp/checksum.txt
Compare directory hashes:
$ hashdeep -c md5 -r /path/to/dir1 > dir1hashes.txt$ hashdeep -c md5 -r -X -k dir1hashes.txt /path/to/dir2
Set defaults for files:
$ find . -type f -exec chmod 644 {} \;
Set defaults for directories:
$ find . -type d -exec chmod 755 {} \;
$ sudo crontab -l | { cat; echo '@reboot echo $((16*1024*1024)) > /proc/sys/vm/dirty_background_bytes'; } | crontab -$ sudo crontab -l | { cat; echo '@reboot echo $((48*1024*1024)) > /proc/sys/vm/dirty_bytes'; } | crontab -
Remove old kernels:
$ dpkg -l linux-image-\* | grep ^ii$ kernelver=$(uname -r | sed -r 's/-[a-z]+//')$ dpkg -l linux-{image,headers}-"[0-9]*" | awk '/ii/{print $2}' | grep -ve $kernelver$ sudo apt-get purge $(dpkg -l linux-{image,headers}-"[0-9]*" | awk '/ii/{print $2}' | grep -ve "$(uname -r | sed -r 's/-[a-z]+//')")
Install xfce4:
$ sudo apt update$ sudo apt upgrade -y$ sudo apt install xfce4 xfce4-terminal gtk2-engines-pixbuf -y
$ sudo apt install peek -yOr$ sudo apt install byzanz xdotool -y$ xdotool getmouselocation$ byzanz-record --duration=15 --x=130 --y=90 --width=800 --height=500 ~/Desktop/out.gif
$ sudo apt purge ntp -y$ sudo timedatectl set-timezone Europe/Moscow$ sudo vi /etc/systemd/timesyncd.confNTP=0.ru.pool.ntp.org 1.ru.pool.ntp.org 2.ru.pool.ntp.org 3.ru.pool.ntp.org$ sudo service systemd-timesyncd restart$ sudo timedatectl set-ntp true$ timedatectl status$ service systemd-timesyncd status$ service systemd-timedated status
XOR 2 images:
$ convert img1.png img2.png -fx "(((255*u)&(255*(1-v)))|((255*(1-u))&(255*v)))/255" img_out
Pack:
tar -cvf directory.tar directory
Unpack:
tar -xvf directory.tar
Pack:
tar -cvzf directory.tar.gz directory
Unpack:
tar -xvzf directory.tar.gz
Pack:
tar -cvjf directory.tar.bz directory
Unpack:
tar -xvjf directory.tar.bz
Local file to a remote system:
$ scp [-P 2222] file.txt [email protected]:/remote/directory
Remote file to a local system:
$ scp [-P 2222] [email protected]:/remote/file.txt /local/directory
Encrypt and pack all files in directory::
$ 7z a packed.7z -mhe -p"p4sSw0rD" *
Decrypt and unpack:
$ 7z e packed.7z -p"p4sSw0rD"
Recursive grep:
$ grep -nwr 'pattern' /path/to/dir
Recursive find and replace:
$ find . -type f -name "*.txt" -exec sed -i'' -e 's/\<foo\>/bar/g' {} +
Exec strings and grep on the result with printing filenames:
$ find . -type f -print -exec sh -c 'strings $1 | grep -i -n "signature"' sh {} \;
Find and xargs grep results:
$ find . -type f -print0 | xargs -0 grep <PATTERN>
Get absolute path of a file:
$ readlink -f somefile.txt
Concatenate text files with a delimeter line by line:
$ paste -d':' a.txt b.txt > c.txt
$ dpkg -s <package_name>$ dpkg-query -W -f='${Status}' <package_name>$ OUT="dpkg-query-$(date +'%FT%H%M%S').csv"; echo 'package,version' > ${OUT} && dpkg-query -W -f '${Package},${Version}\n' >> ${OUT}
# Mount volume$ veracrypt -t --pim=0 --keyfiles='' --protect-hidden=no /home/snovvcrash/SecretVolume.dat /mnt# Unmount all$ veracrypt -d
$ sudo openconnect --protocol=gp gp.megacorp.com -u snovvcrash
$ script ~/ws/shells/`date "+%FT%H%M%S"`.script
bash ~/.tmux/plugins/tmux-logging/scripts/screen_capture.shbash ~/.tmux/plugins/tmux-logging/scripts/save_complete_history.sh
~/.bashrc (replace ! with %):
PS1='${debian_chroot:!($debian_chroot)}[\D!d}|\D{!k:!M}] \[\033[01;32m\]λ \[\033[00m\]\[\033[01;34m\]\w\[\033[00m\] '
$ZSH_CUSTOM/themes/robbyrussell.zsh-theme (replace ! with %):
PROMPT="!(?:!{$fg_bold[green]!}➜ :!{$fg_bold[red]!}➜ ) "PROMPT+='!{$fg[cyan]!}!(4~|!-1~/…/!2~|!3~)!{$reset_color!} $(git_prompt_info)'if lsof -tac script "$(tty)" > /dev/null; thenPROMPT="[!D{!d}|!D{!k:!M}]* $PROMPT"elsePROMPT="[!D{!d}|!D{!k:!M}] $PROMPT"fi
# PHP$ sudo add-apt-repository ppa:ondrej/php -y$ sudo apt update$ sudo apt install php7.2 -y$ sudo apt install php7.2-curl php7.2-gd php7.2-json php7.2-mbstring -y# Apache$ sudo apt install apache2 libapache2-mod-php7.2 -y$ sudo service apache2 restart# MySQL$ sudo apt install mysql-server php7.2-mysql$ sudo mysql_secure_installation$ service mysql restart# Test$ sudo sh -c 'echo "<?php phpinfo(); ?>" > phpinfo.php'-> http://127.0.0.1/phpinfo.php
$ sudo apt-get install cmatrix
$ wget -O screenfetch https://raw.github.com/KittyKatt/screenFetch/master/screenfetch-dev$ chmod +x screenfetch$ sudo mv screenfetch /usr/bin