๐Ÿ’ปAn open-source eBook with 101 Linux commands that everyone should know

Overview

๐Ÿ’ป ++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 โญ

๐Ÿ“™ Online eBook

An online copy โšก ๐ŸŒ of this ebook is available here ๐Ÿ“™ .

๐Ÿ”ฝ Download links


Content


Basics

File Hierarchy Standard (FHS)

Path Content
/bin Binaries (User)
/boot Static boot loader files
/etc Host specific configs
/lib Shared libraries and kernel modules
/sbin Binaries (System/root)
/var Varying files (e.g. Logs)
/usr 3rd party software
/proc Pseudo file system
/sys Pseudo file system
/mnt Mountpoint for internal drives
/media Mountpoint for external drives
/home User homes
/run PID files of running processes

Commands

File System Commands

Command Options Description
cd - Navigate to last dir
~ Navigate to home
~username Navigate to home of specified user
pwd Print working dir
ls Print dir content
-l Format as list
-a Show hidden items (-A without . and ..)
-r Invert order
-R Recurse
-S Sort by size
-t Sort by date modified
mkdir -p Create dir with parents
cp -r Copy dir
rmdir -p Remove dir and empty parents
rm -rf Remove dir recursively, -f without confirmation
mv Move recursively
find -iname pattern Search dir/file case-insensitive
-mmin n Last modified n minutes ago
-mtime n Last modified n days ago
-regex pattern Path matches pattern
-size n[kMG] By file size (-n less than; +n greater than)
! searchparams Invert search

File Manipulation

Command Options Description
cat file Print content
tac file Print content inverted
sort file Print sorted
file -r -u Print sorted descending without dublicates
head -n10 file Print lines 5-10
tail -f file Print new lines automatically
cut -f -4,7-10,12,15- file Print selected fields (tab delimited)
-c -4,7-10,12,15- file Print selected characters positions
-f 2,4 -d, --output-delimiter=$'\t' file Change delimiter (but use tab for output)
uniq file Hide consecutive identical lines
file -c Show consecutive identical line count
file -u Hide consecutive identical lines
file file Get file type
wc file Count Lines, Words, Chars (Bytes)

Archiving

Command Options Description
tar cfv archiv.tar file1 file2 Create archive / add or overwrite content
tfv archiv.tar Show content
xf archiv.tar [-C ~/extracted] Extract (and decompress) archive (to ~ / extracted)
cfvj archiv.tar.bz2 file Create bzip2 compressed archive
cfvz archiv.tar.gz file Create gzip compressed archive
cfa archiv.tar.[komp] file create compressed archive (auto type based on name)
bzip2 file1 file2 Dateien (einzeln) komprimieren
-d file1 file2 Compress files (one at a time)
gzip file1 file2 Dateien (einzeln) komprimieren
-d file1 file2 Decompress files

Disk and File System Management

General Disk Manipulation (non-LVM)

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

Command Options Description
fdisk -l List physical disks and partitions
/dev/sdb
n
Create new partition
/dev/sdb
t
8e
Change partition type to Linux LVM
mkfs.xfs /dev/myVG/myVol Format LV with XFS
mkfs.ext4 -f /dev/myVG/myVol Format LV with EXT4 (overwrite)
blkid /dev/myVG/myVol Show UUID and formatting of volume
mount Show current mounted file systems
-t ext4 /dev/myVG/myVol /mountpoint Mount LV to /mountpoint
-a Mount as configured in /etc/fstab
umount Unmount a file system
/dev/myVG/myVol Unmount LV from /mountpoint
/mountpoint Unmount LV from /mountpoint
df - Show disk usage
xfs_growfs /dev/myVG/myVol Resize xfs filesystem
resize2fs /dev/myVG/myVol Resize ext3/4 filesystem

Other

Command Options Description
--help Help of current command (not standardized)
-h
-?
man Manual page of command
-k keyword Search command by keyword (oder apropos)
alias Show aliases
name='befehl' Create alias

Globs (Wildcards)

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

Character Description
? 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

Character Description
. Any single character
[ac-e] 1 character in enum
[^ac-e] 1 character not in enum
^ Start of string
$ End of string
\d Digit
\D Not a digit
\s Whitespace
\S Not 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

Command Options Description
grep pattern file Extended Regex
-E pattern file Extended Regex
-v pattern file Invert match
-w pattern file Word match
-i pattern file Ignore case

Stream redirection

  • > overwrite
  • >> append
Character Description
> file or 1> file STDOUT to file
< file Datei to STDIN
2> file STDERR to file
2>&1 STDERR to same target as STDOUT
> file 2>&1 STDOUT and STDERR to file

Text Readers & Editors

Less

Command Description
q Quit
R Refresh content
F Auto scroll
g number Go to line
m lowercaseLetter Mark line
' lowercaseLetter Go to mark
/pattern Search forward
?pattern Search backward
n Next search result
N Last search result
ESC u Remove highlighting from search

VI

VI/VIM Editing

To leave editing mode press ESC.

Command Description
i insert before cursor
a insert after cursor
A insert at end of line
o new line below
O new line above
u undo
. repeat last command
yy copy line
5yy copy 5 lines
p paste below
P paste above
x delete character
5x delete 5 characters
dd delete line
5dd delete 5 lines
:10,20d delete lines 10-20
d0 delete to line begin
d$ delete to line end

Navigation

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

Command Description
5G go to line 5
H go to top of screen
M go to middle of screen
L go to end of screen
5w move over 7 words
5b move back 5 words

Other

Command Description
/foo search forward
?foo search backwards
n repeat search
:w save
:q close
:wq save and close
:q! close without saving
:!command run bash command
:r foo read file foo into this file

User and Group Management

UID

UID Type
<1000 system account
>1000 user account

User Database

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

username PW UID GID GECOS HOME SHELL
hfict x 1000 1000 /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.

groupname PW GID Users
wheel x 10 hfict,user2

Password Database

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

username PW Last PW change Minimum Maximum Warn Inactive Expire
hfict [hash] 17803 0 99999 7

PW:

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

Commands

Command Param Description
id username Show a user's ID and groups
who Show logged in users
last Show last logins
lastb Show last failed logins
sudo -u user command Execute command with user rights (default is root)
-i or su - Shell with root rights
su Shell as root (non-login shell)
- Shell as root (login shell)
- user Shell as user
useradd -u 2101 -g primarygroup -c comment username Create user (without -g, new group will be created)
usermod -G group1, group2 Define (overwrite) secondary groups
-ag group, group2 Add secondary groups
-l username Change username
-L Lock Account
-U Unlock Account
-s shellpath Change shell
userdel -r username Delete user including home and mail spool
passwd username Change password (interactive)
groupadd groupname Create group (optionally set GID with -g)
groupdel groupname Delete 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):

Char Binary Flag Permission
r 4 read
w 2 write
x 1 execute

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

Char Binary Flag Name Description
t / T 1 Sticky Bit Others can't delete content (only applicable for directories)
s / S 2 SGID-Bit File: run with permissions of Group
Dir: New elements inherit Group
s / S 4 SUID-Bit File 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

Command Options Description
chmod -R [uog] dirname Set permissions recursively using binary flags
+[suog] filename Add permissions using binary flags
-[suog] filename Remove permissions using binary flags
u+x filename Add execute permission for User
g+wx filename Add write and execute permissions for Group
o-r filename Remove read permission for Others
chown -R user:group filename Change owner (User & Group) recursively
user filename Change owner (User)
:group filename Change owner (Group)
chgroup group filename Change 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.

Config Option Description
PermitRootLogin no Deny root to login via SSH
yes Allow root to login via SSH
without-password Allow only with private/public key auth
AllowUsers user1 user2 Allow only user1 and user2
DenyUsers user1 user2 Allow all users but user1 and user2
AllowGroups group1 group2 Allow only users from specified groups
DenyGroups group1 group2 Allow 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
Command Description
rpm -q cronie Check if package is installed
systemctl status crond.service Check if service is running
crontab -l List current users crontab
crontab -e Edit current users crontab
crontab -e -u username Edit specific users crontab
crontab -r Remove 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

Command Description
rpm -i rpmfile|rpmurl Install package
rpm -e packagename Uninstall package
rpm -q packagename Check if package is installed
rpm -ql packagename List files in a package
rpm -qa List all installed packages
rpm -qf /path/to/file Get package that installed the file
rpm -qf $(which ) Get package that installed the executable
rpm -V packagename Validate 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

Command Description
yum install packagename [-y] Install package (-y no confirm message)
yum remove packagename Uninstall package
yum update Update all installed packages
yum update packagename Update specific package
yum update pattern* Update packages using wildcard
yum info packagename Get detailed info about package
yum list packagename List installed and available packages
yum search searchstring search for a package (name & summary)
yum search all searchstring search for a package (all infos)
yum deplist packagename List dependencies of a package
yum reinstall packagename Reinstall (corrupted) package
yumdownloader --resolve packagename Download 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
  • 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
  • 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
  • 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

  • crontab - maintain individual tables used to drive the cron daemon
  • df - display free disk space
  • du - display disk usage statistics
  • free - show memory usage information
  • hostname - set or print name of current host system
  • hostnamectl - change hostname settings
  • ionice - get/set I/O process priority
  • iostat - I/O statistics
  • kill - terminate or signal a process by id
  • killall - kill processes by name
  • lsblk - display block and loop devices
  • lsof - list open files
  • 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
  • top/htop - display process information
  • uname - prints operating system details
  • useradd - add/update user accounts
  • userdel - delete user account
  • usermod - modify user properties
  • vmstat - virtual memory statistics
  • whereis - locate programs

Networking Commands

  • dig - DNS lookup utility
  • ifconfig - configure network interface parameters
  • ip - perform network administration tasks
  • iptable - configure IPv4 network firewall
  • lscpu - display CPU architecture information
  • netstat - show network status
  • ping - check network connectivity
  • 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

  • clear - clear terminal screen
  • env - display environment variables, or set variables for command execution
  • exit - close the active session/shell
  • printenv - print specified environment variables
  • history - display the command history
  • login - login and initiate a user session
  • nohup - invoke a utility immune to hangups
  • sleep - suspend execution for a time interval
  • ssh - secure shell login
  • su - substitute user identity
  • sudo - execute a command as another user
  • screen - start a screen session

Getting Help

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

Applications

  • 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
  • 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

๐Ÿคฒ Contributing

If you are contributing ๐Ÿฟ please read the contributing file before submitting your pull requests.

Owner
Ashfaque Ahmed
I crunch data for breakfast, lunch, dinner and all the meals in between .
Ashfaque Ahmed
Second version of SQL-PYTHON-Practicas

SQLite-Python Acerca de | Autor Sobre el repositorio Segunda version de SQL-PYTHON-Practicas ๐Ÿ’ป Tecnologias Visual Studio Code Python SQLite3 ๐Ÿ“– Requi

1 Jan 06, 2022
Fully reproducible, Dockerized, step-by-step, tutorial on how to mock a "real-time" Kafka data stream from a timestamped csv file. Detailed blog post published on Towards Data Science.

time-series-kafka-demo Mock stream producer for time series data using Kafka. I walk through this tutorial and others here on GitHub and on my Medium

Maria Patterson 26 Nov 15, 2022
Python-samples - This project is to help someone need some practices when learning python language

Python-samples - This project is to help someone need some practices when learning python language

Gui Chen 0 Feb 14, 2022
Generate a backend and frontend stack using Python and json-ld, including interactive API documentation.

d4 - Base Project Generator Generate a backend and frontend stack using Python and json-ld, including interactive API documentation. d4? What is d4 fo

Markus Leist 3 May 03, 2022
Read write method - Read files in various types of formats

ไธ€ไธชๅ…ณไบŽๆ‰€ๆœ‰ๆ ผๅผๆ–‡ไปถ่ฏปๅ–็š„ๆ–นๆณ• 1ใ€‚ ้—ฎ้ข˜ๆ่ฟฐ๏ผš ๅ„็งๅ„ๆ ท็š„ๆ–‡ไปถๆ ผๅผ๏ผŒ่ฏปๅ†™ๆ“ไฝœ้žๅธธ็š„้บป็ƒฆ๏ผŒ่ƒฝๅคŸๆœ‰ไธ€็งๆ–นๆณ•๏ผŒๅฏไปฅๆ•ดๅˆๆ‰€ๆœ‰ๆ ผๅผ็š„ๆ–‡ไปถ๏ผŒๆ–นไพฟ็”จๆˆท่ฟ›่กŒ่ฏปๅ–ๅ’Œๅ†™ๅ…ฅใ€‚ 2

2 Jan 26, 2022
Leetcode Practice

LeetCode Practice Description This is my LeetCode Practice. Visit LeetCode Website for detailed question description. The code in this repository has

Leo Hsieh 75 Dec 27, 2022
A next-generation curated knowledge sharing platform for data scientists and other technical professions.

Knowledge Repo The Knowledge Repo project is focused on facilitating the sharing of knowledge between data scientists and other technical roles using

Airbnb 5.2k Dec 27, 2022
Easy OpenAPI specs and Swagger UI for your Flask API

Flasgger Easy Swagger UI for your Flask API Flasgger is a Flask extension to extract OpenAPI-Specification from all Flask views registered in your API

Flasgger 3.1k Dec 24, 2022
Toolchain for project structure and documents optimisation

ritocco Toolchain for project structure and documents optimisation

Harvey Wu 1 Jan 12, 2022
This program has been coded to allow the user to rename all the files in the entered folder.

Bulk_File_Renamer This program has been coded to allow the user to rename all the files in the entered folder. The only required package is "termcolor

1 Jan 06, 2022
Quilt is a self-organizing data hub for S3

Quilt is a self-organizing data hub Python Quick start, tutorials If you have Python and an S3 bucket, you're ready to create versioned datasets with

Quilt Data 1.2k Dec 30, 2022
Test utility for validating OpenAPI documentation

DRF OpenAPI Tester This is a test utility to validate DRF Test Responses against OpenAPI 2 and 3 schema. It has built-in support for: OpenAPI 2/3 yaml

snok 106 Jan 05, 2023
Fully typesafe, Rust-like Result and Option types for Python

safetywrap Fully typesafe, Rust-inspired wrapper types for Python values Summary This library provides two main wrappers: Result and Option. These typ

Matthew Planchard 32 Dec 25, 2022
NetBox plugin for BGP related objects documentation

Netbox BGP Plugin Netbox plugin for BGP related objects documentation. Compatibility This plugin in compatible with NetBox 2.10 and later. Installatio

Nikolay Yuzefovich 133 Dec 27, 2022
30 days of Python programming challenge is a step-by-step guide to learn the Python programming language in 30 days

30 days of Python programming challenge is a step-by-step guide to learn the Python programming language in 30 days. This challenge may take more than100 days, follow your own pace.

Asabeneh 17.7k Jan 07, 2023
An MkDocs plugin that simplifies configuring page titles and their order

MkDocs Awesome Pages Plugin An MkDocs plugin that simplifies configuring page titles and their order The awesome-pages plugin allows you to customize

Lukas Geiter 282 Dec 28, 2022
Python Advanced --- numpy, decorators, networking

Python Advanced --- numpy, decorators, networking (and more?) Hello everyone ๐Ÿ‘‹ This is the project repo for the "Python Advanced - ..." introductory

Andreas Poehlmann 2 Nov 05, 2021
Soccerdata - Efficiently scrape soccer data from various sources

SoccerData is a collection of wrappers over soccer data from Club Elo, ESPN, FBr

Pieter Robberechts 195 Jan 04, 2023
DeltaPy - Tabular Data Augmentation (by @firmai)

DeltaPyโ โ  โ€” Tabular Data Augmentation & Feature Engineering Finance Quant Machine Learning ML-Quant.com - Automated Research Repository Introduction T

Derek Snow 470 Dec 28, 2022
MonsterManualPlus - An advanced monster manual for Tower of the Sorcerer.

Monster Manual + This is an advanced monster manual for Tower of the Sorcerer mods. Users can get a plenty of extra imformation for decision making wh

Yifan Zhou 1 Jan 01, 2022