Essential Linux Commands: uname, hostname, dmesg, du, date, echo and More
This guide presents a concise reference of common Linux command‑line utilities—including uname, hostname, dmesg, stat, du, date, echo, watch, which, whereis, locate and updatedb—showing their typical options, usage examples and visual output to help users quickly retrieve system information, manage files and monitor processes.
uname – display system information
Common options: uname -a – show all related system information. uname -m – display hardware architecture. uname -n – show the host name. uname -r – display kernel release number. uname -s – show kernel name. uname -p – display processor type. uname -o – show operating system name. uname -i – display hardware platform.
hostname – view or set the system host name
hostname– print the current host name. hostname A – temporarily change the host name (lost after reboot). vi /etc/hostname – permanently modify the host name. vi /etc/hosts – add a custom name resolution entry (e.g., for Mr.white). hostname -I – list all IP addresses assigned to the machine.
dmesg – diagnose system boot and kernel messages
Typical usage:
dmesg | less # view kernel buffer, useful for hardware fault investigationstat – display file or filesystem status
stat /etc/hosts– show file metadata. stat -f /etc/hosts – display filesystem attributes.
du – summarize disk space usage
du -a– list space used by all files and directories. du -s – show total size of a directory. du -h – present sizes in human‑readable units (K/M/G). du -sh – combined total size in a readable format. du -h --max-depth=1 /usr/local/ – show first‑level directory sizes. du -h --max-depth=2 /usr/local/ – show first two levels. du -h --max-depth=2 /usr/local/ --exclude=/usr/local/share – same as above but exclude a specific path.
date – display and set system time
date +%y– short year (YY). date +%Y – full year (YYYY). date +%m – month. date +%d – day of month. date +%H – hour (24‑hour). date +%M – minute. date +%S – second. date +%F – ISO date (YYYY‑MM‑DD). date +%T – time (HH:MM:SS).
Relative date examples: date -d '-1day' +%F (yesterday), date -d '+1day' +%F (tomorrow), date -d '1month' +%F (one month later), date -d '1year' +%F (one year later).
Custom format conversion: date -d 'Thu Jul 6 21:41:16 CST 2017' '+%Y-%m-%d %H:%M:%S'.
Set date: date -s 20201220 (date only) or date -s '18:24:30 20201220' (full timestamp).
Combined display: date +%D%n%T – date, newline, then time.
echo – output text to the terminal
echo Hello world!– simple output. echo 'Hello world!' – output with single quotes. echo "hello world!" – double quotes (note special handling of ! in some shells).
Escape characters: echo "hello\!" prints hello!.
Tab and newline: echo -e "hello\tworld", echo -e "hello\nworld".
Redirect to file: echo hello world >> hello.txt.
Command chaining: echo hello; echo world or echo -n hello; echo world (no newline after first).
Colored output: echo -e '\033[31m red text \033[0m' (red foreground), echo -e '\033[41;37m red background white text \033[0m'.
Print environment variable: echo $PATH.
watch – monitor command execution periodically
watch -n 1 -d netstat -ant– run netstat -ant every second, highlighting changes. watch cat test1220.txt – watch a file for changes. watch -t cat test1220.txt – same without the header.
which – locate the full path of a command
which date– show path of date. which which – reveal alias information if any. which java – path of java. which -a java – all locations containing java.
whereis – find command binaries, sources and manuals
whereis java– display binary, source and man page locations. whereis -b java – only binaries. whereis -m java – only manual pages. whereis -s java – only source files (often none).
locate – quickly find files by name
First install the database utility:
yum install mlocate locate pwd– list paths containing pwd. locate -c pwd – count matching entries. locate /etc/sh – fuzzy match. locate /etc/sh* – wildcard search. locate /etc/*sh* – broader wildcard pattern.
updatedb – update the mlocate database
The updatedb command builds or refreshes the index used by locate. It is typically scheduled via a daily cron job. updatedb – initialize the database.
Check the cron schedule for automatic updates. updatedb -vU /root/mytest20201219/ – verbose update limited to a specific directory.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
