Linux sysadmin Cheat Sheet
by bugmenot via cheatography.com/19356/cs/8306/
SystemD service management Process management I/O redirection
systemctl status Shows the status of a watch -n Issue command every > Redirect STDOUT to a file.
name.service service. interval interval seconds and print
2> Redirect STDERR to a file.
'command' output.
systemctl Changes a service's &> Redirect all output to a file.
start|stop|restart|relo state (not reboot kill pid Kill process with ID pid.
persistent). 2>&1 Redirect all output to a pipe.
ad name.service
pkill name Kill process with name name.
Use >> to append rather than overwrite.
systemctl Restarts if the service
killall name Kill all processes with names
condrestart is already running.
beginning with name.
useradd/usermod options
name.service
systemctl list-units -- Displays the status of Crontab management -d, --home The user's home directory.
type=service all services. HOME_DIR
crontab -l List current entries in crontab.
systemctl list- Lists all services. -e, -- Date on which the user
crontab -r Remove current entries in
unit-files -- expiredate account will be disabled
crontab.
type=service EXPIRE_DAT (YYYY-MM-DD)
crontab - Edit existing entries in crontab.
E
systemctl Set whether or not a e
enable|disable service should start -G, --groups A list of supplementary groups
on boot. Cron syntax: <minute> <hour> <day of month> GROUP1[,G‐ which the user is also a
name.service
<month> <day of week> <command> ROUP2...] member
systemctl is-enabled Check if a service is
name.service configured to start on -m, -- useradd: Create the user's
File management
boot. create-home home directory if it doesn't
find dir - Find all files named string in dir. exist.
systemctl daemon- Reload systemctl after
name -m, --move- usermod: Move the content of
reload config changes.
string home the users home directory to
find dir - Find all files named string owned the new location.
SystemD system management
user by user in dir.
systemctl Powers off the system. Linux miscellaneous commands
user
poweroff
find dir - Find all files modified less than time timedatectl list- RHEL7 only: List
systemctl Restarts the system.
mmin minutes ago in dir. timezones available timezones.
reboot
time timedatectl set- RHEL7 only: Set
journalctl -f Tails the system message system timezone to
grep -i Search input for lines containing timezone time/zone
log. timezone.
string string (case-insensitive).
journalctl -u Shows logs for name.
ln -s Set system timezone
grep -C Search input for lines containing
name.service to timezone.
num string, and show num lines before /usr/share/zoneinfo/ti
journalctl Shows all messages related and after. me/zone
string
/path/to/execut to the specified executable. /etc/localtime
grep -v Search input for lines NOT
able
string containing string
grep -c Count input for number of lines
string containing string
By bugmenot Published 30th May, 2016. Sponsored by Readability-Score.com
cheatography.com/bugmenot/ Last updated 30th May, 2016. Measure your website readability!
Page 1 of 2. https://readability-score.com
Linux sysadmin Cheat Sheet
by bugmenot via cheatography.com/19356/cs/8306/
MySQL command-line options vim shortcuts
mysql -u user -p Connect to a :set Toggles line numbers.
password -h hostname database. nu[!]
[database] :%s/fo Find all occurrences of foo and
mysql -u user -p Run command o/bar/ replace them with bar.
password -h hostname against database g
[database] [-e and print output.
:s/foo/ Find occurrences of foo and replace
command] bar/ g them with bar in the current line only.
mysql -u user -p Import database
:%s/fo Find all occurrences of foo and
password -h hostname from file.sql. replace them with bar after asking for
o/bar/
database < file.sql confirmation.
gc
mysqldump -u user -p Dump database to
D Delete line.
password -h hostname file.sql.
numd Delete num lines below the cursor.
database > file.sql
d
MySQL database/table management gg Go to top of file.
G Go to end of file.
CREATE Creates database
DATABASE name; name. P Paste after cursor.
USE DATABASE Selects database O Insert line above cursor.
name; name.
o Insert line below cursor.
DROP DATABASE Drops database name. p Paste before cursor.
name;
V Visual lines mode.
SHOW TABLES; Shows all tables in the
v Visual selection mode.
selected database.
Y Yank line.
DESCRIBE table; Shows the fields in
table. y Yank selection.
SELECT * FROM Shows data from all
table; rows and columns in
table.
SELECT * FROM Shows data from all
table ORDER BY rows and columns in
column table in specified order.
[ASC|DESC];
By bugmenot Published 30th May, 2016. Sponsored by Readability-Score.com
cheatography.com/bugmenot/ Last updated 30th May, 2016. Measure your website readability!
Page 2 of 2. https://readability-score.com