Linux Commands - DAY 4
Published: 2023-08-12 23:16:23

> **24-07-2023**
---

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bsug0u3xzll7zxa1h5k1.png)

---

## **<u>KILL</u>**

1. which transfers or sends signal to the process.
2. Then what is process ? A task that your Linux machine is currently working on.
Eg., ஒரு browser open  பண்றோம் , now Linux creates a PROCESS.

```
kill -l    --> gives list of available signals
kill <pid> --> PID can be taken from the **ps aux** command
kill <pid> <pid> <pid> --> also end multiple pid also in one kill command.
kill -9 <pid>
kill -l 9
kill -l 3

```
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4ivp1ab0lh6szzijlkqr.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lutbobg899nxp2vso4bp.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8sofo73dlgdaog9epr90.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wu7ijpypaebe5hm0od2d.png)

---


## **<u>KILLALL</u>**

- Same like kill , but here we are passing the program name rather than PID.
- -i can be used for interactive mode.

```
killall <program_name>
killall chrome
killall -l --> list all the signals which are available.
killall -i <program1> <program2>
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zdbcgktfh83mqnsea2qp.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ferm8shqp9pzughepbik.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s9ky1vgb4xuxfdrhcmvu.png)

---

## **<u>PIDOF</u>**

- Helps to find the PID of the program.
- But how to get the program name ? [TBD]

```
pidof chrome
pidof java
```
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7sztwqi3qiaax4r0qopz.png)

---

## **<u>NICE & RENICE</u>**

- to change the scheduling priority.
- Nice value range (NI): -20 to 19.
- users can only specify values from 1 to 19
- root user can specify the full range of values
- renice will help to resize it.
- '+' are low priority
- '-' high priority

```
sudo nice -n 5 tar -czf backup.tar.gz ./Documents/*
ps -el | grep htop --> check the nice value , its "ni" ( 4th column )
ps aux | grep sleep
ps -o pid,nice 36323 ( get using PID )
nice -n <number><process name>  --> set the priority
nice -10 htop
sudo renice -n 10 -p <PID>
```

Eg., please provide a sleep process and test ,


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zi46gftb9psux0dkk7bn.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mm7datmy7i56f1oat1uw.png)

below is the output of _**HTOP**_,

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/66jnhhpilqo7cxbmbqjz.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ejnl958nlkis3jsy5t36.png)

---

## **<u>USERADD</u>**

- Used to create the user or update the user.
- always we need to execute this command using sudo.
- each user gets a unique ID (UID) , even that we can choose on our own.

```
sudo useradd user1 --> this won't create any home directory , it will create only user.
sudo useradd -m user_name --> this creates a home directory
sudo useradd -u 1004 user3
tail -3 /etc/passwd   --> to check whether the UID is created
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1lgfun5jbfnuwyvu9lks.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p6lyx37wxq6hcd68oj84.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vvtkc4th291sy7vsa5hh.png)

---

## **<u>ADDUSER</u>**

- This is ask all questions like password , name , etc

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4xqasp48g61bdon3vb85.png)

---

## **<u>PASSWD</u>**

- change the user password.

```
passwd ( just type this , you can change the current user password )
sudo passwd -S user2
sudo passwd -Sa   --> all user information
sudo passwd root  --> root user can also be change by this way.
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mx9xfr9zqnxjd4qfbeve.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/egx668blcawbww3rwuw0.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aos9ckxnv4fienbf9ipc.png)

---

## **<u>USERDEL</u>**

- To delete the user.

```
sudo userdel user4 --> it will delete user but home directory will be there.
sudo userdel -r user3  --> this will delete the home directory also.
sudo userdel -f user_name  --> forcefully remove the user
```
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zdrt4hpz4ed0yui9nhu9.png)

---

## **<u>DELUSER</u>**

- to remove a user or group from the system.
- only sudo can delete the user.

```
sudo deluser user4
sudo deluser --remove-home user4
sudo deluser --force user4   --> Even while the user is logged in , it will be deleted forcefully.
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mob0nu7sccth1ndfyt9u.png)

---

## **<u>GROUPADD</u>**

- to create a new group.

```
sudo groupadd group_name
sudo groupadd <group_name> -g 1234 --> with specific groupid
```

---

## **<u>ADDGROUP</u>**

- add group to the system.

```
sudo addgroup <group_name>
sudo addgroup group_name --gid 6789
```

---

## **<u>GROUPDEL</u>**

- to delete the group.

```
sudo groupdel group_name
```
---

## **<u>DELGROUP</u>**

- remove a group from the system

```
sudo delgroup group_name
```
---

## **<u>GROUPS</u>**

- to get the group of the users.

```
groups <username>
groups
sudo su -
# groups
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0kybqagx96a7wsjaybki.png)

---

## **<u>ID</u>**

- print real and effective user and group IDs.

```
id
id -u testing   --> user id it will provide
id -g testing   --. group id it will provide
id testing
```
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9aw3v0wcrg0sr8riyk0n.png)

---

## **<u>USERMOD</u>**

- it's used to modify a user account.

```
sudo usermod -aG sudo <user_name>  --> add a user to sudo group
sudo usermod -aG group_name user_name --> add group to an existing user
```
---

## **<u>LN</u>**

- creates the hard and symbolic links between the files.

```
cat > sample_file.txt
this is hardlink file.
ln sample_file.txt sample_hardlink.txt --> original file got deleted in some scenario , in that situation we can use the linked file.

ln -s /home/testing/Documents/file.txt softlink_file.txt
--> symbolic or soft link to a file / folder
ln -s file.txt softlink_file.txt
ls -al softlink_file.txt

```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3bqoy6x0udgc2hkpzmpn.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/suun45ofzsl92exth9om.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yzobqpnh2gx1enw5ns1t.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kesjizh8ize5u2n18afo.png)

---

## **<u>UNLINK</u>**

- call the unlink function to remove the specified file.

```
unlink filename
unlink dir_name
unlink softlink_file.txt
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xova38acni2d4x8khqac.png)

---

## _<u>**Important Notes :**</u>_

1. control + p --> Previous command.

2. UID : A UID (user identifier) is a number assigned by Linux to each user on the system. This number is used to identify the user to the system and to determine which system resources the user can access.

3. Control + d --> come out of the command.