You are on page 1of 2

Linux sysadmin Cheat Sheet

by bugmenot via cheatography.com/19356/cs/8306/

SystemD service management Process management I/O redire​ction

syst​emctl status Shows the status of a watch -n Issue command every > Redirect STDOUT to a file.
name.se​rvice service. interval interval seconds and print
2> Redirect STDERR to a file.
'comm​and' output.
syst​emctl Changes a service's &> Redirect all output to a file.
start|​sto​p|r​est​art​|relo state (not reboot kill pid Kill process with ID pid.
persis​tent). 2>&1 Redirect all output to a pipe.
ad name.se​rvice
pkill name Kill process with name name.
Use >> to append rather than overwrite.
syst​emctl Restarts if the service
killall name Kill all processes with names
condre​start is already running.
beginning with name.
userad​d/u​sermod options
name.se​rvice

syst​emctl list-units -- Displays the status of Crontab management -d, --home The user's home directory.

type​​=s​e​r​vice all services. HOME_DIR


crontab -l List current entries in crontab.
syst​emctl list- Lists all services. -e, -- Date on which the user
crontab -r Remove current entries in
u​​ni​t​-​files -- expi​​redate account will be disabled
crontab.
type​​=s​e​r​vice EXPIRE​​_D​AT (YYYY​​-MM​​-DD)
crontab - Edit existing entries in crontab.
E
syst​emctl Set whether or not a e
enable​|di​sable service should start -G, --groups A list of supple​​me​ntary groups
on boot. Cron syntax: <mi​nut​e> <ho​ur> <day of month> GROUP1​​[,​G​‐ which the user is also a
name.se​rvice
<mo​nth> <day of week> <co​mma​nd> R​OU​​P2...] member
syst​emctl is-enabled Check if a service is
name.se​rvice configured to start on -m, -- useradd: Create the user's
File management
boot. crea​​te​-​h​ome home directory if it doesn't
find dir - Find all files named string in dir. exist.
syst​emctl daemon​​- Reload systemctl after
name -m, --move​​- usermod: Move the content of
r​eload config changes.
string h​ome the users home directory to

find dir - Find all files named string owned the new location.
SystemD system management
user by user in dir.
syst​emctl Powers off the system. Linux miscel​laneous commands
user
poweroff
find dir - Find all files modified less than time time​datectl list- RHEL7 only: List
syst​emctl Restarts the system.
mmin minutes ago in dir. t​ime​zones available timezones.
reboot
time time​datectl set- RHEL7 only: Set
jour​nalctl -f Tails the system message system timezone to
grep -i Search input for lines containing ti​mezone time/​zone
log. timez​one.
string string (case-​ins​ens​itive).
jour​nalctl -u Shows logs for name.
ln -s Set system timezone
grep -C Search input for lines containing
name.se​rvice to timez​one.
num string, and show num lines before /usr/s​har​e/z​one​inf​o/​ti
jour​nalctl Shows all messages related and after. m​e/zone
string
/path​/to​/ex​ecu​t to the specified execut​able. /etc/l​oca​ltime
grep -v Search input for lines NOT
ab​le
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 comman​d-line options vim shortcuts

mysql -u user -p Connect to a :set Toggles line numbers.


password -h hostname database. nu[!]
[data​bas​e] :%s/​fo​ Find all occurr​ences of foo and
mysql -u user -p Run command o/​ba​r/ replace them with bar.
password -h hostname against database g
[data​base] [-e and print output.
:s/​foo/​ Find occurr​ences of foo and replace
comma​nd] bar/​ g them with bar in the current line only.
mysql -u user -p Import database
:%s/​fo​ Find all occurr​ences of foo and
password -h hostname from file.s​ql. replace them with bar after asking for
o/​ba​r/
database < file.s​ql confir​mation.
gc
mysq​ldump -u user -p Dump database to
D Delete line.
password -h hostname file.s​ql.
num​d Delete num lines below the cursor.
database > file.s​ql
d

MySQL databa​se/​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|D​ESC];

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

You might also like