Last active
February 26, 2024 03:42
-
-
Save llluksa/8cd0cf94d4f6ec0fbde419044f62897f to your computer and use it in GitHub Desktop.
[Linux] Linux #sh #linux
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Kernel version of a Linux system | |
| uname -a | |
| # Check if lib is installed | |
| ldconfig -p | grep libgtk | |
| # Services | |
| service <service name> status (old school) | |
| systemctl status <service name> | |
| # disk free | |
| df -ah | |
| # dir total size | |
| du -sh /dir | |
| # size of directories with a dept | |
| du -h --max-dept=1 | |
| # CPU use | |
| ps aux | grep nginx | |
| top # more info | |
| htop # not by default but better graphics | |
| # Mount drive e.g. usb stick | |
| mount /dev/sda2 /mnt | |
| # check for existing mounts | |
| mount | |
| # automatically mount volume at boot: | |
| less /etc/fstab | |
| # Manual pages for commands | |
| man ps | |
| # Change host name | |
| sudo vi /etc/hostname | |
| sudo reboot | |
| # Create alias | |
| alias <aliasname>='<cmd>' | |
| # Curl | |
| # add header | |
| curl -H "Host:jupyterhub.luksa" 192.168.0.153:30010 -v |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # get pk: | |
| openssl pkcs12 -in abc.pfx -nocerts -out key.pem && openssl rsa -in key.pem -out key.pem | |
| # get fullchain: | |
| # openssl pkcs12 -in prod.pfx -nokeys -out cert.pem | |
| openssl pkcs12 -in abc.pfx -nokeys | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > cert.pem |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # (default azure pw is empty), extract key only: | |
| openssl pkcs12 -in abc.pfx -nocerts -out key.pem | |
| # (create a passphrase), extract certs only: | |
| openssl pkcs12 -in abc.pfx -nokeys -out cert.pem | |
| # remove passphrase from key and clean up the file: | |
| openssl rsa -in key.pem -out key.pem |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| cj.sh # add e.g. echo 'I run a cronjob!' >> /home/malu/cb-sh-log.txt | |
| crontab -l # add cron job e.g.: * * * * * /home/malu/cj.sh | |
| sudo service cron status | |
| sudo service cron start | |
| https://devhints.io/cron | |
| https://serverfault.com/questions/449651/why-is-my-crontab-not-working-and-how-can-i-troubleshoot-it |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # use sudo sh -c an EOF if permissions are an issue: | |
| # https://stackoverflow.com/questions/82256/how-do-i-use-sudo-to-redirect-output-to-a-location-i-dont-have-permission-to-wr | |
| sudo sh -c 'cat << EOF > /etc/telegraf/telegraf_new.conf | |
| something | |
| EOF | |
| ' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Export secret env var without having it in history: | |
| read -s -p "Enter password:" MROOTPASS | |
| export MROOTPASS | |
| # or disable history for anything that starts with whitespace | |
| export HISTCONTROL=ignorespace | |
| # now start a command with whitespace... it won't be in history :) | |
| export PW=abc |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Replace all literal \n with a new line: | |
| sed 's/\\n/\n/g' # cat myfile | sed 's/\\n/\n/g' > myfile | |
| # Delete all lines which start with #: | |
| sed '/^#/d' | |
| # add "#" to the beggening of each line | |
| sed 's/^/#/' file.txt | |
| sed s/^/'terraform state mv '/ refactor.sh > refactor2.sh | |
| # add "#" to the end of each line | |
| sed s/$/:80/ file.txt > another_file.txt | |
| sed s/$/' \&\& \\'/ refactor2.sh > refactor3.sh |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # set keys permissions | |
| chmod 600 ~/.ssh/id_rsa | |
| # SCP | |
| # download a file from server | |
| scp -i id_rsa_ansible_monit ansible@10.0.130.11:/etc/telegraf/telegraf.conf . | |
| # downlaod a directory: | |
| scp -i id_rsa_ansible_monit -r ansible@10.0.130.11:/etc/dir ./dir | |
| # SSH pub key copy | |
| # cat and pipe the result to the server | |
| cat id_rsa.pub | ssh ubuntu@192.168.0.153 'cat >> /home/ubuntu/.ssh/authorized_keys' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # start edit | |
| vim file.tf | |
| # quit | |
| :q | |
| # write | |
| :w | |
| # write and quite | |
| :wq | |
| # quit without changes | |
| :q! | |
| # jump to a line | |
| :set number (see line numbers) | |
| # start writing | |
| :i | |
| # delete a line | |
| dd | |
| # delete 10 lines | |
| 10dd | |
| # undo | |
| :u | |
| # redo | |
| ctrl r | |
| # looking for string 'provisioner' | |
| /provisioner | |
| # replace all 'privisioner' strings with 'foo' plus confirm with enters | |
| :%s/provisioner/foo/g |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment