Skip to content

Instantly share code, notes, and snippets.

@flc
Last active May 25, 2022 14:20

Revisions

  1. flc revised this gist Nov 1, 2021. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions commands.txt
    Original file line number Diff line number Diff line change
    @@ -178,3 +178,6 @@ openssl s_client -connect example.com:443 -tls1_3

    # list all the processes currently listening
    ss -ltup

    # delete files older than 180 days in the current directory tree
    find . -type f -mtime +180 | xargs rm
  2. flc revised this gist Apr 22, 2021. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions commands.txt
    Original file line number Diff line number Diff line change
    @@ -175,3 +175,6 @@ openssl s_client -connect example.com:443 -tls1_1
    openssl s_client -connect example.com:443 -tls1_2
    # TLS1.3
    openssl s_client -connect example.com:443 -tls1_3

    # list all the processes currently listening
    ss -ltup
  3. flc revised this gist Apr 21, 2021. 1 changed file with 9 additions and 1 deletion.
    10 changes: 9 additions & 1 deletion commands.txt
    Original file line number Diff line number Diff line change
    @@ -166,4 +166,12 @@ sudo lsof -i -P -n | grep LISTEN

    # git | delete all local branches that are gone
    # will not delete branches that are not fully merged
    git branch -vv | grep gone | cut -d " " -f3 | xargs git branch -d
    git branch -vv | grep gone | cut -d " " -f3 | xargs git branch -d

    # check TLS connections
    # TLS1.1
    openssl s_client -connect example.com:443 -tls1_1
    # TLS1.2
    openssl s_client -connect example.com:443 -tls1_2
    # TLS1.3
    openssl s_client -connect example.com:443 -tls1_3
  4. flc revised this gist Apr 13, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion commands.txt
    Original file line number Diff line number Diff line change
    @@ -165,5 +165,5 @@ ssh-keygen -t rsa -b 4096 -C "<optional_comment>"
    sudo lsof -i -P -n | grep LISTEN

    # git | delete all local branches that are gone
    # will not delete branches that are nto fully merged
    # will not delete branches that are not fully merged
    git branch -vv | grep gone | cut -d " " -f3 | xargs git branch -d
  5. flc revised this gist Apr 12, 2021. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions commands.txt
    Original file line number Diff line number Diff line change
    @@ -100,6 +100,7 @@ tail -n +2 file.csv | awk -F "," '$2 >= <my threshold value>' | wc -l

    # pg_dump ssh tunnel
    ssh -o "Compression=no" mydbserver "pg_dump -Fc -Z9 -U postgres mydb" > mydb.dump
    ssh -i <private_key_path> -o "Compression=no" yourdomain.com "pg_dump --username=<username> --host=localhost --blobs --verbose --format=c --compress=9 <db_name>" > mydb.dump

    # generate random password
    # of course there are tons of ways to do this
  6. flc revised this gist Apr 6, 2021. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion commands.txt
    Original file line number Diff line number Diff line change
    @@ -161,4 +161,8 @@ cat -A file
    ssh-keygen -t rsa -b 4096 -C "<optional_comment>"

    # check listening ports and applications
    sudo lsof -i -P -n | grep LISTEN
    sudo lsof -i -P -n | grep LISTEN

    # git | delete all local branches that are gone
    # will not delete branches that are nto fully merged
    git branch -vv | grep gone | cut -d " " -f3 | xargs git branch -d
  7. flc revised this gist Jan 27, 2021. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion commands.txt
    Original file line number Diff line number Diff line change
    @@ -158,4 +158,7 @@ sed -e "s/\r//g" file > newfile
    cat -A file

    # generate ssh key
    ssh-keygen -t rsa -b 4096 -C "<optional_comment>"
    ssh-keygen -t rsa -b 4096 -C "<optional_comment>"

    # check listening ports and applications
    sudo lsof -i -P -n | grep LISTEN
  8. flc revised this gist Sep 4, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion commands.txt
    Original file line number Diff line number Diff line change
    @@ -125,7 +125,7 @@ openssl enc -aes-256-cbc -md sha512 -pbkdf2 -iter 1000 -salt -in <file> -out <en
    openssl aes-256-cbc -d -md sha512 -pbkdf2 -iter 1000 -in <encrypted_file> -out <file> -k <passphrase>

    # generate your dhparam.pem file
    openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
    openssl dhparam -out /etc/nginx/ssl/dhparam.pem 4096

    # search for pattern in codebase
    grep -inIEr --color=ALWAYS "<pattern_to_search>" .
  9. flc revised this gist May 7, 2020. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion commands.txt
    Original file line number Diff line number Diff line change
    @@ -155,4 +155,7 @@ sed -i -e '$a\' file
    sed -e "s/\r//g" file > newfile

    # check for all visible characters
    cat -A file
    cat -A file

    # generate ssh key
    ssh-keygen -t rsa -b 4096 -C "<optional_comment>"
  10. flc revised this gist Sep 25, 2019. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions commands.txt
    Original file line number Diff line number Diff line change
    @@ -13,6 +13,9 @@ tail -n +2 file > new_file
    # remove first line of the file (less efficient)
    sed 1d file > newfile

    # show from a specific line number <number> till the end of the file
    tail -n +<number> file

    # count how many lines of a file contain a pattern
    cat file | grep pattern | wc -l
    grep pattern -c file
  11. flc revised this gist Jun 28, 2019. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions commands.txt
    Original file line number Diff line number Diff line change
    @@ -43,6 +43,12 @@ tar -xzf archive.tar.gz
    # view an tar archive
    tar tvf archive.tar.gz

    # create uncompressed tar archive
    tar -cvf archive.tar dirname

    # extract uncompressed tar archive
    tar -xvf archive.tar dirname

    # extract tar.bz2
    tar jxf filename.tar.bz2

  12. flc revised this gist Jun 14, 2019. 1 changed file with 7 additions and 1 deletion.
    8 changes: 7 additions & 1 deletion commands.txt
    Original file line number Diff line number Diff line change
    @@ -140,4 +140,10 @@ rsync -avz -e "ssh -i <ssh_key_path> -o StrictHostKeyChecking=no -o UserKnownHos
    find . -type f | wc -l

    # adds newline at the end of the file if it doesn't already end with a newline
    sed -i -e '$a\' file
    sed -i -e '$a\' file

    # remove CTRL-M (^M) characters from a file
    sed -e "s/\r//g" file > newfile

    # check for all visible characters
    cat -A file
  13. flc revised this gist May 29, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion commands.txt
    Original file line number Diff line number Diff line change
    @@ -121,7 +121,7 @@ openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
    # search for pattern in codebase
    grep -inIEr --color=ALWAYS "<pattern_to_search>" .

    # searcg for pattern in files with specific extension (.py in the example)
    # search for pattern in files with specific extension (.py in the example)
    find . -iname '*.py' | xargs grep -inIE --color=ALWAYS "<pattern_to_search>"

    # copy directory tree recursively without overwrite
  14. flc revised this gist May 29, 2019. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions commands.txt
    Original file line number Diff line number Diff line change
    @@ -121,6 +121,9 @@ openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
    # search for pattern in codebase
    grep -inIEr --color=ALWAYS "<pattern_to_search>" .

    # searcg for pattern in files with specific extension (.py in the example)
    find . -iname '*.py' | xargs grep -inIE --color=ALWAYS "<pattern_to_search>"

    # copy directory tree recursively without overwrite
    rsync -a -v --ignore-existing <src_dir> <dst_dir>

  15. flc revised this gist Apr 15, 2019. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions commands.txt
    Original file line number Diff line number Diff line change
    @@ -111,6 +111,10 @@ sudo reboot
    openssl aes-256-cbc -salt -in <file> -out <encrypted_file> -k <passphrase>
    openssl aes-256-cbc -d -in <encrypted_file> -out <file> -k <passphrase>

    # encrypt/decrypt file with openssl NEW
    openssl enc -aes-256-cbc -md sha512 -pbkdf2 -iter 1000 -salt -in <file> -out <encrypted_file> -k <passphrase>
    openssl aes-256-cbc -d -md sha512 -pbkdf2 -iter 1000 -in <encrypted_file> -out <file> -k <passphrase>

    # generate your dhparam.pem file
    openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048

  16. flc revised this gist Mar 20, 2018. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions commands.txt
    Original file line number Diff line number Diff line change
    @@ -104,6 +104,9 @@ sudo chage -d 0 <username>
    sudo shutdown -h now
    sudo poweroff

    # server restart / reboot
    sudo reboot

    # encrypt/decrypt file with openssl
    openssl aes-256-cbc -salt -in <file> -out <encrypted_file> -k <passphrase>
    openssl aes-256-cbc -d -in <encrypted_file> -out <file> -k <passphrase>
  17. flc revised this gist Nov 16, 2017. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion commands.txt
    Original file line number Diff line number Diff line change
    @@ -127,4 +127,7 @@ lsof -Fpcn | nawk '/^p/ { pid=substr($0,2) } /^c/ { cmd=substr($0,2) } /^n/ { fd
    rsync -avz -e "ssh -i <ssh_key_path> -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" --progress <file> <username>@<remote_ip>:<remote_dir>

    # count files in a directory recursively
    find . -type f | wc -l
    find . -type f | wc -l

    # adds newline at the end of the file if it doesn't already end with a newline
    sed -i -e '$a\' file
  18. flc revised this gist Aug 30, 2017. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion commands.txt
    Original file line number Diff line number Diff line change
    @@ -124,4 +124,7 @@ ps -e -orss,%mem,cputime,%cpu,pid,args | sort -b -k1,1n | pr -TW$COLUMNS
    lsof -Fpcn | nawk '/^p/ { pid=substr($0,2) } /^c/ { cmd=substr($0,2) } /^n/ { fd[cmd"["pid"]"]++ } END { for (cc in fd) printf("%-30s %i\n",cc,fd[cc]) } ' | sort -n -k 2 | tail -30

    # copy file with rsync over SSH
    rsync -avz -e "ssh -i <ssh_key_path> -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" --progress <file> <username>@<remote_ip>:<remote_dir>
    rsync -avz -e "ssh -i <ssh_key_path> -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" --progress <file> <username>@<remote_ip>:<remote_dir>

    # count files in a directory recursively
    find . -type f | wc -l
  19. flc revised this gist Aug 25, 2017. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions commands.txt
    Original file line number Diff line number Diff line change
    @@ -122,3 +122,6 @@ ps -e -orss,%mem,cputime,%cpu,pid,args | sort -b -k1,1n | pr -TW$COLUMNS

    # find processes with maximum file descriptors
    lsof -Fpcn | nawk '/^p/ { pid=substr($0,2) } /^c/ { cmd=substr($0,2) } /^n/ { fd[cmd"["pid"]"]++ } END { for (cc in fd) printf("%-30s %i\n",cc,fd[cc]) } ' | sort -n -k 2 | tail -30

    # copy file with rsync over SSH
    rsync -avz -e "ssh -i <ssh_key_path> -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" --progress <file> <username>@<remote_ip>:<remote_dir>
  20. flc revised this gist May 12, 2016. 1 changed file with 7 additions and 1 deletion.
    8 changes: 7 additions & 1 deletion commands.txt
    Original file line number Diff line number Diff line change
    @@ -115,4 +115,10 @@ openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
    grep -inIEr --color=ALWAYS "<pattern_to_search>" .

    # copy directory tree recursively without overwrite
    rsync -a -v --ignore-existing <src_dir> <dst_dir>
    rsync -a -v --ignore-existing <src_dir> <dst_dir>

    # find processes with most memory usage
    ps -e -orss,%mem,cputime,%cpu,pid,args | sort -b -k1,1n | pr -TW$COLUMNS

    # find processes with maximum file descriptors
    lsof -Fpcn | nawk '/^p/ { pid=substr($0,2) } /^c/ { cmd=substr($0,2) } /^n/ { fd[cmd"["pid"]"]++ } END { for (cc in fd) printf("%-30s %i\n",cc,fd[cc]) } ' | sort -n -k 2 | tail -30
  21. flc revised this gist Dec 31, 2015. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion commands.txt
    Original file line number Diff line number Diff line change
    @@ -112,4 +112,7 @@ openssl aes-256-cbc -d -in <encrypted_file> -out <file> -k <passphrase>
    openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048

    # search for pattern in codebase
    grep -inIEr --color=ALWAYS "<pattern_to_search>" .
    grep -inIEr --color=ALWAYS "<pattern_to_search>" .

    # copy directory tree recursively without overwrite
    rsync -a -v --ignore-existing <src_dir> <dst_dir>
  22. flc revised this gist Nov 11, 2015. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion commands.txt
    Original file line number Diff line number Diff line change
    @@ -109,4 +109,7 @@ openssl aes-256-cbc -salt -in <file> -out <encrypted_file> -k <passphrase>
    openssl aes-256-cbc -d -in <encrypted_file> -out <file> -k <passphrase>

    # generate your dhparam.pem file
    openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
    openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048

    # search for pattern in codebase
    grep -inIEr --color=ALWAYS "<pattern_to_search>" .
  23. flc revised this gist Oct 12, 2015. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions commands.txt
    Original file line number Diff line number Diff line change
    @@ -107,3 +107,6 @@ sudo poweroff
    # encrypt/decrypt file with openssl
    openssl aes-256-cbc -salt -in <file> -out <encrypted_file> -k <passphrase>
    openssl aes-256-cbc -d -in <encrypted_file> -out <file> -k <passphrase>

    # generate your dhparam.pem file
    openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
  24. flc revised this gist Oct 2, 2015. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion commands.txt
    Original file line number Diff line number Diff line change
    @@ -102,4 +102,8 @@ sudo chage -d 0 <username>

    # server shutdown
    sudo shutdown -h now
    sudo poweroff
    sudo poweroff

    # encrypt/decrypt file with openssl
    openssl aes-256-cbc -salt -in <file> -out <encrypted_file> -k <passphrase>
    openssl aes-256-cbc -d -in <encrypted_file> -out <file> -k <passphrase>
  25. flc revised this gist May 18, 2015. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion commands.txt
    Original file line number Diff line number Diff line change
    @@ -98,4 +98,8 @@ ssh -o "Compression=no" mydbserver "pg_dump -Fc -Z9 -U postgres mydb" > mydb.dum
    < /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-32};echo;

    # force the user to change their password upon next login
    sudo chage -d 0 <username>
    sudo chage -d 0 <username>

    # server shutdown
    sudo shutdown -h now
    sudo poweroff
  26. flc revised this gist Jan 13, 2015. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions commands.txt
    Original file line number Diff line number Diff line change
    @@ -96,3 +96,6 @@ ssh -o "Compression=no" mydbserver "pg_dump -Fc -Z9 -U postgres mydb" > mydb.dum
    # of course there are tons of ways to do this
    # you can replace 32 with the desired password length
    < /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-32};echo;

    # force the user to change their password upon next login
    sudo chage -d 0 <username>
  27. flc revised this gist Dec 18, 2014. 1 changed file with 6 additions and 1 deletion.
    7 changes: 6 additions & 1 deletion commands.txt
    Original file line number Diff line number Diff line change
    @@ -90,4 +90,9 @@ sudo renice -n <niceness> -g <pid>
    tail -n +2 file.csv | awk -F "," '$2 >= <my threshold value>' | wc -l

    # pg_dump ssh tunnel
    ssh -o "Compression=no" mydbserver "pg_dump -Fc -Z9 -U postgres mydb" > mydb.dump
    ssh -o "Compression=no" mydbserver "pg_dump -Fc -Z9 -U postgres mydb" > mydb.dump

    # generate random password
    # of course there are tons of ways to do this
    # you can replace 32 with the desired password length
    < /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-32};echo;
  28. flc revised this gist Dec 16, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion commands.txt
    Original file line number Diff line number Diff line change
    @@ -55,7 +55,7 @@ sudo groupadd <groupname>
    # add existing user to group
    sudo usermod -a -G <groupname> <username>

    # ass a user to multiple groups
    # add a user to multiple groups
    sudo usermod -a -G <groupname1>,<groupname2>,<groupname3> <username>

    # view user's group assignemnts
  29. flc revised this gist Dec 16, 2014. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions commands.txt
    Original file line number Diff line number Diff line change
    @@ -62,6 +62,14 @@ sudo usermod -a -G <groupname1>,<groupname2>,<groupname3> <username>
    id <username>
    groups <username>

    # make a directory accessible for a group
    # change group of all files/directories recursively
    sudo chgrp -R <groupname> <directory>
    # add write permissions to group
    sudo chmod -R g+w <directory>
    # set "GID", so that all new files and directories created under <directory> are owned by the group
    sudo find <directory> -type d -exec chmod 2775 {} \;

    # randomize lines of a big file memory efficiently
    uuid -v 4 -n $(wc -l < lines.txt) | paste - lines.txt | sort | cut -f2 > lines_random.txt

  30. flc revised this gist Dec 16, 2014. 1 changed file with 14 additions and 1 deletion.
    15 changes: 14 additions & 1 deletion commands.txt
    Original file line number Diff line number Diff line change
    @@ -47,7 +47,20 @@ tar tvf archive.tar.gz
    tar jxf filename.tar.bz2

    # add user
    sudo adduser username
    sudo adduser <username>

    # add group
    sudo groupadd <groupname>

    # add existing user to group
    sudo usermod -a -G <groupname> <username>

    # ass a user to multiple groups
    sudo usermod -a -G <groupname1>,<groupname2>,<groupname3> <username>

    # view user's group assignemnts
    id <username>
    groups <username>

    # randomize lines of a big file memory efficiently
    uuid -v 4 -n $(wc -l < lines.txt) | paste - lines.txt | sort | cut -f2 > lines_random.txt