manual, sysadmins, computer basics

This commit is contained in:
Mik-TF 2024-05-14 13:02:02 -04:00
parent c54a6ab037
commit 8f74e1e9bf
3 changed files with 98 additions and 92 deletions

View File

@ -70,16 +70,16 @@ sudo sh get-docker.sh
To completely remove docker from your machine, you can follow these steps: To completely remove docker from your machine, you can follow these steps:
* List the docker packages * List the docker packages
* ``` ```
dpkg -l | grep -i docker dpkg -l | grep -i docker
``` ```
* Purge and autoremove docker * Purge and autoremove docker
* ``` ```
apt-get purge -y docker-engine docker docker.io docker-ce docker-ce-cli docker-compose-plugin apt-get purge -y docker-engine docker docker.io docker-ce docker-ce-cli docker-compose-plugin
apt-get autoremove -y --purge docker-engine docker docker.io docker-ce docker-compose-plugin apt-get autoremove -y --purge docker-engine docker docker.io docker-ce docker-compose-plugin
``` ```
* Remove the docker files and folders * Remove the docker files and folders
* ``` ```
rm -rf /var/lib/docker /etc/docker rm -rf /var/lib/docker /etc/docker
rm /etc/apparmor.d/docker rm /etc/apparmor.d/docker
groupdel docker groupdel docker
@ -93,11 +93,11 @@ You can also use the command **whereis docker** to see if any Docker folders and
### List containers ### List containers
* List only running containers * List only running containers
* ``` ```
docker ps docker ps
``` ```
* List all containers (running + stopped) * List all containers (running + stopped)
* ``` ```
docker ps -a docker ps -a
``` ```
@ -108,15 +108,15 @@ You can also use the command **whereis docker** to see if any Docker folders and
To pull an image from [Docker Hub](https://hub.docker.com/): To pull an image from [Docker Hub](https://hub.docker.com/):
* Pull an image * Pull an image
* ``` ```
docker pull <image_name> docker pull <image_name>
``` ```
* Pull an image with the tag * Pull an image with the tag
* ``` ```
docker pull <image_name>:tag docker pull <image_name>:tag
``` ```
* Pull all tags of an image * Pull all tags of an image
* ``` ```
docker pull <image_name> -a docker pull <image_name> -a
``` ```
@ -127,15 +127,15 @@ To pull an image from [Docker Hub](https://hub.docker.com/):
To pull an image to [Docker Hub](https://hub.docker.com/): To pull an image to [Docker Hub](https://hub.docker.com/):
* Push an image * Push an image
* ``` ```
docker push <image_name> docker push <image_name>
``` ```
* Push an image with the tag * Push an image with the tag
* ``` ```
docker push <image_name>:tag docker push <image_name>:tag
``` ```
* Push all tags of an image * Push all tags of an image
* ``` ```
docker pull <image_name> -a docker pull <image_name> -a
``` ```
@ -144,11 +144,11 @@ To pull an image to [Docker Hub](https://hub.docker.com/):
### Inspect and pull an image with GHCR ### Inspect and pull an image with GHCR
* Inspect the docker image * Inspect the docker image
* ``` ```
docker inspect ghcr.io/<repository>/<image>:<tag> docker inspect ghcr.io/<repository>/<image>:<tag>
``` ```
* Pull the docker image * Pull the docker image
* ``` ```
docker pull ghcr.io/<repository>/<image>:<tag> docker pull ghcr.io/<repository>/<image>:<tag>
``` ```
@ -174,20 +174,20 @@ To install Skopeo, read [this documentation](install.md).
Use **docker build** to build a container based on a Dockerfile Use **docker build** to build a container based on a Dockerfile
* Build a container based on current directory Dockerfile * Build a container based on current directory Dockerfile
* ``` ```
docker build . docker build .
``` ```
* Build a container and store the image with a given name * Build a container and store the image with a given name
* Template * Template
* ``` ```
docker build -t "<image_name>:<tag>" docker build -t "<image_name>:<tag>"
``` ```
* Example * Example
* ``` ```
docker build -t newimage:latest docker build -t newimage:latest
``` ```
* Build a docker container without using the cache * Build a docker container without using the cache
* ``` ```
docker build --no-cache docker build --no-cache
``` ```
@ -206,15 +206,15 @@ docker images
To run a container based on an image, use the command **docker run**. To run a container based on an image, use the command **docker run**.
* Run an image * Run an image
* ``` ```
docker run <image_name> docker run <image_name>
``` ```
* Run an image in the background (run and detach) * Run an image in the background (run and detach)
* ``` ```
docker run -d <image_name> docker run -d <image_name>
``` ```
* Run an image with CLI input * Run an image with CLI input
* ``` ```
docker run -it <image_name> docker run -it <image_name>
``` ```
@ -229,7 +229,7 @@ You can also specify the shell, e.g. **docker run -it <image_name> /bin/bash**
To run a new command in an existing container, use **docker exec**. To run a new command in an existing container, use **docker exec**.
* Execute interactive shell on the container * Execute interactive shell on the container
* ``` ```
docker exec -it <container_name> sh docker exec -it <container_name> sh
``` ```
@ -238,11 +238,11 @@ To run a new command in an existing container, use **docker exec**.
### Bash shell into container ### Bash shell into container
* Bash shell into a container * Bash shell into a container
* ``` ```
docker exec -i -t /bin/bash docker exec -i -t /bin/bash
``` ```
* Bash shell into a container with root * Bash shell into a container with root
* ``` ```
docker exec -i -t -u root /bin/bash docker exec -i -t -u root /bin/bash
``` ```
@ -300,22 +300,22 @@ docker cp <container_id>:<file_path> <file_path_destination>
### Delete all the containers, images and volumes ### Delete all the containers, images and volumes
* To delete all containers: * To delete all containers:
* ``` ```
docker compose rm -f -s -v docker compose rm -f -s -v
``` ```
* To delete all images: * To delete all images:
* ``` ```
docker rmi -f $(docker images -aq) docker rmi -f $(docker images -aq)
``` ```
* To delete all volumes: * To delete all volumes:
* ``` ```
docker volume rm $(docker volume ls -qf dangling=true) docker volume rm $(docker volume ls -qf dangling=true)
``` ```
* To delete all containers, images and volumes: * To delete all containers, images and volumes:
* ``` ```
docker compose rm -f -s -v && docker rmi -f $(docker images -aq) && docker volume rm $(docker volume ls -qf dangling=true) docker compose rm -f -s -v && docker rmi -f $(docker images -aq) && docker volume rm $(docker volume ls -qf dangling=true)
``` ```
@ -324,7 +324,7 @@ docker cp <container_id>:<file_path> <file_path_destination>
### Kill all the Docker processes ### Kill all the Docker processes
* To kill all processes: * To kill all processes:
* ``` ```
killall Docker && open /Applications/Docker.app killall Docker && open /Applications/Docker.app
``` ```
@ -353,11 +353,11 @@ docker ps -s
### Examine disks usage ### Examine disks usage
* Basic mode * Basic mode
* ``` ```
docker system df docker system df
``` ```
* Verbose mode * Verbose mode
* ``` ```
docker system df -v docker system df -v
``` ```

View File

@ -33,14 +33,14 @@ Deploying on the TFGrid with tools such as the Playground and Terraform is easy
### File transfer with IPv4 ### File transfer with IPv4
* From local to remote, write the following on the local terminal: * From local to remote, write the following on the local terminal:
* ``` ```
scp <path_to_local_file>/<filename> <remote_username>@<remote_IPv4_address>:/<remote_username>/<path_to_remote_file>/<filename> scp <path_to_local_file>/<filename> <remote_username>@<remote_IPv4_address>:/<remote_username>/<path_to_remote_file>/<filename>
``` ```
* From remote to local, you can write the following on the local terminal (more secure): * From remote to local, you can write the following on the local terminal (more secure):
* ``` ```
scp <remote_username>@<remote_IPv4_address>:/<remote_username>/<path_to_remote_file>/<filename> <path_to_local_file>/<file> scp <remote_username>@<remote_IPv4_address>:/<remote_username>/<path_to_remote_file>/<filename> <path_to_local_file>/<file>
* From remote to local, you can also write the following on the remote terminal: * From remote to local, you can also write the following on the remote terminal:
* ``` ```
scp <path_to_remote_file>/<file> <local_user>@<local_IPv4_address>:/<local_username>/<path_to_local_file>/<filename> scp <path_to_remote_file>/<file> <local_user>@<local_IPv4_address>:/<local_username>/<path_to_local_file>/<filename>
### File transfer with IPv6 ### File transfer with IPv6
@ -56,11 +56,11 @@ For IPv6, it is similar to IPv4 but you need to add `-6` after scp and add `\[`
We show here how to transfer files between two computers. Note that at least one of the two computers must be local. This will transfer the content of the source directory into the destination directory. We show here how to transfer files between two computers. Note that at least one of the two computers must be local. This will transfer the content of the source directory into the destination directory.
* From local to remote * From local to remote
* ``` ```
rsync -avz --progress --delete /path/to/local/directory/ remote_user@<remote_host_or_ip>:/path/to/remote/directory rsync -avz --progress --delete /path/to/local/directory/ remote_user@<remote_host_or_ip>:/path/to/remote/directory
``` ```
* From remote to local * From remote to local
* ``` ```
rsync -avz --progress --delete remote_user@<remote_host_or_ip>:/path/to/remote/directory/ /path/to/local/directory rsync -avz --progress --delete remote_user@<remote_host_or_ip>:/path/to/remote/directory/ /path/to/local/directory
``` ```
@ -77,16 +77,16 @@ Here is short description of the parameters used:
[rsync-sidekick](https://github.com/m-manu/rsync-sidekick) propagates changes from source directory to destination directory. You can run rsync-sidekick before running rsync. Make sure that [Go is installed](#install-go). [rsync-sidekick](https://github.com/m-manu/rsync-sidekick) propagates changes from source directory to destination directory. You can run rsync-sidekick before running rsync. Make sure that [Go is installed](#install-go).
* Install rsync-sidekick * Install rsync-sidekick
* ``` ```
sudo go install github.com/m-manu/rsync-sidekick@latest sudo go install github.com/m-manu/rsync-sidekick@latest
``` ```
* Reorganize the files and folders with rsync-sidekick * Reorganize the files and folders with rsync-sidekick
* ``` ```
rsync-sidekick /path/to/local/directory/ username@IP_Address:/path/to/remote/directory rsync-sidekick /path/to/local/directory/ username@IP_Address:/path/to/remote/directory
``` ```
* Transfer and update files and folders with rsync * Transfer and update files and folders with rsync
* ``` ```
sudo rsync -avz --progress --delete --log-file=/path/to/local/directory/rsync_storage.log /path/to/local/directory/ username@IP_Address:/path/to/remote/directory sudo rsync -avz --progress --delete --log-file=/path/to/local/directory/rsync_storage.log /path/to/local/directory/ username@IP_Address:/path/to/remote/directory
``` ```
@ -95,18 +95,18 @@ Here is short description of the parameters used:
We show how to automate file transfers between two computers using rsync. We show how to automate file transfers between two computers using rsync.
* Create the script file * Create the script file
* ``` ```
nano rsync_backup.sh nano rsync_backup.sh
``` ```
* Write the following script with the proper paths. Here the log is saved in the same directory. * Write the following script with the proper paths. Here the log is saved in the same directory.
* ``` ```
# filename: rsync_backup.sh # filename: rsync_backup.sh
#!/bin/bash #!/bin/bash
sudo rsync -avz --progress --delete --log-file=/path/to/local/directory/rsync_storage.log /path/to/local/directory/ username@IP_Address:/path/to/remote/directory sudo rsync -avz --progress --delete --log-file=/path/to/local/directory/rsync_storage.log /path/to/local/directory/ username@IP_Address:/path/to/remote/directory
``` ```
* Give permission * Give permission
* ``` ```
sudo chmod +x /path/to/script/rsync_backup.sh sudo chmod +x /path/to/script/rsync_backup.sh
``` ```
* Set a cron job to run the script periodically * Set a cron job to run the script periodically
@ -115,11 +115,11 @@ We show how to automate file transfers between two computers using rsync.
sudo cp path/to/script/rsync_backup.sh /root sudo cp path/to/script/rsync_backup.sh /root
``` ```
* Open the cron file * Open the cron file
* ``` ```
sudo crontab -e sudo crontab -e
``` ```
* Add the following to run the script everyday. For this example, we set the time at 18:00PM * Add the following to run the script everyday. For this example, we set the time at 18:00PM
* ``` ```
0 18 * * * /root/rsync_backup.sh 0 18 * * * /root/rsync_backup.sh
``` ```
@ -128,11 +128,11 @@ We show how to automate file transfers between two computers using rsync.
Depending on your situation, the parameters **--checksum** or **--ignore-times** can be quite useful. Note that adding either parameter will slow the transfer. Depending on your situation, the parameters **--checksum** or **--ignore-times** can be quite useful. Note that adding either parameter will slow the transfer.
* With **--ignore time**, you ignore both the time and size of each file. This means that you transfer all files from source to destination. * With **--ignore time**, you ignore both the time and size of each file. This means that you transfer all files from source to destination.
* ``` ```
rsync --ignore-time source_folder/ destination_folder rsync --ignore-time source_folder/ destination_folder
``` ```
* With **--checksum**, you verify with a checksum that the files from source and destination are the same. This means that you transfer all files that have a different checksum compared source to destination. * With **--checksum**, you verify with a checksum that the files from source and destination are the same. This means that you transfer all files that have a different checksum compared source to destination.
* ``` ```
rsync --checksum source_folder/ destination_folder rsync --checksum source_folder/ destination_folder
``` ```
@ -141,11 +141,11 @@ Depending on your situation, the parameters **--checksum** or **--ignore-times**
rsync does not act the same whether you use or not a slash ("\/") at the end of the source path. rsync does not act the same whether you use or not a slash ("\/") at the end of the source path.
* Copy content of **source_folder** into **destination_folder** to obtain the result: **destination_folder/source_folder_content** * Copy content of **source_folder** into **destination_folder** to obtain the result: **destination_folder/source_folder_content**
* ``` ```
rsync source_folder/ destination_folder rsync source_folder/ destination_folder
``` ```
* Copy **source_folder** into **destination_folder** to obtain the result: **destination_folder/source_folder/source_folder_content** * Copy **source_folder** into **destination_folder** to obtain the result: **destination_folder/source_folder/source_folder_content**
* ``` ```
rsync source_folder destination_folder rsync source_folder destination_folder
``` ```

View File

@ -16,6 +16,12 @@
- [Go to another branch](#go-to-another-branch) - [Go to another branch](#go-to-another-branch)
- [Add your changes to a local branch](#add-your-changes-to-a-local-branch) - [Add your changes to a local branch](#add-your-changes-to-a-local-branch)
- [Push changes of a local branch to the remote Github branch](#push-changes-of-a-local-branch-to-the-remote-github-branch) - [Push changes of a local branch to the remote Github branch](#push-changes-of-a-local-branch-to-the-remote-github-branch)
- [Count the differences between two branches](#count-the-differences-between-two-branches)
- [See the default branch](#see-the-default-branch)
- [Force a push](#force-a-push)
- [Merge a branch to a different branch](#merge-a-branch-to-a-different-branch)
- [Clone completely one branch to another branch locally then push the changes to Github](#clone-completely-one-branch-to-another-branch-locally-then-push-the-changes-to-github)
- [The 3 levels of the command reset](#the-3-levels-of-the-command-reset)
- [Reverse modifications to a file where changes haven't been staged yet](#reverse-modifications-to-a-file-where-changes-havent-been-staged-yet) - [Reverse modifications to a file where changes haven't been staged yet](#reverse-modifications-to-a-file-where-changes-havent-been-staged-yet)
- [Download binaries from Github](#download-binaries-from-github) - [Download binaries from Github](#download-binaries-from-github)
- [Resolve conflicts between branches](#resolve-conflicts-between-branches) - [Resolve conflicts between branches](#resolve-conflicts-between-branches)
@ -50,11 +56,11 @@ You can install git on MAC, Windows and Linux. You can consult Git's documentati
### Install on Linux ### Install on Linux
* Fedora distribution * Fedora distribution
* ``` ```
dnf install git-all dnf install git-all
``` ```
* Debian-based distribution * Debian-based distribution
* ``` ```
apt install git-all apt install git-all
``` ```
* Click [here](https://git-scm.com/download/linux) for other Linux distributions * Click [here](https://git-scm.com/download/linux) for other Linux distributions
@ -62,7 +68,7 @@ You can install git on MAC, Windows and Linux. You can consult Git's documentati
### Install on MAC ### Install on MAC
* With Homebrew * With Homebrew
* ``` ```
brew install git brew install git
``` ```
@ -125,11 +131,11 @@ git checkout <branch_name>
### Add your changes to a local branch ### Add your changes to a local branch
* Add all changes * Add all changes
* ``` ```
git add . git add .
``` ```
* Add changes of a specific file * Add changes of a specific file
* ``` ```
git add <path_to_file>/<file_name> git add <path_to_file>/<file_name>
``` ```
@ -139,13 +145,13 @@ git checkout <branch_name>
To push changes to Github, you can use the following commands: To push changes to Github, you can use the following commands:
* ``` ```
git add . git add .
``` ```
* ``` ```
git commit -m "write your changes here in comment" git commit -m "write your changes here in comment"
``` ```
* ``` ```
git push git push
``` ```
@ -178,15 +184,15 @@ git push --force
### Merge a branch to a different branch ### Merge a branch to a different branch
* Checkout the branch you want to copy content TO * Checkout the branch you want to copy content TO
* ``` ```
git checkout branch_name git checkout branch_name
``` ```
* Merge the branch you want content FROM * Merge the branch you want content FROM
* ``` ```
git merge origin/dev_mermaid git merge origin/dev_mermaid
``` ```
* Push the changes * Push the changes
* ``` ```
git push -u origin/head git push -u origin/head
``` ```
@ -197,19 +203,19 @@ git push --force
For this example, we copy **branchB** into **branchA**. For this example, we copy **branchB** into **branchA**.
* See available branches * See available branches
* ``` ```
git branch -r git branch -r
``` ```
* Go to **branchA** * Go to **branchA**
* ``` ```
git checkout branchA git checkout branchA
``` ```
* Copy **branchB** into **branchA** * Copy **branchB** into **branchA**
* ``` ```
git git reset --hard branchB git git reset --hard branchB
``` ```
* Force the push * Force the push
* ``` ```
git push --force git push --force
``` ```
@ -217,17 +223,17 @@ For this example, we copy **branchB** into **branchA**.
### The 3 levels of the command reset ### The 3 levels of the command reset
* ``` ```
git reset --soft git reset --soft
``` ```
* Bring the History to the Stage/Index * Bring the History to the Stage/Index
* Discard last commit * Discard last commit
* ``` ```
git reset --mixed git reset --mixed
``` ```
* Bring the History to the Working Directory * Bring the History to the Working Directory
* Discard last commit and add * Discard last commit and add
* ``` ```
git reset --hard git reset --hard
``` ```
* Bring the History to the Working Directory * Bring the History to the Working Directory
@ -252,7 +258,7 @@ git checkout <filename>
### Download binaries from Github ### Download binaries from Github
* Template: * Template:
* ``` ```
wget -O <file_name> https://raw.githubusercontent.com/<user_name>/<repository>/<path_to_file>/<file_name> wget -O <file_name> https://raw.githubusercontent.com/<user_name>/<repository>/<path_to_file>/<file_name>
``` ```
@ -263,29 +269,29 @@ git checkout <filename>
We show how to resolve conflicts in a development branch (e.g. **branch_dev**) and then merging the development branch into the main branch (e.g. **branch_main**). We show how to resolve conflicts in a development branch (e.g. **branch_dev**) and then merging the development branch into the main branch (e.g. **branch_main**).
* Clone the repo * Clone the repo
* ``` ```
git clone <repo_url> git clone <repo_url>
``` ```
* Pull changes and potential conflicts * Pull changes and potential conflicts
* ``` ```
git pull origin branch_main git pull origin branch_main
``` ```
* Checkout the development branch * Checkout the development branch
* ``` ```
git checkout branch_dev git checkout branch_dev
``` ```
* Resolve conflicts in a text editor * Resolve conflicts in a text editor
* Save changes in the files * Save changes in the files
* Add the changes * Add the changes
* ``` ```
git add . git add .
``` ```
* Commit the changes * Commit the changes
* ``` ```
git commit -m "your message here" git commit -m "your message here"
``` ```
* Push the changes * Push the changes
* ``` ```
git push git push
``` ```
@ -294,11 +300,11 @@ We show how to resolve conflicts in a development branch (e.g. **branch_dev**) a
### Download all repositories of an organization ### Download all repositories of an organization
* Log in to gh * Log in to gh
* ``` ```
gh auth login gh auth login
``` ```
* Clone all repositories. Replace <organization> with the organization in question. * Clone all repositories. Replace <organization> with the organization in question.
* ``` ```
gh repo list <organization> --limit 1000 | while read -r repo _; do gh repo list <organization> --limit 1000 | while read -r repo _; do
gh repo clone "$repo" "$repo" gh repo clone "$repo" "$repo"
done done
@ -309,15 +315,15 @@ We show how to resolve conflicts in a development branch (e.g. **branch_dev**) a
### Revert a push commited with git ### Revert a push commited with git
* Find the commit ID * Find the commit ID
* ``` ```
git log -p git log -p
``` ```
* Revert the commit * Revert the commit
* ``` ```
git revert <commit_ID> git revert <commit_ID>
``` ```
* Push the changes * Push the changes
* ``` ```
git push git push
``` ```
@ -334,11 +340,11 @@ git clone -b <branch_name> --single-branch /<path_to_repo>/<repo_name>.git
### Revert to a backup branch ### Revert to a backup branch
* Checkout the branch you want to update (**branch**) * Checkout the branch you want to update (**branch**)
* ``` ```
git checkout <branch> git checkout <branch>
``` ```
* Do a reset of your current branch based on the backup branch * Do a reset of your current branch based on the backup branch
* ``` ```
git reset --hard <backup_branch> git reset --hard <backup_branch>
``` ```
@ -363,19 +369,19 @@ Note that this will not work for untracked and new files. See below for untracke
This method can be used to overwrite local files. This will work even if you have untracked and new files. This method can be used to overwrite local files. This will work even if you have untracked and new files.
* Save local changes on a stash * Save local changes on a stash
* ``` ```
git stash --include-untracked git stash --include-untracked
``` ```
* Discard local changes * Discard local changes
* ``` ```
git reset --hard git reset --hard
``` ```
* Discard untracked and new files * Discard untracked and new files
* ``` ```
git clean -fd git clean -fd
``` ```
* Pull the remote branch * Pull the remote branch
* ``` ```
git pull git pull
``` ```
@ -388,27 +394,27 @@ Then, to delete the stash, you can use **git stash drop**.
The stash command is used to record the current state of the working directory. The stash command is used to record the current state of the working directory.
* Stash a branch (equivalent to **git stash push**) * Stash a branch (equivalent to **git stash push**)
* ``` ```
git stash git stash
``` ```
* List the changes in the stash * List the changes in the stash
* ``` ```
git stash list git stash list
``` ```
* Inspect the changes in the stash * Inspect the changes in the stash
* ``` ```
git stash show git stash show
``` ```
* Remove a single stashed state from the stash list and apply it on top of the current working tree state * Remove a single stashed state from the stash list and apply it on top of the current working tree state
* ``` ```
git stash pop git stash pop
``` ```
* Apply the stash on top of the current working tree state without removing the state from the stash list * Apply the stash on top of the current working tree state without removing the state from the stash list
* ``` ```
git stash apply git stash apply
``` ```
* Drop a stash * Drop a stash
* ``` ```
git stash drop git stash drop
``` ```
@ -431,15 +437,15 @@ To download VS-Code, visit their website and follow the given instructions.
There are many ways to install VS-Codium. Visit the [official website](https://vscodium.com/#install) for more information. There are many ways to install VS-Codium. Visit the [official website](https://vscodium.com/#install) for more information.
* Install on MAC * Install on MAC
* ``` ```
brew install --cask vscodium brew install --cask vscodium
``` ```
* Install on Linux * Install on Linux
* ``` ```
snap install codium --classic snap install codium --classic
``` ```
* Install on Windows * Install on Windows
* ``` ```
choco install vscodium choco install vscodium
``` ```