Command Line Mastery: Key Linux Commands for Everyday Use

am dynamic DevOps Engineer and Web Developer with 4+ years of experience in automation, CI/CD pipelines, and infrastructure optimization. I possess strong skills in PHP, AngularJS, MySQL, AWS, Linux, GIT, Jenkins, and Terraform. My goal is to leverage my expertise in DevOps methodologies and cloud technologies to drive innovation and efficiency across projects, ensuring timely delivery and high-quality software products.
User Management :
| Command | Info | Syntax |
| useradd | Create a new user | useradd username |
| userdel | Delete a user account | userdel username |
| usermod | Modify a user account. | usermod [option] group_name username |
| useradd -d | Add User by Specifying a home directory path | useradd -d /home/test_user test_user |
| useradd -u | To create a new user with a custom UID | useradd -u 1234 username |
| useradd -e | To set an expiry date for a user account, | useradd -e 2020-05-30 username |
| useradd -g | To create a new user and assign a primary group | useradd -g group_name username |
| useradd -g gid | To create a new user and assign a specific group ID | useradd -g 1000 test_user |
| useradd -G | To create a new user and assign a secondary group | useradd -G group_name username |
| useradd -s /bin/sh | To create a user with a different login shell (nologin/login). | useradd -s /bin/sh test_user |
| getent passwd | Display list of users | getent passwd |
Group Management:
| Command | Info | Syntax |
| groupadd | Create a new group | groupadd group_name |
| groupdel | Delete a group | groupdel group_name |
| groupmod | modify or change the existing group | groupmod [option] GROUP |
| gpasswd | Add password to group with group name | gpasswd group_name |
| gpasswd -r | Delete group password | gpasswd -r group_name |
| getent group | list all the available groups |
Options: There are following option available in groupmod command.
-g, –gid GID: The group ID of the given GROUP will be changed to GID.
-n, –new-name NEW_GROUP: The name of group will change into newname.
-h, –help: This option display help message and exist.
-o, –non-unique: This option used with the -g option that allow to change the group GID to a non-unique value.
-p, –password PASSWORD: This gives the encrypted password.
-R, –root CHROOT_DIR: Apply changes in the CHROOT_DIR directory and use the configuration files from the CHROOT_DIR directory.
Process/System Management:
| Command | Info | Syntax |
| ps | Display information about running processes | ps |
| ps -f | Display full information about running processes | ps -f |
| ps process_id | For single-process information, ps along with process id is used | ps process_id |
| bg | Resumes suspended jobs and runs them in the background. | bg [ job ] |
| fg | It continues a stopped job by running it in the foreground. | fg [ %job_id ] |
| kill | Terminate processes | kill process_id |
| top | Display and update sorted information about processes | top |
| htop | Interactive process viewer | htop |
| vmstat | Report virtual memory statistics | vmstat |
| free | Display amount of free and used memory in the system | free -m |
| df | Display disk space usage | df |
| sar | Collect, report, or save system activity information | sar |
| iostat | Report CPU and I/O statistics | iostat |
| nice | It starts a new process (job) and assigns it a priority (nice) value at the same time. | nice [-nice value] |
| renice | To change the priority of an already running process renice is used. | renice [-nice value] [process id] |
For a running program (named process) Pidof finds the process id’s (pids)
Fields described by ps are described as:
UID: User ID that this process belongs to (the person running it)
PID: Process ID
PPID: Parent process ID (the ID of the process that started it)
C: CPU utilization of process
STIME: Process start time
TTY: Terminal type associated with the process
TIME: CPU time is taken by the process
CMD: The command that started this process
There are other options which can be used along with ps command :
-a: Shows information about all users
-x: Shows information about processes without terminals
-u: Shows additional information like -f option
-e: Displays extended information.
Archive Management:
tar: Create a tar Archive.
Syntax : tar [options] [archive-file] [file or directory to be archived]
| Option | Info |
| -c,--create | Create a new archive. |
| -v,--verbose | Verbosely list files processed. |
| -f,--file | Specify the filename |
| -x,--extract | Extracts files from an archive. |
| -t,--list | Show list of file & directory without extract tar file. |
| -j,--bzip2 | Create with bzip2 compression/big file |
| -z,--gzip | Create with gzip compression . |
| -J,--xz | Create with xz compression. |
| -r | recursive store file in tar file |
System Control :
1) cron: Schedule tasks to run periodically.
| Option | Info |
| crontab -e | Edit the scheduling for current user |
| crontab -l | Show list of scheduling for current user |
| crontab -r | Remove all scheduling for current user |
| crontab -e -u | Edit the scheduling for particular user |
| crontab -l -u | Show list of scheduling for particular user |
| crontab -r -u | Remove all scheduling for particular user |
2) systemctl: Control the systemd system and service manager.
Syntax : systemctl [option] service_name
| Option | Info |
| start | start the service |
| stop | stop the service |
| status | check the status of the service |
| restart | 1st stop service and then start service give downtime |
| reload | without stop, start service not given downtime |
| enable | boot time active |
| disable | boot time disable |
| mask | permanent lock/stop service |
| unmask | to remove mask |
3) journalctl: to query and display logs from the systemd journal, which is a system service that collects and stores logging data
Syntax :journalctl
Package Management
| Command | Info | Syntax |
| yum/dnf | Package manager for RPM-based Linux distributions. | yum install package_name |
| apt-get install | Installing a package | apt-get install package-name |
| apt-get update | Updating the package list | apt-get update |
| apt-get upgrade | Upgrading packages | apt-get upgrade |
| apt-get remove | Removing a package | apt-get remove package-name |
| rpm | Package manager for RPM-based Linux distributions. | bash rpm -i package.rpm |


