This is a bookmark-able reference to commonly used commands in Unix-like environments.
tar
Basic tar commands. Remember this one?
tar czf file.tar.gz <files> # create a tarballtar xzf file.tar.gz # extract a tarballdd
Useful for creating files of arbitrary size with pseudorandom content.
dd if=/dev/urandom of=target-file bs=1M count=10if is the input file, of is the output file, and bs is the block size.
count is number of blocks to read from if and write to of.
split
Splitting files. Use -d for numeric suffixes.
split -b 8K <file> <prefix-name> # split a file into 8kb chunkssplit -n 128 <file> # split a file into 128 chunksscp
Basic copy syntax. Use -r for copying directories recursively.
scp -i path_to_secret.pem local_file.txt remote_username@10.10.0.2:/remote/directoryscp -i path_to_secret.pem remote_username@10.10.0.2:/remote/file.txt /local/directoryscp user1@host_1.com:/files/file.txt user2@host_2.com:/filesssh
Generate an RSA SSH key:
ssh-keygen -t rsa -b 2048 -C "foo@bar.com"SSH config example Host block
# ~/.ssh/configHost <name> Hostname <ipv4> User <user> Port <port> IdentitiesOnly <yes/no> IdentityFile <path_to_secret>To proxy using a bastion host, use the following directive in the config.
ProxyCommand ssh -W %h:%p <name-of-jump-server> # Add an SSH key to authentication agentssh-add -K ~/.ssh/id_rsa# ~/.ssh/config (bg SSH session with port forwarding# e.g. running remote jupyter notebooks)Host foo Hostname <ipv4> User <user> IdentityFile <path_to_secret>$ ssh -NfL 9999:localhost:8888 foopsql
Common PostgreSQL slash commands
\l # list databases \c orders # switch to database 'orders' \dt # list tables \conninfo # echo connection info \des # list foreign servers \dew # list foreign data wrappers \? # get meta-command helpConnect to a PostgreSQL database
psql -h <host> -p <port> -d <db> -U <user>