Show Menu

Linux sysadmin Cheat Sheet by

mysql     linux     usermod     useradd     vim     systemd

SystemD service management

syst­emctl status name.se­rvice
Shows the status of a service.
syst­emctl start|­sto­p|r­est­art­|reload name.se­rvice
Changes a service's state (not reboot persis­tent).
syst­emctl condre­start name.se­rvice
Restarts if the service is already running.
syst­emctl list-units --type­­=s­e­r­vice
Displays the status of all services.
syst­emctl list-u­­ni­t­-­files --type­­=s­e­r­vice
Lists all services.
syst­emctl enable­|di­sable name.se­rvice
Set whether or not a service should start on boot.
syst­emctl is-enabled name.se­rvice
Check if a service is configured to start on boot.
syst­emctl daemon­­-r­eload
Reload systemctl after config changes.

SystemD system management

syst­emctl poweroff
Powers off the system.
syst­emctl reboot
Restarts the system.
jour­nalctl -f
Tails the system message log.
jour­nalctl -u name.se­rvice
Shows logs for name.
jour­nalctl /path­/to­/ex­ecu­tab­le
Shows all messages related to the specified execut­able.

Process management

watch -n interval 'comm­and'
Issue command every interval seconds and print output.
kill pid
Kill process with ID pid.
pkill name
Kill process with name name.
killall name
Kill all processes with names beginning with name.

Crontab management

crontab -l
List current entries in crontab.
crontab -r
Remove current entries in crontab.
crontab -e
Edit existing entries in crontab.
Cron syntax: <mi­nut­e> <ho­ur> <day of month> <mo­nth> <day of week> <co­mma­nd>
 

File management

find dir -name string
Find all files named string in dir.
find dir -user user
Find all files named string owned by user in dir.
find dir -mmin time
Find all files modified less than time minutes ago in dir.
grep -i string
Search input for lines containing string (case-­ins­ens­itive).
grep -C num string
Search input for lines containing string, and show num lines before and after.
grep -v string
Search input for lines NOT containing string
grep -c string
Count input for number of lines containing string

I/O redire­ction

>
Redirect STDOUT to a file.
2>
Redirect STDERR to a file.
&>
Redirect all output to a file.
2>&1
Redirect all output to a pipe.
Use >> to append rather than overwrite.

userad­d/u­sermod options

-d, --home HOME_DIR
The user's home directory.
-e, --expi­­redate EXPIRE­­_D­ATE
Date on which the user account will be disabled (YYYY­­-MM­­-DD)
-G, --groups GROUP1­­[,­G­R­OU­­P2...]
A list of supple­­me­ntary groups which the user is also a member
-m, --crea­­te­-­h­ome
useradd: Create the user's home directory if it doesn't exist.
-m, --move­­-h­ome
usermod: Move the content of the users home directory to the new location.

Linux miscel­laneous commands

time­datectl list-t­ime­zones
RHEL7 only: List available timezones.
time­datectl set-ti­mezone time/­zone
RHEL7 only: Set system timezone to timez­one.
ln -s /usr/s­har­e/z­one­inf­o/­tim­e/zone /etc/l­oca­ltime
Set system timezone to timez­one.
 

MySQL comman­d-line options

mysql -u user -p password -h hostname [data­bas­e]
Connect to a database.
mysql -u user -p password -h hostname [data­base] [-e comma­nd]
Run command against database and print output.
mysql -u user -p password -h hostname database < file.s­ql
Import database from file.s­ql.
mysq­ldump -u user -p password -h hostname database > file.s­ql
Dump database to file.s­ql.

MySQL databa­se/­table management

CREATE DATABASE name;
Creates database name.
USE DATABASE name;
Selects database name.
DROP DATABASE name;
Drops database name.
SHOW TABLES;
Shows all tables in the selected database.
DESCRIBE table;
Shows the fields in table.
SELECT * FROM table;
Shows data from all rows and columns in table.
SELECT * FROM table ORDER BY column [ASC|D­ESC];
Shows data from all rows and columns in table in specified order.

vim shortcuts

:set nu[!]
Toggles line numbers.
:%s/­fo­oba­r/g
Find all occurr­ences of foo and replace them with bar.
:s/­foo­/­bar­/g
Find occurr­ences of foo and replace them with bar in the current line only.
:%s/­fo­oba­r/gc
Find all occurr­ences of foo and replace them with bar after asking for confir­mation.
D
Delete line.
num­dd
Delete num lines below the cursor.
gg
Go to top of file.
G
Go to end of file.
P
Paste after cursor.
O
Insert line above cursor.
o
Insert line below cursor.
p
Paste before cursor.
V
Visual lines mode.
v
Visual selection mode.
Y
Yank line.
y
Yank selection.

Download the Linux sysadmin Cheat Sheet

2 Pages
//media.cheatography.com/storage/thumb/bugmenot_linux-sysadmin.750.jpg

PDF (recommended)

Alternative Downloads

Share This Cheat Sheet!

 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          VI Editor Cheat Sheet
          Vim NERDTree Cheat Sheet
          *nix users and groups Cheat Sheet

          More Cheat Sheets by bugmenot