Show Menu

CentOS Cheat Sheet by

Performing basic tasks in CentOS
bash     linux     iptables     cron

I/O Redire­ction

>
Redirect STDOUT to a file
2>
Redirect STERR to a file
&>
Redirect all output to a file
2>&1
Redirect all output to a pipe
cmd1 | cmd2
Pipe STDOUT of cmd1 to cmd2
Use >> to append rather than overwrite

Scheduling with cron

#list current entries in crontab
crontab -l
#remove current entries in crontab
crontab -r
#edit existing entries in crontab
crontab -e
#format
<minute> <hour> <day of month> <month> <day of week> <command>

File Management

find / -name tofind
Find all files named tofind
find / -mmin 10
Find all files modified less than 10 minutes ago
grep -i STRING
Search input for lines containing STRING (nocase)
grep -C 2 STRING
Search input for lines containing STRING and showing 2 lines before and after
grep -v STRING
Search input for lines NOT containing STRING
grep -c STRING
Search input for number of lines containing STRING
 

Bash Shortcuts

CTRL-c
Kill current command
CTRL-a
Goto start of current line
CTRL-e
Goto end of current line
CTRL-r
Search history
!!
Repeat last command
^abc^def
Run previous command, replacing abc with def

Useful Snippets

#hostname
Displays FQDN of system
#uname -a
Displays current kernel version
#df -h
Display partit­ions, sizes details, and mount points
#chconfig --list
Displays all services and their status at each runlevel

File Paths

/var/named
Bind zone files
/etc/n­ame­d.conf
Bind config­uration file
/etc/h­ttp­d/c­onf­/ht­tpd.conf
Main apache config­uration file
/var/l­og/­httpd/
Default location for logs
/etc/hosts
System hosts file
/etc/r­eso­lv.conf
DNS lookup config­uration file
/etc/s­ysc­onf­ig/­network
Networ­k/h­ostname config­uration file
/etc/s­ysc­onf­ig/­net­wor­k-s­cripts/
Default location of a network setting file
 

Archiving

# compress (tar/gzip)
tar cvzf <file>.tgz <directory>
# extract (tar/gzip)
tar xvzf <file>.tgz
# compress (tar/bzip)
tar cvjf <file>.tbz <directory>
# extract (tar/bzip)
tar xvjf <file>.tbz
# extract (gzip)
gunzip <file>.gzip

Screen shortcuts

CTRL-a c
Create a new screen session
CTRL-a n
Goto the next screen session
CTRL-a p
Goto the previous screen session
CTRL-a "
Present a list of all sessions
CTRL-a d
Detach screen from terminal
CTRL-a k
Kill current session
screen -r to reattach to a detached session

iptables

#iptables -L
Displays ruleset of iptables
#iptables -I INPUT -p tcp -m tcp -s 192.16­8.1­5.2­54/26 --dport 22 -j ACCEPT
Accepts incoming SSH connec­tions from IP range 192.16­8.1­5.2­54/26
#iptables -I INPUT -s "­192.16­8.1­0.0­/24­" -j DROP
Drops all traffic from IP range 192.16­8.1­0.0/24
#iptables -A INPUT -p tcp --dport 25 -j DROP
Blocks all traffic to TCP port 25
#/etc/­ini­t.d­/ip­tables save
Saves all IPtables rules and re-applies them after a reboot

Download the CentOS Cheat Sheet

1 Page
//media.cheatography.com/storage/thumb/mrinflictor_centos.750.jpg

PDF (recommended)

Alternative Downloads

Share This Cheat Sheet!

 

Comments

Andreas Hinderberger Andreas Hinderberger, 15:30 14 Dec 14

Hi, thanks for the nice sheet, but you have a typo in there:
#chconfig --list
should be
#chkconfig --list

kashbrook kashbrook, 23:32 16 Jul 18

Thanks for making this cheat sheet.

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          Linux Command Line Cheat Sheet
          Bash/ZSH Shourtcuts Cheat Sheet
          bash Shortcuts Cheat Sheet