Star 历史趋势
数据来源: GitHub API · 生成自 Stargazers.cn
README.md

💻 ++101 Linux commands Open-source eBook

This is an open-source eBook with 101 Linux commands that everyone should know. No matter if you are a DevOps/SysOps engineer, developer, or just a Linux enthusiast, you will most likely have to use the terminal at some point in your career.

Make sure to star the repository

If you need a Linux virtual machine to test these commands on, use the following referral link to get a free $200 Credit For DigitalOcean!

Introduction to Linux eBook

If you are looking for a comprehensive guide for beginners, check out this eBook: Introduction to Linux eBook

📙 Online eBook

An online copy :zap:🌐 of this ebook is available here 📙.

🔽 Download links

📚 Multiple Formats Available

This eBook is now available in multiple formats to suit different reading preferences:

  • 📄 PDF (Light Theme): Download PDF - Perfect for printing and desktop reading
  • 🌙 PDF (Dark Theme): Download PDF - Ideal for dark mode readers
  • 📱 EPUB: Download EPUB - Compatible with e-readers, tablets, and mobile devices
  • 🌐 HTML: Download HTML - Single-page web version

🔄 Latest Releases

Visit our Releases page to download the latest versions or browse previous releases.

Star History

Star History Chart


Content


Basics

File Hierarchy Standard (FHS)

PathContent
/binBinaries (User)
/bootStatic boot loader files
/etcHost specific configs
/libShared libraries and kernel modules
/sbinBinaries (System/root)
/varVarying files (e.g. Logs)
/usr3rd party software
/procPseudo file system
/sysPseudo file system
/mntMountpoint for internal drives
/mediaMountpoint for external drives
/homeUser homes
/runPID files of running processes

Commands

File System Commands

CommandOptionsDescription
cd-Navigate to last dir
~Navigate to home
~usernameNavigate to home of specified user
pwdPrint working dir
lsPrint dir content
-lFormat as list
-aShow hidden items (-A without . and ..)
-rInvert order
-RRecurse
-SSort by size
-tSort by date modified
mkdir-pCreate dir with parents
cp-rCopy dir
rmdir-pRemove dir and empty parents
rm-rfRemove dir recursively, -f without confirmation
mvMove recursively
find-iname patternSearch dir/file case-insensitive
-mmin nLast modified n minutes ago
-mtime nLast modified n days ago
-regex patternPath matches pattern
-size n[kMG]By file size (-n less than; +n greater than)
! searchparamsInvert search

File Manipulation

CommandOptionsDescription
catfilePrint content
tacfilePrint content inverted
sortfilePrint sorted
file -r -uPrint sorted descending without dublicates
head-n10 filePrint lines 5-10
tail-f filePrint new lines automatically
cut-f -4,7-10,12,15- filePrint selected fields (tab delimited)
-c -4,7-10,12,15- filePrint selected characters positions
-f 2,4 -d, --output-delimiter=$'\t' fileChange delimiter (but use tab for output)
uniqfileHide consecutive identical lines
file -cShow consecutive identical line count
file -uHide consecutive identical lines
filefileGet file type
wcfileCount Lines, Words, Chars (Bytes)

Archiving

CommandOptionsDescription
tarcfv archiv.tar file1 file2Create archive / add or overwrite content
tfv archiv.tarShow content
xf archiv.tar [-C ~/extracted]Extract (and decompress) archive (to ~ / extracted)
cfvj archiv.tar.bz2 fileCreate bzip2 compressed archive
cfvz archiv.tar.gz fileCreate gzip compressed archive
cfa archiv.tar.[komp] filecreate compressed archive (auto type based on name)
bzip2file1 file2Dateien (einzeln) komprimieren
-d file1 file2Compress files (one at a time)
gzipfile1 file2Dateien (einzeln) komprimieren
-d file1 file2Decompress files

Disk and File System Management

General Disk Manipulation (non-LVM)

Creating physical partitions is not required! You can create PVs directly!

CommandOptionsDescription
fdisk-lList physical disks and partitions
/dev/sdb
n
Create new partition
/dev/sdb
t
8e
Change partition type to Linux LVM
mkfs.xfs/dev/myVG/myVolFormat LV with XFS
mkfs.ext4-f /dev/myVG/myVolFormat LV with EXT4 (overwrite)
blkid/dev/myVG/myVolShow UUID and formatting of volume
mountShow current mounted file systems
-t ext4 /dev/myVG/myVol /mountpointMount LV to /mountpoint
-aMount as configured in /etc/fstab
umountUnmount a file system
/dev/myVG/myVolUnmount LV from /mountpoint
/mountpointUnmount LV from /mountpoint
df-Show disk usage
xfs_growfs/dev/myVG/myVolResize xfs filesystem
resize2fs /dev/myVG/myVolResize ext3/4 filesystem

Other

CommandOptionsDescription
<command>--helpHelp of current command (not standardized)
-h
-?
man<command>Manual page of command
-k keywordSearch command by keyword (oder apropos)
aliasShow aliases
name='befehl'Create alias

Globs (Wildcards)

The dot . in front of hidden items is ignored by glob patterns!

CharacterDescription
?Any single character
*Any characters
[ac-e]1 character in enum
[!ac-e]1 character not in enum

Regex

Bash itself does not know regex. Use programs like grep, sed, awk.

Control characters

CharacterDescription
.Any single character
[ac-e]1 character in enum
[^ac-e]1 character not in enum
^Start of string
$End of string
\dDigit
\DNot a digit
\sWhitespace
\SNot a Whitespace
\<Start of word
\>End of word
pattern?Quantifier 0 or 1
pattern*Quantifier 0..n
pattern+Quantifier 1..n
pattern{x}Quantifier exactly x
pattern{x,}Quantifier x..n
pattern{x,y}Quantifier x..y
pattern{,y}Quantifier 0..y

Grep

CommandOptionsDescription
greppattern fileExtended Regex
-E pattern fileExtended Regex
-v pattern fileInvert match
-w pattern fileWord match
-i pattern fileIgnore case

Stream redirection

  • > overwrite
  • >> append
CharacterDescription
> file or 1> fileSTDOUT to file
< fileDatei to STDIN
2> fileSTDERR to file
2>&1STDERR to same target as STDOUT
> file 2>&1STDOUT and STDERR to file

Text Readers & Editors

Less

CommandDescription
qQuit
RRefresh content
FAuto scroll
g numberGo to line
m lowercaseLetterMark line
' lowercaseLetterGo to mark
/patternSearch forward
?patternSearch backward
nNext search result
NLast search result
ESC uRemove highlighting from search

VI

VI/VIM Editing

To leave editing mode press ESC.

CommandDescription
iinsert before cursor
ainsert after cursor
Ainsert at end of line
onew line below
Onew line above
uundo
.repeat last command
yycopy line
5yycopy 5 lines
ppaste below
Ppaste above
xdelete character
5xdelete 5 characters
dddelete line
5dddelete 5 lines
:10,20ddelete lines 10-20
d0delete to line begin
d$delete to line end

Navigation

Navigate as usual with arrow keys, home, end, pg up, pg dn.

CommandDescription
5Ggo to line 5
Hgo to top of screen
Mgo to middle of screen
Lgo to end of screen
5wmove over 7 words
5bmove back 5 words

Other

CommandDescription
/foosearch forward
?foosearch backwards
nrepeat search
:wsave
:qclose
:wqsave and close
:q!close without saving
:!commandrun bash command
:r fooread file foo into this file

User and Group Management

UID

UIDType
<1000system account
>1000user account

User Database

User info without passwords is stored in /etc/passwd.

usernamePWUIDGIDGECOSHOMESHELL
hfictx10001000/home/hfict/bin/bash

Group Database

Group info with secondary group members are stored in /etc/group. Primary group members are identified by GID in user database.

groupnamePWGIDUsers
wheelx10hfict,user2

Password Database

Hashed user passwords are stored in /etc/shadow. Password encryption is configured in /etc/login.defs.

usernamePWLast PW changeMinimumMaximumWarnInactiveExpire
hfict[hash]178030999997

PW:

  • [hash] Encrypted test password
  • ! [hash] Account locked
  • !! or * Account locked, no password set

Commands

CommandParamDescription
idusernameShow a user's ID and groups
whoShow logged in users
lastShow last logins
lastbShow last failed logins
sudo-u user commandExecute command with user rights (default is root)
-i or su -Shell with root rights
suShell as root (non-login shell)
-Shell as root (login shell)
- userShell as user
useradd-u 2101 -g primarygroup -c comment usernameCreate user (without -g, new group will be created)
usermod-G group1, group2Define (overwrite) secondary groups
-ag group, group2Add secondary groups
-l usernameChange username
-LLock Account
-UUnlock Account
-s shellpathChange shell
userdel-r usernameDelete user including home and mail spool
passwdusernameChange password (interactive)
groupaddgroupnameCreate group (optionally set GID with -g)
groupdelgroupnameDelete group

File System Permissions

Permissions can be set on:

  • User (owner)
  • Group (owner)
  • Others

Only root can change User. User can change Group.

Basic permissions (Add binary flags to combine):

CharBinary FlagPermission
r4read
w2write
x1execute

Advanced permissions (place in front of basic permissions: chmod 1777 shared).:

CharBinary FlagNameDescription
t / T1Sticky BitOthers can't delete content (only applicable for directories)
s / S2SGID-BitFile: run with permissions of Group
Dir: New elements inherit Group
s / S4SUID-BitFile is run with permissions of User (only applicable for files)

Advanced permissions replace the x when using ls -l. Lower case if x is set, upper case if x is not set.

Read permission on a directory only allows to see the directory itself but not it's contents. Use execute permission to show contents.

Commands

CommandOptionsDescription
chmod-R [uog] dirnameSet permissions recursively using binary flags
+[suog] filenameAdd permissions using binary flags
-[suog] filenameRemove permissions using binary flags
u+x filenameAdd execute permission for User
g+wx filenameAdd write and execute permissions for Group
o-r filenameRemove read permission for Others
chown-R user:group filenameChange owner (User & Group) recursively
user filenameChange owner (User)
:group filenameChange owner (Group)
chgroupgroup filenameChange owner (Group)

SSH

SSH Configuration is done in /etc/ssh/sshd_config.

Reload SSH service with systemctl reload sshd to apply changes!

DenyUsers, AllowUsers, DenyGroups, AllowGroups override each other and are applied in the order listed above.

ConfigOptionDescription
PermitRootLoginnoDeny root to login via SSH
yesAllow root to login via SSH
without-passwordAllow only with private/public key auth
AllowUsersuser1 user2Allow only user1 and user2
DenyUsersuser1 user2Allow all users but user1 and user2
AllowGroupsgroup1 group2Allow only users from specified groups
DenyGroupsgroup1 group2Allow all users but those in specified groups

Cronjobs

Crontab

Cronjobs are configured in crontab files. Do not edit these files directly. Use crontab -e instead. This runs all required actions to activate a cronjob after saving the edited crontab. The locations are as follows:

  • /var/spool/cron/username user specific
  • /etc/crontab system wide crontab

The format of the files is (user specific crontabs do not have the column user-name):

Example of job definition:
.---------------- minute (0 - 59 | */5 [every 5 minutes])
|  .------------- hour (0 - 23)
|  |  .---------- day of month (1 - 31)
|  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
|  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
|  |  |  |  |
*  *  *  *  * user-name  command to be executed
CommandDescription
rpm -q cronieCheck if package is installed
systemctl status crond.serviceCheck if service is running
crontab -lList current users crontab
crontab -eEdit current users crontab
crontab -e -u usernameEdit specific users crontab
crontab -rRemove current users crontab

Script folders

Scripts in one of the following directories will be executed at the interval specified by the directory's name:

  • /etc/cron.hourly
  • /etc/cron.daily
  • /etc/cron.weekly
  • /etc/cron.monthly

Allow / Deny usage

Add user names one per line to the following files:

  • /etc/cron.allow Whitelist
  • /etc/cron.deny Blacklist

If none of the files exists, all users are allowed.

Logs and Results

Execution of cronjobs is logged in /var/log/cron. Results are sent to the users mail /var/spool/mail/username.

Package Management

RPM

RPM

CommandDescription
rpm -i rpmfile|rpmurlInstall package
rpm -e packagenameUninstall package
rpm -q packagenameCheck if package is installed
rpm -ql packagenameList files in a package
rpm -qaList all installed packages
rpm -qf /path/to/fileGet package that installed the file
rpm -qf $(which <exe>)Get package that installed the executable
rpm -V packagenameValidate installed package

YUM

YUM is configured in /etc/yum.conf

Repos are configured in /etc/yum.repos.d/

Log is in /var/log/yum.log

CommandDescription
yum install packagename [-y]Install package (-y no confirm message)
yum remove packagenameUninstall package
yum updateUpdate all installed packages
yum update packagenameUpdate specific package
yum update pattern*Update packages using wildcard
yum info packagenameGet detailed info about package
yum list packagenameList installed and available packages
yum search searchstringsearch for a package (name & summary)
yum search all searchstringsearch for a package (all infos)
yum deplist packagenameList dependencies of a package
yum reinstall packagenameReinstall (corrupted) package
yumdownloader --resolve packagenameDownload rpm package with dependencies

📃 List of commands by category:

If you want to contribute, feel free to pick up a topic marked as TODO and submit a pull request 🙌

Feel free to add new topics in case that you don't find one that you like from the current list.


Directory Navigation

  • cd - change working directory
  • ls - list directory contents
  • dir - directory listing, columnar format
  • pwd - return working directory name
  • tree - list subdirectories in a tree structure

File Commands

  • cat/tac - concatenate and print files
  • column - format text into columns
  • diff/sdiff - compare files line by line
  • find - search for files
  • grep - file pattern matcher
  • head - display the first lines of a file
  • locate - find files and directories
  • stat - display file status
  • tail - display the last lines of a file
  • uniq - report or filter out repeated lines in a file

File and Directory Manipulation

  • awk - pattern-directed scanning and processing language
  • chmod - change permissions
  • chown - change file owner and group
  • cp - copy files and directories
  • cut - remove sections from files
  • ln - create links between files
  • mkdir - make a new directory
  • mv - move files and directories
  • nano - text editor
  • rm - delete files and directories
  • rmdir - remove directory
  • paste - merge corresponding or subsequent lines of file
  • rsync - remote copy files
  • scp - secure copy
  • basename - strips directory information and suffixes from file path
  • sed - text transformation tool
  • sort - arrange or merge lines of files
  • split - split a file into pieces
  • touch - change file access and modification times
  • vim - text editor

Package archive and compression tools

  • bzip2 - block-sorting file compressor
  • cpio - copy files to/from archives
  • gzip - compression tool
  • gunzip - decompression tool
  • tar - create, extract and manipulate archives
  • zip - package and compress files
  • unzip - list, test, extract compressed ZIP files

System commands

  • badblocks - search for bad blocks on storage devices
  • cfdisk - curses-based disk partitioning tool
  • crontab - maintain individual tables used to drive the cron daemon
  • df - display free disk space
  • dmidecode - retrieve hardware information from DMI table
  • dmesg - display kernel ring buffer messages
  • du - display disk usage statistics
  • free - show memory usage information
  • fsck - file system check and repair
  • hostname - set or print name of current host system
  • hostnamectl - change hostname settings
  • ionice - get/set I/O process priority
  • iostat - I/O statistics
  • journalctl - view systemd journal logs
  • kill - terminate or signal a process by id
  • killall - kill processes by name
  • lsb_release - display LSB and distribution information
  • lsblk - display block and loop devices
  • lsof - list open files
  • lspci - list PCI devices
  • mkfs - build file systems
  • mpstat - CPU statistics
  • ncdu - curses-based disk usage
  • ps - display process status
  • pstree - show processes in tree format
  • reboot - restart the system
  • service - run an init script
  • shutdown - close down the system at a specific time
  • systemctl - control systemd services
  • top/htop - display process information
  • tty - print terminal name
  • uname - prints operating system details
  • useradd - add/update user accounts
  • userdel - delete user account
  • usermod - modify user properties
  • vmstat - virtual memory statistics
  • watch - execute commands repeatedly
  • whereis - locate programs

Networking Commands

  • dig - DNS lookup utility
  • ifconfig - configure network interface parameters
  • ip - perform network administration tasks
  • iptables - configure netfilter firewall
  • lscpu - display CPU architecture information
  • netstat - show network status
  • nmcli - NetworkManager command line interface
  • ping - check network connectivity
  • traceroute - trace network path to destination
  • ufw - uncomplicated firewall
  • whois - information about Internet domain names and network numbers

Package Management

  • apt - Debian package management
  • rpm - RPM package manager (RedHat)
  • yum - package manager for RedHat Linux

User Information commands

For user modification, see useradd, userdel, usermod under System commands

  • groups - show group memberships
  • finger - shows information about users
  • last - displays most recent user logins
  • passwd - modify a user's password
  • w - display who is logged in and what they are doing
  • who - display who is logged in
  • whoami - display effective user id

Session commands

  • bg - put jobs in background
  • clear - clear terminal screen
  • env - display environment variables, or set variables for command execution
  • exit - close the active session/shell
  • export - set environment variables
  • fg - bring jobs to foreground
  • history - display the command history
  • jobs - display active jobs
  • login - login and initiate a user session
  • nohup - invoke a utility immune to hangups
  • printenv - print specified environment variables
  • screen - start a screen session
  • sleep - suspend execution for a time interval
  • ssh - secure shell login
  • su - substitute user identity
  • sudo - execute a command as another user
  • wall - message to all users

Getting Help

  • apropos - search manual page names and descriptions
  • man - format and display online manual pages
  • help - displays help about basic commands not covered by 'man'
  • whatis - display one-line command descriptions

Applications

  • !! - history expansion (repeat last command)
  • bc - basic calculator
  • cal - displays a calendar
  • cmatrix - enter the Matrix
  • curl - transfer data to or from a server
  • echo - display interpreted arguments
  • factor - prints prime factors of numbers
  • printf - format output
  • sl - runs a steam locomotive across your terminal
  • time - measure command execution time
  • wget - non-interactive web file download
  • xargs - construct argument lists and execute utility
  • yes - print continous output stream
  • banner - Writes ASCII character strings in large letters to standard output.
  • aplay - aplay is a command-line to play audio files.
  • spd-say - plays the given text as the sound from the command line.

📃 List of commands by chapter:

If you want to contribute, feel free to pick up a topic, update it with New Examples | [Options]and submit a pull request 🙌

Feel free to add new topics in case that you don't find one that you like from the current list.

🔗Links

📖Other eBooks

📚 eBook Generation

This project uses Ibis Next to generate eBooks in multiple formats:

Quick Start

  1. Install dependencies:
composer install
  1. Generate eBooks:
# Generate PDF (light theme)
composer run pdf

# Generate PDF (dark theme)
composer run pdf-dark

# Generate EPUB
composer run epub

# Generate HTML
composer run html

Available Formats

  • PDF: Available in both light and dark themes, perfect for printing or desktop reading
  • EPUB: Compatible with most e-readers, tablets, and mobile devices
  • HTML: Single-page HTML version, great for web viewing and sharing

All generated files are saved in the ebook/en/export/ directory.


🤲Contributing

If you are contributing 🍿 please read the contributing file before submitting your pull requests.

关于 About

101 Linux commands Open-source eBook and CLI tool
devopsebookhacktoberfestlinuxshell

语言 Languages

HTML98.8%
Python1.1%
CSS0.1%
PHP0.1%

提交活跃度 Commit Activity

代码提交热力图
过去 52 周的开发活跃度
158
Total Commits
峰值: 48次/周
Less
More

核心贡献者 Contributors