Operations 26 min read

Master Essential Linux Commands: From Basics to Advanced System Operations

This comprehensive guide walks you through Linux command connectors, system resource monitoring tools, file search and transfer utilities, text processing commands, mounting and NFS configuration, user and file management, as well as advanced scripting techniques like expect, semanage, and xargs, providing clear examples and code snippets for each topic.

Raymond Ops
Raymond Ops
Raymond Ops
Master Essential Linux Commands: From Basics to Advanced System Operations

0. Command Connectors

; ; executes commands sequentially; & runs the following command regardless of the previous command's success; && runs the next command only if the previous one succeeds; | pipes the output of the first command to the second; || runs the second command only if the first fails.

1. System Resource Monitoring Commands

1) File system inspection with df

The df command shows filesystem usage, including space occupied by deleted files that are still held by processes.

df output
df output

2) Directory and file size with du

du

reports disk usage for files and directories.

du -sh * | sort -nr
du output
du output

3) Process inspection with ps

[publisher@shfttppfbdb ~]$ ps -ef|grep sync
publish+  15990      1 97 Jun30 ?        33-12:38:36 python3.6 -u sync_bmcapp_newversion.py
publish+  40899      1 99 Jun29 ?        34-16:32:24 python3.6 -u sync_hxapp_newversion.py
publish+ 129897 129351  0 15:16 pts/1    00:00:00 grep --color=auto sync
[publisher@shfttppfbdb ~]$ ps -ef|grep sync |awk '{print $2}'
15990
40899
129914
[publisher@shfttppfbdb ~]$

The grep -v grep pattern filters out the grep process itself.

2. Editing Commands with vi

1) Command mode

Press ESC to enter command mode; commands are not echoed on screen. Example: G jumps to the end of the file, gg to the beginning.

2) Insert mode

Use i, a, o, c, r or s to start inserting text. Press ESC to return to command mode.

3) Ex (last‑line) mode

Press : to enter ex mode, where commands such as wq (write and quit) or q! (force quit) are entered.

4) Vim substitution

Search and replace syntax: :[range]s/<search>/<replace>/<modifier>. range can be % for the whole file or specific line numbers. Modifiers include g (global), gc (confirm each replacement), and gn (highlight only).

:%s/python/Python3/g
:%s/python\|py/Python3/g

3. File Search Commands

1) grep

# Find a specific string in a file
grep 'string' filename
# Search all files in a directory
grep 'string' dirPath/*
# Recursive search
grep -r 'string' ./

2) find

# Find a file by name
find / -name install.log
# Find files modified more than 10 days ago
find . -mtime +10
# Find files of a specific size
find . -size 25k
# Find files between 20KB and 50KB and list details
find /etc -size +20k -a -size -50k -exec ls -lh {} \;

3) whereis and which

# Locate command and its documentation
whereis command_name
# Locate only the executable
whereis -b command_name
# Locate only the manual page
whereis -m command_name

4) locate

# Fast filename search using the database
locate filename
# Update the database
updatedb

4. File Transfer Commands

1) scp

# Download a single file
scp user@host:/remote/path/file.txt /local/path
# Download a directory
scp -r user@host:/remote/dir /local/path
# Upload a file
scp /local/file.txt user@host:/remote/path
# Upload a directory
scp -r /local/dir user@host:/remote/path

2) rsync

# Sync a remote directory to local, excluding some sub‑dirs
rsync -azh -e ssh --exclude 'l_temp' --exclude 'l_tmp/claimImageList' user@host:/remote/dir /local/dir
# Example with log file and exclusion list
rsync -az /source/path /dest/path --log-file=./rsync.log --exclude-from=/path/exclude.conf --delete

3) rz (Zmodem)

Used for transferring files from a local PC to a remote terminal; the command is invoked from the remote side.

4) sftp

sftp user@host
put local_file remote_path
get remote_file local_path

5. Linux Text Operations

1) The "Three Musketeers": grep , sed , awk

Refer to external tutorials for detailed usage.

2) Sorting with sort

sort

supports many options for numeric, reverse, and field‑based sorting, useful for top‑N problems.

3) Splitting files with split

split -b 1024M bigfile.tar.gz part_
cat part_* > bigfile.tar.gz
md5sum bigfile.tar.gz

4) Mounting and NFS

Query and automatic mount

# Show mounted devices
mount
# Mount all entries from /etc/fstab
mount -a
# Show NFS exports from a server
showmount -e 192.168.161.128

Mount command syntax

mount [-t filesystem] [-o options] device mount_point

Unmount

umount /dev/sda1
umount /mount/point

Install NFS on CentOS

sudo yum install nfs-utils
sudo systemctl start rpcbind nfs-server nfs-lock nfs-idmap
sudo systemctl enable rpcbind nfs-server nfs-lock nfs-idmap
# Add export
echo "/nfs/data *(rw,sync,no_root_squash,no_all_squash)" >> /etc/exports
sudo exportfs -rav
sudo systemctl restart nfs-server
# Open firewall ports
sudo firewall-cmd --permanent --zone=public --add-service=nfs
sudo firewall-cmd --permanent --zone=public --add-service=mountd
sudo firewall-cmd --permanent --zone=public --add-service=rpc-bind
sudo firewall-cmd --reload

Mount NFS on client (temporary)

sudo mount -t nfs 192.168.44.132:/nfs/data /nfs/data

Permanent mount via /etc/fstab

192.168.44.132:/nfs/data /nfs/data nfs defaults 0 0

Install NFS on Ubuntu

sudo apt update
sudo apt install nfs-kernel-server
sudo mkdir -p /srv/nfs/share
sudo vi /etc/exports   # add: /srv/nfs/share *(rw,sync,no_subtree_check)
sudo exportfs -ra
sudo systemctl start nfs-kernel-server
sudo systemctl enable nfs-kernel-server
# Client side
sudo apt install nfs-common
sudo mount 192.168.44.132:/srv/nfs/share /mnt

6. Automation with expect

#!/usr/bin/expect
spawn ssh [email protected]
expect "password:"
send "mypassword\r"
expect "$ "
send "ls -l\r"
expect eof
spawn

starts a process, expect waits for output, send sends input, and interact can hand control back to the user.

7. Encryption with openssl

tar -zcf - host.conf | openssl des3 -salt -k ZYProduct@2022 | dd of=host.des
openssl des3 -d -k ZYProduct@2022 | tar zxf -

8. Evaluation with eval

eval

concatenates its arguments into a single command string and executes it in the current shell.

9. Argument transformation with xargs

Common options: -n (number per command), -d (delimiter), -p (prompt), -t (show command), -I (placeholder), -r (skip empty).

# Find files containing "password"
find . -name "*.txt" -exec grep "password" {} \;
# Or using xargs
find . -name "*.txt" | xargs grep "password"
# Pass each line as a separate argument
echo "hello world" | xargs -n 1
# Split on a custom delimiter
echo "hello#world" | xargs -d "#" echo

10. Output with echo

echo -e "\e[1;33m test \e[0m"   # colored output

11. Linux User Management

1) User and group creation

groupadd mysql
useradd -u 544 -d /home/mysql -g mysql -m mysql

2) Change ownership

# Change owner and group of a file
chown zhuo:zhuogroup test.php
# Recursively change owner and group of a directory
chown -R zhuo:zhuogroup testdir

12. Linux File Management

1) File types

Regular files, directories, symbolic links, device files, sockets, etc.

2) Sorting files

Use sort with appropriate options for numeric, reverse, or field‑based ordering.

13. SELinux Management with semanage

Common parameters

port

manages network port types; fcontext manages file contexts. Options: -l list, -a add, -m modify, -d delete, -t type, -p protocol, -e inherit context.

Installation check

# Install semanage on RHEL/CentOS
yum install policycoreutils-python -y

Enable SELinux

# Verify SELinux status
egrep -i selinux /etc/sysconfig/selinux
# Set enforcing mode
sed -i 's/^SELINUX=.*/SELINUX=enforcing/' /etc/sysconfig/selinux
reboot

Port management

# List all defined ports
semanage port -l
# Add a new HTTP port
semanage port -a -t http_port_t -p tcp 8081
# Delete the port
semanage port -d -t http_port_t -p tcp 8081

File context management

# List file contexts
semanage fcontext -l
# Add a new context
semanage fcontext -a -t httpd_sys_content_t '/var/www/html(/.*)?'
# Apply changes
restorecon -Rv /var/www/html

14. Miscellaneous Useful Commands

eval

– execute constructed command strings. expect – automate interactive sessions. openssl – encrypt/decrypt data streams. xargs – build and execute command lines from standard input. echo – display text with optional escape sequences.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

command-lineNFSfile management
Raymond Ops
Written by

Raymond Ops

Linux ops automation, cloud-native, Kubernetes, SRE, DevOps, Python, Golang and related tech discussions.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.