Skip to main content

Command Palette

Search for a command to run...

Command Line Mastery: Key Linux Commands for Everyday Use

Updated
6 min readView as Markdown
Command Line Mastery: Key Linux Commands for Everyday Use
S

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 :

CommandInfoSyntax
useraddCreate a new useruseradd username
userdelDelete a user accountuserdel username
usermodModify a user account.usermod [option] group_name username
useradd -dAdd User by Specifying a home directory pathuseradd -d /home/test_user test_user
useradd -uTo create a new user with a custom UIDuseradd -u 1234 username
useradd -eTo set an expiry date for a user account,useradd -e 2020-05-30 username
useradd -gTo create a new user and assign a primary groupuseradd -g group_name username
useradd -g gidTo create a new user and assign a specific group IDuseradd -g 1000 test_user
useradd -GTo create a new user and assign a secondary groupuseradd -G group_name username
useradd -s /bin/shTo create a user with a different login shell (nologin/login).useradd -s /bin/sh test_user
getent passwdDisplay list of usersgetent passwd

Group Management:

CommandInfoSyntax
groupaddCreate a new groupgroupadd group_name
groupdelDelete a groupgroupdel group_name
groupmodmodify or change the existing groupgroupmod [option] GROUP
gpasswdAdd password to group with group namegpasswd group_name
gpasswd -rDelete group passwordgpasswd -r group_name
getent grouplist 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:

CommandInfoSyntax
psDisplay information about running processesps
ps -fDisplay full information about running processesps -f
ps process_idFor single-process information, ps along with process id is usedps process_id
bgResumes suspended jobs and runs them in the background.bg [ job ]
fgIt continues a stopped job by running it in the foreground.fg [ %job_id ]
killTerminate processeskill process_id
topDisplay and update sorted information about processestop
htopInteractive process viewerhtop
vmstatReport virtual memory statisticsvmstat
freeDisplay amount of free and used memory in the systemfree -m
dfDisplay disk space usagedf
sarCollect, report, or save system activity informationsar
iostatReport CPU and I/O statisticsiostat
niceIt starts a new process (job) and assigns it a priority (nice) value at the same time.nice [-nice value]
reniceTo 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]

OptionInfo
-c,--createCreate a new archive.
-v,--verboseVerbosely list files processed.
-f,--fileSpecify the filename
-x,--extractExtracts files from an archive.
-t,--listShow list of file & directory without extract tar file.
-j,--bzip2Create with bzip2 compression/big file
-z,--gzipCreate with gzip compression .
-J,--xzCreate with xz compression.
-rrecursive store file in tar file

System Control :

1) cron: Schedule tasks to run periodically.

OptionInfo
crontab -eEdit the scheduling for current user
crontab -lShow list of scheduling for current user
crontab -rRemove all scheduling for current user
crontab -e -uEdit the scheduling for particular user
crontab -l -uShow list of scheduling for particular user
crontab -r -uRemove all scheduling for particular user

2) systemctl: Control the systemd system and service manager.

Syntax : systemctl [option] service_name

OptionInfo
startstart the service
stopstop the service
statuscheck the status of the service
restart1st stop service and then start service give downtime
reloadwithout stop, start service not given downtime
enableboot time active
disableboot time disable
maskpermanent lock/stop service
unmaskto 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

CommandInfoSyntax
yum/dnfPackage manager for RPM-based Linux distributions.yum install package_name
apt-get installInstalling a packageapt-get install package-name
apt-get updateUpdating the package listapt-get update
apt-get upgradeUpgrading packagesapt-get upgrade
apt-get removeRemoving a packageapt-get remove package-name
rpmPackage manager for RPM-based Linux distributions.bash rpm -i package.rpm

More from this blog

Swapna Aware's Blog

19 posts