[Linux] How to Compress Folder and Decompress File

1. Compress a folder To compress a folder in Linux, you can use the tar command. The tar command is used to create, manage, and extract files that are archived in the tar format. To compress a folder, you can use the -czvf flags, which tell tar to create a compressed archive, use gzip compression, be verbose, and use the file name that follows. First, navigate to the directory containing the folder you want to compress. Then, run the following command: ...

[Linux] How to Download Files and Folders from Remote Server

To use scp to download a file from a remote server to your local machine, you can use the following syntax: scp username@host:/path/to/remote/file /path/to/local/destination This will download the file located at /path/to/remote/file on the remote server, and save it to /path/to/local/destination on your local machine. You will need to replace username with your username on the remote server, host with the hostname or IP address of the remote server, and /path/to/remote/file and /path/to/local/destination with the actual paths to the remote file and the local destination, respectively. ...

Docker Handbook (🚧Continuous Update)

1. Install docker and docker-compose on Ubuntu sudo apt-get update sudo apt install docker.io sudo apt install docker-compose 2. Configure rootless user to run docker sudo groupadd docker sudo usermod -aG docker $USER # Linux user can run below to activate the changes newgrp docker docker ps https://docs.docker.com/engine/install/linux-postinstall/ 3. List and delete images docker images docker iamge ls docker rmi <image_id_1> <image_id_2> 4. Check if the specific docker image exists IMAGE_ID=$(docker images | grep 'portainer/base' | awk '{ print $3 }') if [[ -n ${IMAGE_ID} ]]; then docker rm -f ${IMAGE_ID}; fi 5. Login remote registry # Default is dockerhub. username is docker hub id docker login # Login the specific registry docker login registry.private.com 6. Build image from Dockerfile docker build -t <user>/<repo>:<tag> -f Dockerfile . 7. Push the local image to remote registry docker image push <user>/<repo>:<tag> # Push to the private registry docker push registry.private.com/<repo>:<tag> 8. Add and view the docker volume # add volume docker volume create <volume_name> # view volume docker volume ls sudo ls /var/lib/docker/volumes 9. Check the volume detail docker volume inspect <volume_name> 10. Test docker container service connection with curl ping the http service ...

Linux Handbook (🚧Continuous Update)

1. Set up permanent alias alais boltbrowser="bb" source .bashrc 2. Mount the external drive permanently See other posts: How to mount the external hard drive permanently External hard drive is read-only 3. Check which process owns the specific port sudo netstat -tulpn sudo netstat -tulpn | grep 80 # or sudo ss -tulpn sudo ss -tulpn | grep 80 # or sudo ps aux sudo ps aux | grep 80 4. Open an url in web browser from Terminal xdg-open https://google.com 5. Delete the installed package with apt # Check the apt installed history gtrep " install " /var/log/apt/history.log # Only remove the package but keep the configuration sudo apt remove <package_name> # Remove both package and configuration sudo apt purge <package_name> 6. List all the block devices lsblk -f Output is like ...

Bash Handbook (🚧Continuous Update)

1. Check if a file path represented by environment variable exists [[ "$(cat ${ENV_VARIABLE})" ]] || printf "env is not exported." 2. Get the file name from the full path echo "$basename -a /home/foo/abc.txt" # Output abc.txt 3. Extract the specific cell value from a table output For example, the output of the command nomad node status -address=https://127.0.0.1:4646 ID DC Name Class Drain Eligibility Status d88b0888 dc1 oscarzhou-B550-AORUS-ELITE-AX-V2 <none> false eligible ready If we want to get value of the datacenter dc1 where is [2,2] in the array. The solution is ...

Git Handbook (🚧Continuous Update)

1. Discard the changes git checkout -- . 2. Create a new branch git checkout -b <branch_name> # or git branch <branch_name> 3. Cache the password git config --global credential.helper store git config --global credential.helper cache 4. Stash the current changes git stash 5. Recovery/Apply the stash to the current branch git stash list git stash apply stash@{stash_index} # Most often we recover the stash@{0}, so we also can use below git stash apply 6. Configure username and email locally Sometime we need to configure a different username and email for the specific repository ...

Helm Handbook (🚧Continuous Update)

Helm is the package manager for Kubernetes. We can download it from here Take the public repository portainer/k8s as an example 1. Render the helm chart locally Open the terminal under the path github.com/portainer/k8s/charts helm template portainer/ # Render the chart with configurable argument helm template portainer/ --set image.tag="2.6.0" helm template portainer/ --set enterpriseEdition.enabled=true --set enterpriseEdition.image.tag="2.7.0" 2. Install helm chart helm install --create-namespace -n portainer portainer portainer/portainer 3. Install helm chart with local repository helm install --create-namespace -n portainer portainer-local portainer/ \ --values portainer/values.yaml # with argument helm install --set image.tag="2.6.0" --create-namespace \ -n portainer portainer-2-6 portainer/ \ --values portainer/values.yaml 4. helm chart repo # Add repo helm repo add <repo_name> https://portainer.github.io/k8s/ helm repo update # Remove repo helm repo remove <repo_name> 5. Delete helm namespace helm delete -n portainer portainer 6. List helm namespace helm ls --all-namespaces

Minikube Handbook (🚧Continuous Update)

Where to start? https://minikube.sigs.k8s.io/docs/start/ 1. Create kubernetes cluster # Specify the kubernetes version minikube start --kubernetes-version=v1.22.3 # Create second cluster minikube start -p minikube2 --kubernetes-version=v1.22.3 2. Create nginx ingress service kubectl create deployment ingress-nginx --image=k8s.gcr.io/ingress-nginx/controller kubectl expose deployment ingress-nginx --type=LoadBalancer --port=30777 3. General commands kubectl get pods -n portainer kubectl get svc -n portainer kubectl get events -n portainer kubectl logs -n portainer portainer-local-7c9f9d6897-jn97c kubectl get deployment -n portainer -o wide kubectl get --namespace portainer svc -w portainer kubectl port-forward -n portainer service/portainer 7080:9000 kubectl get --namespace portainer -o jsonpath="{.spec.ports[1].nodePort}" services portainer kubectl get nodes --namespace portainer -o jsonpath="{.items[0].status.addresses[0].address}" 4. Install and uninstall minkube cluster sudo dpkg -i minikube_latest_amd64.deb sudo dpkg --purge minikube

Windows Handbook (🚧Continuous Update)

1. Find the running process with <PORT> netstat -ano | findstr :<PORT> 2. Delete the running process with <PID> taskkill /PID <PID> /F 3. Find the running Named Pipe Open the powershell with the administrator permission and execute get-childitem \\.\pipe\ | grep "me.clic.ipc.v1"

PostgreSQL Handbook (🚧Continuous Update)

1. Init a database sudo su postgres psql create database osmapi create user osmapi \password osmapi grant all privileges on database "osmapi" to osmapi \c osmapi create extension "uuid-ossp" create extension cube create extension earthdistance 2. Duplicate a table create table dupe_users as (select * from users); create table dupe_users as (select * from users) with no data; 3. Change the owner of a table and view ALTER TABLE public.tablename OWNER TO my_user; ALTER VIEW latest_status_logs OWNER TO my_user; 4. Drop a column ALTER TABLE tablename DROP COLUMN category_id; 5. Install “uuid-ossp” apt-get install postgresql-contrib-9.3 6. Check index SELECT * FROM pg_indexes WHERE TABLENAME NOT LIKE 'pg%' DROP INDEX xxx alter table activity_auditings drop constraint activity_auditings_extra_curriculum_no_key 7. Connect to the remote database by CLI psql -d mydb -U myuser psql -h myhost -d mydb -U myuser psql --host=dataant-test.cpkuy5lqfq7v.ap-southeast-2.rds.amazonaws.com \ --port=5432 \ --username=dataanttest \ --password \ --dbname=dataantapi 8. Change a column name ALTER TABLE client_profiles RENAME COLUMN user_id TO profile_id 9. Install Postgres sudo apt-get update sudo apt-get install postgresql postgresql-contrib 10. Set the access permission of other machines /etc/postgresql/9.1/main/pg_hba.conf # ipv4 host all all 0.0.0.0/0 md5 (e.g. 192.168.0.0/16) host all all 192.168.239.133/16 md5 /etc/postgresql/9.1/main/postgresql.conf listen_address='*' Restart database ...

DigitalOcean Referral Badge
Sign up to get $200, 60-day account credit !