Operations 73 min read

Master Linux Command Line: Essential Commands and Tips for Beginners

This comprehensive guide walks you through Linux command line fundamentals, covering directory navigation, file manipulation, text processing, compression, system monitoring, networking, user management, permissions, and disk operations with clear examples, code snippets, and practical tips for both newcomers and seasoned users.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Master Linux Command Line: Essential Commands and Tips for Beginners

1. Linux Command Overview

The article begins with an overview of essential Linux commands for directory and file operations, such as mkdir, cp, mv, and rm, explaining their common options ( -p, -r, -v, -f) and providing usage examples.

# Create nested directories and a file
mkdir -p a/b/c
touch a/b/c/file.txt
# Copy, move, and delete examples
cp -rv a/b/c/file.txt backup/
mv a/b/c/file.txt new_location/
rm -rf a/b/c

2. Directory Navigation

Key navigation commands include pwd to display the current directory, cd for changing directories, and shortcuts like ~ (home), .. (parent), . (current), and - (previous). The article demonstrates creating a deep directory tree and moving between levels.

# Create a 7‑level directory tree
mkdir -p a1/b2/c3/d4/e5/f6/{g7,g8,g9,g10}
# Navigate to the deepest level and back
cd a1/b2/c3/d4/e5/f6/g7
pwd
cd ..
pwd
cd -

3. Viewing Files

Various tools for displaying file contents are covered: cat – prints the whole file (use -n for line numbers). less – paginated view with navigation keys (Space, b, /, q, g, G). head and tail – show the beginning or end of a file, with -n to specify line count.

# Show first 5 lines
head -n 5 file.txt
# Follow a log file in real time
tail -f /var/log/messages

4. Searching and Filtering

The guide introduces grep for pattern matching, including color output ( --color), line numbers ( -n), and context options ( -A, -B, -C). It also covers find for locating files and combining it with xargs for batch operations.

# Find all Python files named decorator.py
find / -type f -name decorator.py
# Delete all .class files in current directory tree
find . -name "*.class" | xargs rm -rvf
# Show lines containing "Exception" with context
grep -rn --color "Exception" -A10 -B2 error.log

5. Text Processing Tools

Common utilities such as awk, sed, sort, and uniq are mentioned for column‑wise processing, pattern substitution, sorting, and deduplication. Examples illustrate extracting the third field from a log, sorting numerically, and counting unique occurrences.

# Extract IP column from nginx log and count top 10
awk -F"|" '{print $3}' access.log | sort | uniq -c | sort -nk1 -r | head -n10

6. Compression and Archiving

The article explains creating tar archives and compressing them with gzip, resulting in .tar.gz files. It also lists other formats ( .bz2, .zip, .rar) and shows how to list archive contents or extract to a specific directory.

# Create a compressed tarball
tar cvfz files.tar.gz files/
# List contents of a tarball
tar tvf files.tar.gz
# Extract to /opt directory
tar xvfz files.tar.gz -C /opt

7. System Monitoring

Commands for checking system status include: uname -a – kernel and OS information. ps -ef and top – process inspection. free – memory usage. df -h – disk space. ifconfig / ip addr – network interfaces. netstat -ant – active TCP connections.

8. Network Utilities

Essential networking commands covered are ssh for remote login, scp and sftp for file transfer, wget -c for downloading with resume support, and ping for connectivity testing.

# Remote login to a server
ssh [email protected]
# Copy a file to a remote host
scp a.txt user@host:/tmp/
# Download a large file with resume
wget -c http://example.com/bigfile.bin

9. User and Permission Management

Creating users ( useradd), setting passwords ( passwd), and assigning groups ( usermod -G) are demonstrated. File ownership is changed with chown, group ownership with chgrp, and permissions with chmod using symbolic notation (e.g., u+x, g+r, a=rw) and numeric mode (e.g., 755).

# Add a user and set password
useradd zhang3
passwd zhang3
# Change ownership of a script
chown zhang3:zhang3 /tmp/confirm777.sh
# Give the owner execute permission
chmod u+x /tmp/confirm777.sh

10. Disk Management

The guide walks through adding a new virtual disk, partitioning it with fdisk, formatting (e.g., mkfs.xfs /dev/sdb1), mounting ( mount /dev/sdb1 /data), and making the mount persistent by editing /etc/fstab. It also explains swap space creation with mkswap and activation with swapon / swapoff.

# Partition a new disk
fdisk /dev/sdb   # use 'n' to create a partition, then 'w' to write
# Format the partition as XFS
mkfs.xfs /dev/sdb1
# Mount it
mkdir /data
mount /dev/sdb1 /data
# Add to fstab for automatic mounting
echo "/dev/sdb1 /data xfs defaults 0 0" >> /etc/fstab
# Create and enable swap on a partition
mkswap /dev/sdb2
swapon /dev/sdb2

11. Miscellaneous Utilities

Additional useful commands include: dd if=/dev/urandom of=test bs=1M count=69 – generate a random file of a specific size. stat – display detailed file metadata (size, timestamps, permissions). chmod 777 vs. symbolic modes, and the effect of the sticky bit ( t) on directories like /tmp to prevent users from deleting each other's files.

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.

LinuxTutorialSystem Administration
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

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.