Operations 14 min read

Master Essential Linux Commands: From uname to updatedb

This guide walks through dozens of fundamental Linux shell commands—including uname, hostname, dmesg, stat, du, date, echo, watch, which, whereis, locate, and updatedb—explaining their options, usage examples, and how to interpret their output for effective system administration.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Master Essential Linux Commands: From uname to updatedb

1. uname – display system information

uname -a

– shows all system information.

uname -m

– displays the hardware architecture.

uname -n

– shows the host name.

uname -r

– displays the kernel release version.

uname -s

– shows the kernel name.

uname -p

– displays the processor type.

uname -o

– shows the operating system name.

uname -i

– displays the hardware platform.

2. hostname – display or set the system host name

hostname

– shows the current host name.

hostname -A

– temporarily changes the host name (lost after reboot).

vi /etc/hostname

– permanently modify the host name (effective after reboot).

vi /etc/hosts

– add a name resolution entry for a host (e.g., Mr.white).

hostname -I

– retrieves all IP addresses of the system (useful for multi‑NIC hosts).

3. dmesg – kernel ring buffer diagnostics

dmesg | less

– view kernel messages, useful for hardware fault diagnosis.

4. stat – display file or filesystem status

stat /etc/hosts

– shows detailed information about the file.

stat -f /etc/hosts

– displays filesystem attributes.

5. du – estimate disk space usage

du -a

– shows space used by all files and directories.

du -s

– displays the total size of a directory.

du -h

– presents sizes in human‑readable units (K/M/G).

du -sh

– shows the total size of the current directory in a readable format.

du -h --max-depth=1 /usr/local/

– lists sizes of the first‑level subdirectories.

du -h --max-depth=2 /usr/local/

– includes second‑level directories.

du -h --max-depth=2 /usr/local/ --exclude=/usr/local/share

– same as above but excludes a specific path.

6. date – display or set system time

date +%y

– short year (e.g., 23).

date +%Y

– full year (e.g., 2023).

date +%m

– month number.

date +%d

– day of month.

date +%H

– hour (24‑hour format).

date +%M

– minutes.

date +%S

– seconds.

date +%F

– formatted date (YYYY‑MM‑DD).

date +%T

– formatted time (HH:MM:SS).

date +%F -d '-1day'

– yesterday’s date.

date +%F -d 'yesterday'

– another way to show yesterday.

date +%F -d '-1440min'

– yesterday using minutes offset.

date +%F -d '+1day'

– tomorrow’s date.

date +%F -d '+tomorrow'

– alternative tomorrow command.

date +%F -d '1month'

– date one month from now.

date +%F -d '1year'

– date one year from now.

date -d 'Thu Jul 6 21:41:16 CST 2017' '+%Y-%m-%d %H:%M:%S'

– convert a custom date string to a standard format.

date -s 20201220

– set system date (YYYYMMDD).

date -s '18:24:30 20201220'

– set both time and date.

date +%D%n%T

– display date, newline, then time.

7. echo – output a line of text

echo Hello world!

– prints the string.

echo 'Hello world!'

– prints the string with single quotes.

echo "hello world!"

– double quotes cause the exclamation mark to be interpreted specially.

Without the exclamation mark, the text prints normally.

echo "hello world"!

– the exclamation can be placed after the string.

echo "hello world\!"

– escape the exclamation to print it.

echo -e "hello\tworld"

– prints a tab between words.

echo -e "hello
world"

– prints a newline.

echo hello world >> hello.txt

– appends output to a file.

echo hello; echo world

– use a semicolon to run two commands sequentially.

echo -n hello; echo world

-n suppresses the newline after the first echo.

echo -e '\033[31m red text mr.white training \033[0m'

– prints colored text (red).

echo -e '\033[41;37m red background white text mr.white training \033[0m'

– prints text with red background and white foreground.

echo $PATH

– displays the current PATH environment variable.

8. watch – monitor command execution

watch -n 1 -d netstat -ant

– refresh every second, highlight changes in network connections.

watch cat test1220.txt

– monitor changes to a specific file.

watch -t cat test1220.txt

– same as above but without the header.

9. which – locate the full path of a command

which date

– shows the full path of the date command.

which which

– reveals the path (and any alias) of the which command itself.

which java

– displays the location of the Java executable.

which -a java

– lists all occurrences of java in the PATH.

10. whereis – locate command binaries, sources, and manuals

whereis java

– shows binary, source, and manual locations for Java.

whereis -b java

– searches only for executable binaries.

whereis -m java

– searches only for manual pages.

whereis -s java

– searches only for source files (none found in this example).

11. locate – fast file path lookup

Install the utility: yum install mlocate.

locate pwd

– finds paths containing “pwd”.

locate -c pwd

– counts matching entries.

locate /etc/sh

– returns any path containing the substring.

locate /etc/sh*

– uses a wildcard to match patterns.

locate /etc/*sh*

– another wildcard example.

12. updatedb – update the mlocate database

updatedb

– creates or refreshes the database used by locate. A daily cron job typically runs this.

To update a specific directory: updatedb -vU /root/mytest20201219/ – verbose output, updating only the given path.

(© original author, all rights reserved)

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.

LinuxShellUnix
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

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.