Skip to main content

CentOS commands

CentOS commands:

1) To view the list of packages installed

> yum list installed

2) To view the count of packages installed

> yum list installed | wc -l

3) To refresh package database and install updates if any

> yum update -y 

(-y is added so that you need not respond with y or yes when prompted)

4) To check if package is installed

> rpm -qa | grep <package-name>

e.g., rpm -qa | grep docker

5) To install docker

> yum install -y https://download.docker.com/linux/centos/8/x86_64/stable/Packages/containerd.io-1.4.3-3.1.el8.x86_64.rpm

> curl -fsSL https://get.docker.com/ | sh

> rpm -qa | grep docker

docker-ce-20.10.3-3.el8.x86_64
docker-ce-rootless-extras-20.10.3-3.el8.x86_64
docker-ce-cli-20.10.3-3.el8.x86_64

COURTESY: https://vexpose.blog/2020/04/02/installation-of-docker-fails-on-centos-8-with-error-package-containerd-io-1-2-10-3-2-el7-x86-64-is-excluded/

6) To start, stop and view status of docker

> systemctl start docker
> systemctl enable docker
> systemctl status docker

7) To list all containers

> docker container ls

8) To list both running and stopped containers

> docker ps -a

9) To list only stopped containers

> docker ps -a | grep Exit

10) To lists all images

> docker images -a OR docker image ls

11) To remove a container by container-id

> docker rm <first-few-chars-of-container-id>

12) Docker provides a single command that will clean up any resources — images, containers, volumes, and networks — that are dangling (not associated with a container)

> docker system prune

13) To remove a container by image-id

> docker rmi <first-few-chars-of-image-id>

14) To install a container

> docker pull docker/whalesay

15) To run container

e.g., > docker run docker/whalesay cowsay Hi

This will start the container from the image if the image is already present. If the image is not present already, it will download the image and start the container

16) To get ip address

> ifconfig

ens33: ...
inet <YOUR-IP-HERE>  netmask X.X.X.X  broadcast Y.Y.Y.Y

17) Find commands

> find . -type f -name filename

To find files with name filename in the current directory

> find / -type d -name directoryname

To find directories with name directoryname in the entire disk

Comments

Popular posts from this blog

GoLang - How to check if key exists in map?

package main import "fmt" var m map[string]string func main() { m = make(map[string]string) m["foo"] = "abc" if val, ok := m["foo"]; ok { fmt.Println("foo found -", val) } else { fmt.Println("foo not found") } if val, ok := m["bar"]; ok { fmt.Println("bar found -", val) } else { fmt.Println("bar not found") } } Output: foo found - abc bar not found

How to delete commits in Git?

Suppose you have 3 commits with SHAs as follows: HEAD~0 --> Commit 3 ccccccc HEAD~1 --> Commit 2 bbbbbbb HEAD~2 --> Commit 1 aaaaaaa If you want to remove the last two commits (i.e., commits 2 and 3) and make Commit 1 as the latest commit, run the following commands: git reset --hard aaaaaaa git push origin HEAD --force Now, the commit history would be as follows: HEAD~0 --> Commit 1 aaaaaaa