Master Essential Linux Commands: From Login to File Management
This comprehensive guide walks you through the most frequently used Linux commands—including login, shutdown, mount, file handling, searching, and system utilities—detailing their purpose, syntax, key options, practical examples, and tips for efficient system administration.
Login and Installation Commands
login – Purpose: log into the system (available to all users). Syntax: login [name] [-p] [-h hostname]. Key options: -p preserve the current environment; -h specify a remote host. Example: after the kernel and console information, the prompt shows localhost login:root and then asks for the password.
System Control Commands
shutdown – Purpose: safely shut down the computer (superuser only). Syntax: shutdown [-h] [-i] [-k] [-m] [-t]. Important options: -t set delay before changing runlevel; -k send warning signal only; -h power off after shutdown; -c cancel a pending shutdown; -F force fsck on reboot; -m switch to single‑user mode; -i display system info. Example: shutdown -h 3:40 shuts down at 3:40.
halt – Purpose: halt the system (superuser only). Syntax: halt [-n] [-w] [-d] [-f] [-i] [-p]. Key options: -n avoid writing to /etc/mtab; -w write to /var/log/wtmp only; -d do not leave a record; -f force halt without calling shutdown; -i turn off network interfaces; -p power off after halt.
reboot – Purpose: restart the computer (system administrator). Syntax: reboot [-n] [-w] [-d] [-f] [-i]. Key options: -n skip writing memory to disk; -w write to /var/log/wtmp only; -d do not write to /var/log/wtmp (implied by -n); -i shut down network interfaces before reboot.
File Management Commands
install – Purpose: copy or upgrade files and set permissions (all users). Syntax examples:
install [options] source destination install [options] source... directory install -d [options] directory...Key options: --backup[=CONTROL], -b, -c, -d, --directory, -D, -g, --group=GROUP, -m, --mode=MODE, -o, --owner=OWNER, -p, --preserve‑timestamps, -s, --strip, -S, --suffix=SUFFIX, -v, --verbose, --help, --version.
mount – Purpose: mount a filesystem (superuser or allowed users). Syntax: mount -a [-fv] [-t vfstype] [-n] [-rw] [-F] device dir. Key options: -h show help; -v verbose; -a mount all from /etc/fstab; -F run a helper for each mount; -f simulate mount for debugging; -t vfstype specify filesystem type; -n avoid writing to /etc/mtab. Tips: mount CD‑ROM, floppy, or other devices to directories under /mnt. Example: mount -t iso9660 /dev/hdc /mnt/cdrom.
umount – Purpose: unmount a filesystem (superuser or allowed users). Syntax: umount -a [-fFnrsvw] [-t vfstype] [-n] [-rw] [-F] device dir. It is the reverse of mount; after unmounting a CD‑ROM, the device can be ejected.
chsh – Purpose: change a user's login shell (all users). Syntax: chsh [-s] [-list] [--help] [-v] [username]. Key options: -l list available shells; -v show shell version. Example interaction shows changing from /bin/bash to /bin/tcsh.
exit – Purpose: exit the current shell (all users). Syntax: exit (no parameters).
last – Purpose: display recent login sessions (all users). Syntax:
last [‑n] [‑f file] [‑t tty] [‑h node] [‑i IP] [‑1] [‑y] [‑D] [‑x]. Key options: -n limit number of records; -f specify log file; -t filter by tty; -h filter by node; -i filter by IP; -1 show IP as remote address; -y show year/month/day; -D specify username; -x show system shutdown, login, and logout history.
file – Purpose: determine file type by examining contents (all users). Syntax: file [options] filename. Key options: -v version; -z check compressed files; -L follow symlinks; -f name read file list from name. Example: file grap reports grap: English text.
mkdir – Purpose: create directories (all users). Syntax: mkdir [options] directory. Key options: -m, --mode=MODE set permissions; -p, --parents create parent directories as needed; -v, --verbose report each created directory; --version show version.
grep – Purpose: search files for patterns (all users). Syntax: grep [options] pattern [file...]. Important options: -c count matching lines; -i ignore case; -h suppress filename in multi‑file output; -l list matching filenames; -n show line numbers; -s suppress error messages; -v invert match. Regex basics are explained (e.g., ^, $, , character classes, ., *).
dd – Purpose: copy and convert files (all users). Syntax: dd [options]. Key options: bs=BYTES, cbs=BYTES, conv=KEYWORDS, count=BLOCKS, ibs=BYTES, if=FILE, obs=BYTES, of=FILE, seek=BLOCKS, skip=BLOCKS. Typical use: creating boot disks, e.g., dd if=vmlinuz of=/dev/fd0.
find – Purpose: locate files in a directory hierarchy (all users). Syntax: find [path] [options] [expression]. Common options: -depth, -maxdepth LEVELS, -mindepth LEVELS, -mount, -version. Expressions: -name PATTERN, -atime N, -ctime N, -group GROUP, -user USER, -size N, -print. Examples: find / -name lilo.conf, find /etc -size +500000c -and -mtime +1.
mv – Purpose: move or rename files/directories (all users). Syntax: mv [options] source target. Key options: -i interactive (prompt before overwrite); -f force (no prompt).
ls – Purpose: list directory contents (all users). Syntax: ls [options] [file]. Important options: -a, --all show hidden files; -A, --almost‑all omit . and ..; -l long format; -F classify file types; -i show inode; -R recursive; -h human‑readable sizes; many others for sorting, formatting, and filtering.
diff – Purpose: compare two files and show differences (all users). Syntax: diff [options] file1 file2. Key options: -a treat all files as text; -b ignore whitespace changes; -B ignore blank lines; -c context output; -H heuristic search; -I ignore case; -n RCS format.
cmp – Purpose: compare two files byte by byte (all users). Syntax: cmp [options] file1 file2. Option: -l output differing byte positions in decimal and octal.
cat – Purpose: concatenate and display file contents (all users). Syntax: cat [options] file1 file2 …. Key options: -n number all output lines; -b number non‑blank lines only; -s squeeze multiple blank lines.
ln – Purpose: create hard or symbolic links (all users). Syntax: ln [options] source [linkname]. Options: -f remove existing destination; -d allow hard links to directories (admin only); -s create symbolic link; -b backup overwritten files. Explanation of hard links (inode sharing) and symbolic links (path reference).
Practical Exercises
1. Run multiple commands in one line using a semicolon, e.g., last -x; halt to view login history then shut down.
2. Mount Windows partitions with mount -t vfat /dev/hda1 /mnt/winc and display Chinese filenames using -o iocharset=cp936.
3. Mount a USB flash drive: mount /dev/sda1 /usb.
4. Create symbolic links for quick access, e.g., ln -s /usr/local/httpd/htdocs gg to reach web documents via gg.
5. Use dd to copy a floppy image: dd if=/dev/fd0 of=floppy.fd and load a ramdisk: dd if=root.ram of=/dev/ram0.
6. Use grep in pipelines and with find for advanced searches, e.g., ls -l | grep '^d' to list directories only.
Author: njqyu
Source: blog.51cto.com
《Linux云计算及运维架构师高薪实战班》2018年03月26日即将开课中, 120天冲击Linux运维年薪30万 ,改变速约~~~~
*声明:推送内容及图片来源于网络,部分内容会有所改动,版权归原作者所有,如来源信息有误或侵犯权益,请联系我们删除或授权事宜。
更多 Linux好文 请点击 【阅读原文】 哦
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.
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.
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.
