Skip to content

Instantly share code, notes, and snippets.

@henriquelemos0
Last active January 4, 2020 19:11
Show Gist options
  • Save henriquelemos0/8c5f593be6192c3f409f7bf257741226 to your computer and use it in GitHub Desktop.
Save henriquelemos0/8c5f593be6192c3f409f7bf257741226 to your computer and use it in GitHub Desktop.

LinuxCommands

Crypt

Encrypt

openssl enc -in secretfile -aes-256-cbc -pass stdin > secretfile.enc

Decrypt

openssl enc -in secretfile.enc -d -aes-256-cbc -pass stdin > secretfile

Certificates

Decode PEM file

openssl x509 -in certificate.crt -text -noout 

Files

Rename

Add extension to all files

mmv "*" "#1.yml"

#@ Copy

Copy file from romote machine to local machine using key

scp -i ~/.ssh/mykey henrique@remotemachiine:/tmp/file.txt ~/Desktop/file.txt

Remove old files

find ./ -type f -mtime +4  | xargs rm

Compress

Compress to tgz

tar -czvf docker-volume-netshare_0.33_centos_amd64-bin.tgz ./docker-volume-netshare

Decompress from tgz

tar -zxvf <yourfile>.tar.gz -C /usr/src/ # no final o conteudo vai ficar /usr/src/<yourfile>
  • v verbose
  • f file
  • c create
  • x extract
  • z, --gzip, --gunzip, --ungzip filter the archive through gzip

Network

Ports listening and pid

sudo netstat -ntlp

MacOS listining ports

sudo lsof -iTCP -sTCP:LISTEN -n -P

Test communication between ports/hosts

sudo nc -luv 10.147.16.31 500
sudo nc -vnu 10.147.16.31 500

Print

for i in {1..49}; do
	value=$((50+$i))
	echo -ne "Movie ........ ${value}%"\\r
	sleep 1
done

Packages

YUM/RPM

Filter/list rpm packages

yum list docker-engine.x86_64  --showduplicates |sort -r

Show files from a installed rpm package

rpm -qil packagename-7.48.1-1

Show metadata of not installed rpm packages

rpm -qip ./packagename-7.48.2-1.noarch.rpm

APT/DEB

List packakage available versions on debian

sudo apt-cache policy docker-ce

List package content

apt-file list package_name

Install Package from file

sudo dpkg -i package.deb

List package content from file

dpkg -c package.deb

Ansible

Show env variables

ansible -i inventories/env1 blablebli.host.intranet -m setup -u username -k

Run on only one host

ansible-playbook -i  blablebli.host.intranet, file.yml --check

Run on a group of hosts

ansible-playbook -i inventories/env1 -l host1 deploy.yml --check

Copy file from remote host using only the command line

ansible all -i inventories/env1 -m fetch -a 'src=/etc/hosts dest=/home/user/Desktop/hosts/{{ inventory_hostname }}/ flat=yes'

File System

Format partition

sudo mkfs.ntfs -v -n "Files" /dev/sda1 

Mount partition (NTFS filesysstem type to home folder)

mkdir /home/henrique/Files
sudo chmod 755 /home/henrique/Files
sudo mount -t ntfs /dev/sda1 /home/henrique/Files 

Add mount to fstab

sudo vi /etc/fstab

#add:
/dev/sda1 /home/henrique/Files ntfs noauto,user,uid=henrique,gid=henrique 0 2

Increase disk space

Show free space

sudo vgs

IncreaseAum 512M on /opt

sudo lvextend -L+512M /dev/mapper/vg0-opt

Resize

sudo resize2fs /dev/mapper/vg0-opt

Copy ISO to pendrive

sudo dd bs=4M if=~/Desktop/bla.iso of=/dev/sdb status=progress && sync

Time

Adjust time using ntp server

sudo yum -y install ntpdate
sudo ntpdate 0 ntp1.ntp.sys.intranet 1 ntp2.ntp.sys.intranet

Slack

Send slack message

curl -X POST --data-urlencode 'payload={"text": "Test", "channel": "@username" }' https://hooks.slack.com/services/XXXXXX/YYYYYY/ZZZZZZZZZZ

Git

Remove local branches that no longer exist on remote repo

git branch -vv | grep gone] | awk '{print $1}' | xargs git branch -D

Apply last N (ex.: 5) commits from one branch to another branch

git format-patch -5
git checkout master
git checkout -b fix/patch
git am < *.patch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment