DEV Community

technonotes-hacker
technonotes-hacker

Posted on

Linux Commands - DAY 4

24-07-2023

Image description


KILL

  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

Enter fullscreen mode Exit fullscreen mode

Image description

Image description

Image description

Image description


KILLALL

  • 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>
Enter fullscreen mode Exit fullscreen mode

Image description

Image description

Image description


PIDOF

  • Helps to find the PID of the program.
  • But how to get the program name ? [TBD]
pidof chrome
pidof java
Enter fullscreen mode Exit fullscreen mode

Image description


NICE & RENICE

  • 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>
Enter fullscreen mode Exit fullscreen mode

Eg., please provide a sleep process and test ,

Image description

Image description

below is the output of HTOP,

Image description

Image description


USERADD

  • 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
Enter fullscreen mode Exit fullscreen mode

Image description

Image description

Image description


ADDUSER

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

Image description


PASSWD

  • 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.
Enter fullscreen mode Exit fullscreen mode

Image description

Image description

Image description


USERDEL

  • 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
Enter fullscreen mode Exit fullscreen mode

Image description


DELUSER

  • 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.
Enter fullscreen mode Exit fullscreen mode

Image description


GROUPADD

  • to create a new group.
sudo groupadd group_name
sudo groupadd <group_name> -g 1234 --> with specific groupid
Enter fullscreen mode Exit fullscreen mode

ADDGROUP

  • add group to the system.
sudo addgroup <group_name>
sudo addgroup group_name --gid 6789
Enter fullscreen mode Exit fullscreen mode

GROUPDEL

  • to delete the group.
sudo groupdel group_name
Enter fullscreen mode Exit fullscreen mode

DELGROUP

  • remove a group from the system
sudo delgroup group_name
Enter fullscreen mode Exit fullscreen mode

GROUPS

  • to get the group of the users.
groups <username>
groups
sudo su -
# groups
Enter fullscreen mode Exit fullscreen mode

Image description


ID

  • 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
Enter fullscreen mode Exit fullscreen mode

Image description


USERMOD

  • 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
Enter fullscreen mode Exit fullscreen mode

LN

  • 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

Enter fullscreen mode Exit fullscreen mode

Image description

Image description

Image description

Image description


UNLINK

  • call the unlink function to remove the specified file.
unlink filename
unlink dir_name
unlink softlink_file.txt
Enter fullscreen mode Exit fullscreen mode

Image description


Important Notes :

  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.

Top comments (0)