Linux/grep
Comment environmental variables
export SETUPTOOLS_ENABLE_FEATURES=legacy-editable
See distro / linux OS
lscpu$ cat /etc/*-release
See architecture
Log into root
$ sudo -s
Upload public key
$ ssh-keygen
$ vi ~/.ssh/authorized_keys
upload id_rsa.pub
SSH
$ ssh user@IP
See ports in use
lsof -i -P -n | grep LISTEN
Kill process on port
kill $(lsof -t -i:8055)
passwords
openssl
simple password encrypt (example abc)
echo abc | openssl aes-256-cbc -a -salt -pass pass:somepassword -pbkdf2
echo U2FsdGVkX1+W+KyjQ/FywzWm2EXFDe1GnT1MXweYuoU= | openssl aes-256-cbc -d -a -pass pass:somepassword -pbkdf2
mkpasswd
simple password encrypt (example abc)
echo abc | mkpasswd -m sha-512
Install packages
$ sudo apt install vim --yes
$ apt-get install vim -y
Uninstall packages
Update packages
$ sudo apt-get update
$ sudo apt-get upgrade
See environmental variables
$ env
$ printenv
Create an environmental variable
export BLOB2_KEY=aaa
Clear an environmental variable
unset BLOB2_KEY
See CPUS
$ nprocs
See RAM
$ free -h
See disk space
$ df -h
See IP address
curl -s https://checkip.amazonaws.com
See size of directory
du -sh file.zarr
Delete large number of files
for f in *.zarr; do rm -rf "$f"; done
Open a terminal
CTRL + ALT + t
Unzip tar.gz file
tar -xvf archive.tar.gz
gzip a file
gzip -c original_file > compressed_copy.gz
Put stuff from a folder to a zip file
tar -czf FOLDER.tar.gz FOLDER
Create a csv file
echo "a" > file.csv && echo "1" >> file.csv
Date
date +"%Y-%m-%dT%H:%M:%S"
date +"%Y-%m-%dT%H:%M:%S%z"
Change windows
CTRL + ALT + DOWN
See jobs
ps -ef
Kill all jobs
pkill -u USERNAME
Search for a file
...
Detect second screen
https://askubuntu.com/questions/1033785/external-monitor-not-detected-on-ubuntu-18-04
https://linuxconfig.org/how-to-install-the-nvidia-drivers-on-ubuntu-18-04-bionic-beaver-linux
$ ubuntu-drivers devices
$ sudo ubuntu-drivers autoinstall
https://www.nvidia.com/en-us/geforce/drivers/
sudo apt-get purge 'nvidia*'
sudo add-apt-repository ppa:graphics-drivers
sudo apt-get update
sudo ubuntu-drivers autoinstall
Bash
example.sh:
#!/usr/bin/bash
year=2018
echo ${year}
delete folders in a folder in a loop
for f in *; do rm -rf $f; done
Size of folder
For loop
for year in {2003..2018}; do
month_list=(01 02 03 04 05 06 07 08 09 10 11 12)
periods_list=(31 29 31 30 31 30 31 31 30 31 30 31)
i=0
for month in ${month_list[@]}; do
periods=${periods_list[$i]}
i=$(expr $i + 1)
done
simple password encrypt (example abc)
echo abc | openssl aes-256-cbc -a -salt -pass pass:somepassword -pbkdf2
echo U2FsdGVkX1+W+KyjQ/FywzWm2EXFDe1GnT1MXweYuoU= | openssl aes-256-cbc -d -a -pass pass:somepassword -pbkdf2
at
at now +1 minute
echo hello
Ctrl-D
echo echo hello world | at now
echo "command_to_be_run" | at now +1 minute
at 09:00 <<EOF
command_to_be_run
EOF
at -l | awk '{printf "%s ", $1}' | xargs atrm
Create animation
convert -delay 50 -loop 1 *.png animation.gif
Find
Replace a with b in file.txt
find file.txt -type f -exec sed -i "" "s/a/b/g" {} \;
Replace , "a"] with ] in file txt
find file.txt -type f -exec sed -i "" 's/, "a"]/]/g' {} \;