Linux Commands Cheat Sheet from cmdref.net

#System Commands
http://cmdref.net/os/linux/command/#system_commands
##System Commands

|Command | Description |Example |
|:-------|:------------|:-------|
| shutdown  | bring the system down                           | shutdown -h now <- -h = Halt or poweroff after shutdown<br> shutdown -r now <- -r : Reboot after shutdown<br> shutdown -r -F now <- -F : Force fsck after reboot.  |
| halt      | stop the system.                                | halt                                                                                                                                                           |
| reboot    | reboot the system.                              | reboot                                                                                                                                                         |
| init      |                                                 | init 1 #change to single usermode                                                                                                                              |
| uptime    | Tell how long the system has been running.      | uptime                                                                                                                                                         |
| runlevel  | find the previous and current system runlevel.  | runlevel                                                                                                                                                       |
| printenv  | print all or part of environment                | printenv                                                                                                                                                       |
| env       | run a program in a modified environment         | env                                                                                                                                                            |
| hostname  | show or set the system's host name              | hostname <- show the system's host name <br> hostname NEWHOSTNASME <- set the system's host name                                                                 |
| uname     | print system information                        | uname -a <- print all information                                                                                                                              |
| locale    | Get locale-specific information.                | locale <br> locale -a &#124;grep -i ja  <- -a : --all-locales                                                                                                 |




##Process Management

|Command | Description |Example |
|:-------|:------------|:-------|
| ps            | report a snapshot of the current processes.                | ps aux &#124;grep httpd <- Check httpd rocess <br> ps aux &#124; grep XXX &#124; awk '{print $2}' &#124; xargs kill -9<br> ps auxwf &#124;grep XXX  |
| pgrep      | look up  processes based on name and other attributes      | pgrep -f 'bash' <br> pgrep -lf 'bash'  <- output with process name  <br> pgrep -f 'bash' &#124; xargs kill                              |
| pstree                        | display a tree of processes                                | pstree -a                                                                                                                      |
| pidof                         | find the process ID of a running program                   | pidof httpd <br> /bin/kill $(/sbin/pidof qmail-popup)                                                                                |
| kill                          | send a signal to a process                                 | kill -9 PID <- (-9 or -KILL = force-quit)                                                                                          |
| pkill                         | signal processes based on name and other attributes        | pkill -f 'bash' <br> pkill -u user1 <br> pkill java <br> pkill -f jar                                                                    |
| killall                       | kill processes by name                                     | killall vi<br> killall -i vi  <- -i =  Interactively<br> killall -HUP kterm                                                            |
| killproc                      |                                                            |                                                                                                                                    |
| lsof        | list open files                                            | lsof -i :80,443 <- Which process is using Port 80,443                                                                              |
| Ctrl + C                      | Stop running process                                       |                                                                                                                                    |
| Ctrl + Z  | Suspend running process                                    | **Move Running Process to Background** <br> 1. ctrl + z <br> 2. jobs <br> 3. bg <br> 4. disown %JOBID                                      |
| jobs                          | The first form lists the active jobs.                      | jobs -l <- List job                                                                                                                |
| fg                            | Resume jobspec in the foreground                           |                                                                                                                                    |
| bg                            | Resume  each suspended job jobspec in the background       |                                                                                                                                    |
| nohup                         | run a command immune to hangups, with output to a non-tty  | nohup command.sh &                                                                                                                 |
| disown                        |                                                            | disown %jobid                                                                                                                      |
| nice        | run a program with modified scheduling priority            | nice -n 19 test.sh  <br> nice -n 19 ionice -c 3 CMD<br> nice -n 19 ionice -c 2 -n 7 COMMAND                                            |
| renice    | alter priority of running processes                        | renice 19 -p PID <br> you can check the nice whith "top" or "ps alx".                                                                |
| ionice    | sets or gets process io scheduling class and priority      | ionice -p PID <- check<br> ionice -c 3 -p PID <br> nice -n 19 ionice -c 2 -n 7 COMMAND                                                 |


##Schedule
|Command | Description |Example |
|:-------|:------------|:-------|
| crontab             | maintain crontab files                                     | crontab -l <- -l = list user's crontab<br> crontab -u USER -l<br> crontab -e <- -e = edit user's crontab<br> crontab -u USER -e                                                 |
| at  | queue jobs for later execution                             | echo "/sbin/shutdown -h now" &#124;at 21:00 02/30/2009 <br> at -t 200902302100                                                                                               |
| atq                 | lists  the  user's pending jobs                            | atq                                                                                                                                                                       |
| atrm                | delete jobs for later execution                            | atrm JOBID                                                                                                                                                                |
| watch               | execute a program periodically, showing output fullscreen  | watch ntpq -p <- By default, the program is run every 2 seconds <br> watch -n 5 ntpq -p <- 5 seconds interval <br> -d : highlight the differences between successive updates  |

##etc
|Command | Description |Example |
|:-------|:------------|:-------|
| alias                         | Alias with no arguments or with the -p option prints the list of aliases<br> When arguments are supplied, an  alias  is defined  for  each  name whose value is given.  | alias <- check all alias <br> alias ls='ls -la --color=auto' <br> alias grep='grep --color'                                                                                                                  |
| unalias                       | Remove each name from the list of defined aliases.<br> If -a is supplied, all alias definitions are removed.                                                            | unalias COMMAND                                                                                                                                                                                                  |
| ntpdate                       | set the date and time via NTP                                                                                                                                         | ntpdate -b -u IP<br> -b : Force  the  time (step mode)<br> -u : If you are running ntpd, "-u" must be added.                                                                                                         |
| ntpq                          | standard NTP query program                                                                                                                                            | ntpq -p <br> -p : Print a list of the peers known to the server  <br> watch -n 1 ntpq -p                                                                                                                             |
| hwclock                       | query and set the hardware clock (RTC)                                                                                                                                | hwclock (-r) <- Read the Hardware Clock and print the time on standard output.<br> hwclock -w <- Set the Hardware Clock to the current System Time.<br> hwclock -s <-  Set the System Time from the Hardware Clock.  |
| man                           | an interface to the on-line reference manuals                                                                                                                         | man COMMAND                                                                                                                                                                                                      |
| whatis                        | display manual page descriptions                                                                                                                                      | whatis KEYWORD<br> whatis cat<br> whatis vi                                                                                                                                                                          |
| history  | GNU History Library                                                                                                                                                   | history 5 <- lists only the last 5 lines.<br> HISTSIZE=1000<br> HISTTIMEFORMAT="%Y/%m/%d %H:%M:%S "                                                                                                                  |
| which                         | locate a command                                                                                                                                                      | which ls                                                                                                                                                                                                         |
| time                          | time a simple command or give resource usage                                                                                                                          | time sleep 5                                                                                                                                                                                                     |
| strace    | trace system calls and signals                                                                                                                                        | strace -t -o test.txt php test.php <br> <- (-t : each line of the trace with the time of day.)                                                                                                                     |
| ltrace                        | A library call tracer                                                                                                                                                 | lltrace -o test.txt wget http://example.com/<br> ltrace -p PID<br> ltrace -p 3365                                                                                                                                    |
| script    | make typescript of terminal session                                                                                                                                   | script -afq $LOG                                                                                                                                                                                                 |


<br>
# Files and Directories Commands
http://cmdref.net/os/linux/command/index.html#files_and_directories_commands

##File Commands
|Command | Description |Example |
|:-------|:------------|:-------|
| ls                      | list directory contents                             | ls -ltrh <- (-r : reverse order while sorting) <br> -h : with -l, print sizes in human readable format                               |
| cp                      | copy files and directories                          | cp -p SRC DES <br> cp -pr SRC/ DES/ <- (-r,-R : copy directories recursively) <br> cp -p SRC DES <- (-f, --force)                  |
| mv                      | move (rename) files                                 | mv file1 file2<br> mv dir1 dir2<br> mv file1 file2 file3 DIR                                                                           |
| rename                  | renames multiple files                              | rename .htm .html *.htm   <- frm .htm to .html<br> rename "" test *.txt      <- add test<br> rename test "" *.txt      <- delete test  |
| rm                      | remove files or directories                         | rm -rf TARGET <- (-r,-R : remove directories)                                                                                      |
| touch                   | change file timestamps                              | touch file1<br> touch -d "2017/10/20 13:00:00" file1                                                                                 |
| ln                      | make links between files                            | ln -s SRC DES                                                                                                                      |
| unlink                  |                                                     | unlink DES                                                                                                                         |
| wc                      | print newline, word, and byte counts for each file  | wc -l <- (-l, --lines = print the line counts)                                                                                     |
| tree  | list contents of directories in a tree-like format  | tree -Dpuga /etc                                                                                                                   |
| col                     | filter reverse line feeds from input                | man ifconfig | col -bfx > test.txt                                                                                             |



## Directory Commands
|Command | Description |Example |
|:-------|:------------|:-------|
| pwd    | print name of current/working directory                                                                        | pwd                                                                                                                                                                     |
| cd     | Change  the  current directory                                                                                 | cd  <- go to home directory<br> cd ~/ <- go to home directory<br> cd .. <- go to parent directory                                                                           |
| pushd  | Adds a directory to the top of the directory stack                                                             | pushd /var/log<br> pushd `pwd`<br> pushd +2  <- check pushd directory with ''dirs -v'' and go to No.2<br> pushd +3  <- check pushd directory with ''dirs -v'' and go to No.3  |
| popd   | Removes entries from the directory stack.                                                                      | popd                                                                                                                                                                    |
| dirs   | displays the list of currently remembered directories.                                                         | dirs -v                                                                                                                                                                 |
| mkdir  | make directories                                                                                               | mkdir -p /tmp/test1/test2/ <- make parent directories as needed  <br> mkdir -m 700 /home/user01/.ssh                                                                      |
| rmdir  | remove empty directories <br> If you want to delete directory, you must use "rm -r DIR".  | rmdir DIR                                                                                                                                                               |



##Commands to Access File Contents
|Command | Description |Example |
|:-------|:------------|:-------|
| more                      | file perusal filter for crt viewing                 |                                                                                                                                      |
| less                      | opposite of more                                    | crontab -l |less                                                                                                                 |
| view                      | Start in read-only mode.                            |                                                                                                                                      |
| cat                       | concatenate files and print on the standard output  | cat /dev/null > access.log                                                                                                           |
| tail                      | output the last part of files                       | tail -n 50 aaa.txt <- output the last N lines                                                                                        |
| head    | output the first part of files                      | head -n 100 aaa.txt  # -n , --lines) <br> head * |more <- View the beginning of the file in the directory.                     |
| diff    | compare files line by line                          | diff --suppress-common-lines --side-by-side File1 File2 <br> diff -r dir1 dir2 <- When comparing directories, recursively compare  |
| sdiff  | side-by-side merge of file differences              | sdiff -s File1 File2 <- (-s : Do not print common lines.)                                                                            |
| colordiff                 |                                                     |                                                                                                                                      |
| vimdiff                   |                                                     | vimdiff file1 file2 <br> vim -d file1 file2                                                                                            |




##Searching
|Command | Description |Example |
|:-------|:------------|:-------|
| grep          | print lines matching a pattern             | grep -Ev "^#&#124;^\$" xxx.txt  <br> grep -Ev "^$&#124;^#&#124;^\s*#"  file.txt <br> grep "" ifcfg-eth* <- check filename and contents<br> grep -r PATTERN  --include="*.txt" DIRECTORY <- -r : recursive  |
| egrep                           | egrep is the same as grep -E               | egrep "aaa&#124;bbb" file                                                                                                                                                                                 |
| find , xargs  | search for files in a directory hierarchy  | find . -name "*txt*"<br> find /dir -type f -name "*.log*" -mtime +7 -exec rm -rf {} \; <br> <-  "-mtime +7" is 7 days ago                                                                        |




##File Compression
|Command | Description |Example |
|:-------|:------------|:-------|
| tar  | The GNU version of the tar archiving utility  <br> tar warn the order of target and destination.  | tar -zcvf test.tar.gz Dir   <- Create, Verbose, File<br> tar -ztvf test.tar.gz   <- Test, Verbose, File<br> tar -zxvf test.tar.gz   <- eXtract, Verbose, File<br> tar -jcvf test.tar.bz2 DIR   <- Create, Verbose, File<br> tar -jxvf test.tar.bz2  |
| gzip, gunzip          | compress or expand files                                                                                               | gzip file1<br> gunzip file1.gz<br> gzip access_log.2011-[0][5-8]*.txt <-wild card                                                                                                                                                               |
| compress, uncompress  | package and compress (archive) files                                                                                   | compress file1<br> uncompress file1.Z                                                                                                                                                                                                         |
| bzip2 bunzip2 bz2cat  | a block-sorting file compressor                                                                                        | bzip2 file1<br> bunzip2 file1.gz2<br> bz2cat file1.gz2                                                                                                                                                                                          |
| zip/unzip             | package and compress (archive) files                                                                                   | zip file.zip file1 file2<br> zip -l file.zip   <- -l = list for check<br> unzip file.zip<br> unzip -t file.zip <- -t = test                                                                                                                       |
| lha                   |                                                                                                                        | lha a file.lzh file1 file2<br> lha t file.lzh<br> lha x file.lzh                                                                                                                                                                                |
| gzcat                 |                                                                                                                        | gzcat file.gz<br> gzcat file.Z                                                                                                                                                                                                                |
| zcat                  |                                                                                                                        | zcat file.Z                                                                                                                                                                                                                                 |
| zless                 | file perusal filter for crt viewing of compressed text                                                                 | zless file.gz                                                                                                                                                                                                                               |
| zgrep                 | search possibly compressed files for a regular expression                                                              | zgrep PATTERN file.gz                                                                                                                                                                                                                       |
| zegrep                | search possibly compressed files for a regular expression                                                              | zegrep  "new" test.txt.gz                                                                                                                                                                                                                   |
| zdiff                 | compare compressed files                                                                                               | zdiff file1.gz file2.gz                                                                                                                                                                                                                     |

##Character
|Command | Description |Example |
|:-------|:------------|:-------|
| lv                    | a Powerful Multilingual File Viewer / Grep                    |   |
| qkc                   |                                                               |   |
| nkf  | Network Kanji Filter                                          |   |
| iconv                 | Convert encoding of given files from one encoding to another  |   |



<br>
# User Administration
http://cmdref.net/os/linux/command/#user_administration

##User
|Command | Description |Example |
|:-------|:------------|:-------|
| useradd        | create a new user or update default new user information        | useradd -u UID -g GROUP -G GROUP1,GROUP2 -s /bin/bash -d HOME_DIR LOGIN                                                                                                       |
| whoami                              | print effective userid                                          | whoami                                                                                                                                                                        |
| w                                   | Show who is logged on and what they are doing.                  | w                                                                                                                                                                             |
| who                                 | show who is logged on                                           | who<br> who --all                                                                                                                                                           |
| userdel                             | delete a user account and related files                         | userdel -r USER <br> <- (-r, --remove : Files in the user's home directory will be removed)                                                                                 |
| vipw                                | edit the password, group, shadow-password or shadow-group file  | vipw    <- edit /etc/passwd<br> vipw -s   <- edit /etc/shadow                                                                                                                   |
| passwd          | change user password                                            | echo "password01" &#124; passwd --stdin user01<br> passwd -S user1 <- check about the status of the password  <br> passwd -l user01 <- Lock the user<br> passwd -u user01 <- Unlock  |
| chpasswd      | update passwords in batch mode                                  | echo user01:password &#124; chpasswd<br> echo 'USER:PASS' > tmp.txt ; chpasswd < tmp.txt ; rm -f tmp.txt                                                                         |
| mkpasswd                            |                                                                 |                                                                                                                                                                               |
| chage                               | change user password expiry information                         | chage -l USER <- check <br> chage -M 90 USER <- the password expires day set 90days                                                                                             |
| usermod                             | modify a user account                                           | usermod -g GROUP USER <br> usermod -G SUBGROUP USER <br> usermod -G SUBGROUP1,SUBGROUP2 USER <br> usermod -G "" USER                                                            |
| chsh                                | change login shell                                              | chsh -l  <- = cat /etc/shells<br> chsh -s /bin/bash   <- changing shell<br> chsh -s /bin/bash user01                                                                              |
| getent                              | get entries from Name Service Switch libraries                  | getent passwd  <- you can check LDAP Users <br> getent group <br> getent shadow                                                                                                   |
| pam_tally2  | The login counter (tallying) module                             | pam_tally2 -u USER <- check <br> pam_tally2 -u USER --reset <- reset                                                                                                        |



##Group
|Command | Description |Example |
|:-------|:------------|:-------|
| groups   | print the groups a user is in   |groups <br> groups USERNAME   |
| groupadd | create a new group   |groupadd -g GID GROUP <br> groupadd -g 1100 dev   |
| groupdel | delete a group   |   |
| vigr     | edit the password, group, shadow-password or shadow-group file | |

##File Permissions
|Command | Description |Example |
|:-------|:------------|:-------|
| chmod    | change file mode bits   | chmod 777 TARGET  <br> chmod u+s PROGRAM ← add SSUID（Set User ID） |
| chown    | change file owner and group   | chown -R TARGET <- -R : operate on files and directories recursively  |

##Etc
|Command | Description |Example |
|:-------|:------------|:-------|
| finger   | user information lookup program   |   |
| su       | change user ID or become superuser   | su - <- change root user <br> sudo su - USER -s /bin/bash <br> su - user1 -c "ssh user1@192.168.0.xx ls -lh /tmp" >> aaa.txt     |
| sudo     | execute a command as another user   | sudo -u USER COMMAND <br> sudo sh -c 'echo "test" >> /tmp/test.txt'   |
| id       | print real and effective user and group IDs   | id USERNAME  |
| last     | show listing of last logged in users   | last <br> last -5 <- last 5 logged in users |
| lastlog  | reports the most recent login of all users or of a given user   | lastlog  |
| umask    | set file mode creation mask   |   |



<br>
http://cmdref.net/os/linux/command/index.html#Network

# Network 
##Network
|Command | Description |Example |
|:-------|:------------|:-------|
| ip              | show / manipulate routing, devices, policy routing and tunnels  | ip a <- print ip address <br> ip addr <- print ip address <br> ip r <- Show IP Routing<br> ip route <- Show IP Routing                                        |
| ss               | another utility to investigate sockets                          | ss -lt <- TCP Listening Port <br> ss -ltp <- Process Name with Listening TCP  <br> ss -anu                                                                  |
| ifconfig                        | configure a network interface                                   | ifconfig <- check ip <br> ifconfig -a  <- -a : display all interfaces<br> ifconfig eth0 up<br> ifconfig eth0 down                                             |
| ifdown                          | take a network interface down                                   | ifdown eth0 <br> ifdown eth0 && ifup eth0                                                                                                             |
| ifup                            | bring a network interface up                                    | ifup eth0  <br> ifdown eth0 && ifup eth0                                                                                                              |
| route        | show / manipulate the IP routing table                          | route <- show the IP routing table <br> route add -net 192.168.10.0 netmask 255.255.255.0 gw 10.50.0.1 <br> route add -host 192.168.0.100 gw 192.168.1.100  |
| traceroute                      | print the route packets trace to network host                   |                                                                                                                                                         |
| tracepath                       | traces path to a network host discovering MTU along this path   |                                                                                                                                                         |
| ethtool    | Display or change ethernet card settings                        | ethtool eth0                                                                                                                                            |
| mii-tool  | view, manipulate media-independent interface status             | mii-tool eth0 <br> mii-tool -vv eth0                                                                                                                      |
| arp            | manipulate the system ARP cache                                 | arp -a <- (-a : Shows the entries of the specified hosts.) <br> arp -d 192.168.xx.xx <- delete arp                                                        |
| nmcli        | line tool for controlling NetworkManager                        |                                                                                                                                                         |

##DNS
|Command | Description |Example |
|:-------|:------------|:-------|
| dig            | DNS lookup utility                         | dig @8.8.8.8 google.com any<br> dig @8.8.8.8 -x 74.125.235.101<br> dig google.com mx<br> dig +trace google.com<br> dig +trace -x 173.252.120.6  |
| nslookup  | query Internet name servers interactively  | nslookup -type=any google.com 8.8.8.8                                                                                                   |
| host          | DNS lookup utility                         | host -t any google.com 8.8.8.8                                                                                                          |
| whois        | client for the whois service               | whois google.com                                                                                                                        |
| nscd                            | name service cache daemon                  | nscd -i hosts <- chache clear                                                                                                           |

##Connection
|Command | Description |Example |
|:-------|:------------|:-------|
| telnet                                            | user interface to the TELNET protocol                                                                                                                                                                                                                                                                                                                                                                                                                                                             | telnet IP PORT                                                                                                                           |
| ssh       | OpenSSH SSH client (remote login program)                                                                                                                                                                                                                                                                                                                                                                                                                                                         | ssh USER@IP <br> ssh xx.xx.xx.xx "hostname; netstat -rn  &#124;grep 10.110.0"<br> ssh xx.xx.xx.xx sudo /sbin/reboot                       |
| scp                                                  | secure copy (remote file copy program)  <br> scp is changed the file's time stamp and the link file copyed as the real file.                                                                                                                                                                                                                                                                                                                                                 | scp -r /home/user1 user1@192.168.0.10:/home                                                                                              |
| rsync   | a fast, versatile, remote (and local) file-copying tool   <br> rcync remain file's time stamp and the link file copyed as the link file.   <br> <br> rsync -avz --delete /home/user1**<color red>/</color>** /tmp/user1.bk/ <br> <- <color red>rsync "/" is very important.</color> <br> rsync -e ssh -avz --delete /home/user1/ user2@192.168.0.2:/home/backup/server1/home/user1/<br> rsync -e ssh -avz –-bwlimit=1250 FILE  user@192.168.0.2:/DIR/   # 1Mbps = 125KBps                                                                                                                                            ||
| ssh-keygen                                                            | authentication key generation, management and conversion                                                                                                                                                                                                                                                                                                                                                                                                                                          | ssh-keygen -t rsa  <- generate rsa key pair <br> ssh-keygen -R HOST <br> <- Removes all keys belonging to hostname from a known_hosts file.  |




##Check
|Command | Description |Example |
|:-------|:------------|:-------|
| ping                              | send ICMP ECHO_REQUEST to network hosts               | ping -c 5 -s 1500 192.168.0.1 ?<br> ping -i 0.1 192.168.0.1  # -i : interval  |
| nmap                                | Network exploration tool and security / port scanner  | nmap -p 443 www.google.com                                                      |
| nping                                                 |                                                       | nping --tcp -p PORT HOST                                                            |
| httping                          | measure the latency and throughput of a webserver     |                                                                                     |
| http_ping                                             |                                                       |                                                                                     |
| hping , hping3                                        |                                                       |                                                                                     |
| fping                                                 |                                                       | fping -g 192.168.0.0/24                                                             |
| netcat  |                                                       | nc -v -z 192.168.0.10 80 <- portscan <br> nc -v -z 192.168.0.10 1-1023 <- portscan    |

##HTTP
|Command | Description |Example |
|:-------|:------------|:-------|
| curl  | transfer a URL                           | curl -O http://example.com/images/test.jpg <br> curl -I http://www.example.com/ <- Only Header <br> curl -i http://www.example.com/ <- Header and Body<br> curl --proxy http://proxy.example.com:8080 http://example.com/  |
| wget                                              | The non-interactive network downloader.  | wget http://google.com/ <br> wget -e http_proxy=xx.xx.xx.xx:8080 http://example.com/ <br> wget -e https_proxy=xx.xx.xx.xx:8080 https://example.com/ <br> wget -S --spider http://example.com/  <- Only Header              |

##FTP
|Command | Description |Example |
|:-------|:------------|:-------|
| ftp   | ARPANET file transfer program   |   |
| lftp   | Sophisticated file transfer program   |   |

##SNMP
|Command | Description |Example |
|:-------|:------------|:-------|
| snmpwalk            | retrieve a subtree of management values using SNMP GETNEXT requests                     | snmpwalk -v 2c -c public localhost sysname<br> snmpwalk -v 2c -c public localhost .1.3.6.1.2.1                                          |
| snmpget              | communicates with a network entity using SNMP GET requests                              | snmpget -v 2c 192.168.0.10 -c public .1.3.6.1.4.1.2021.11.50.0                                                     |
| snmptranslate  | translate MIB OID names between numeric and textual forms                               | snmptranslate -Tp | less                                                                                                          |
| snmpnetstat                               | display networking status and configuration information from a network entity via SNMP  | snmpnetstat -v 2c -c public -Can localhost <br> snmpnetstat -v 2c -c public -Ci localhost <br> snmpnetstat -v 2c -c public -Cs localhost  |


<br>
# Shell Script 
http://cmdref.net/os/linux/command/#shell_script

##Shell
|Command | Description |Example |
|:-------|:------------|:-------|
| date    | print or set the system date and time                                                                              | date --date '10day ago' +"%d%m%Y"  -> 30102006 <br> date +"%d%m%Y" -> 30102006  <br> date +"%H:%M" -> 12:47 <br> cp -p FILE FILE.`date +%Y%m%d` <br> cp -p FILE FILE.`date -d '1day ago' +%Y%m%d`  |
| tr        | translate or delete characters                                                                                     |                                                                                                                                                                                                            |
| cut                       | remove sections from each line of files                                                                            | echo 12345 &#124;cut -c3-                                                                                                                                                                                   |
| sort    | sort lines of text files                                                                                           | sort -t: +1 -n sample.txt                                                                                                                                                                                  |
| uniq                      | report or omit repeated lines                                                                                      | cat access_log.1 | awk {'print $4'} |awk -F: {'print $1$2$3'} | sort &#124;uniq -c                                                                                                                          |
| logger                    | a shell command interface to the syslog(3) system log module                                                       | logger "test test"                                                                                                                                                                                     |
| basename                  | strip directory and suffix from filenames                                                                          |                                                                                                                                                                                                            |
| dirname                   | strip last component from file name                                                                                | DIR=`dirname ${0}`                                                                                                                                                                                     |
| paste  | merge lines of files                                                                                               | paste -d, test1.txt test2.txt                                                                                                                                                                              |
| awk      |                                                                                                                    | echo "1 2 3 4 5" | awk '{ print $1 "," $3 }'<br> echo "1 2 : 3 4 : 5" &#124; awk -F: '{ print $2 }'                                                                                                       |
| sed      |                                                                                                                    | sed -e 's/xxx/XXX/g' input.txt > output.txt                                                                                                                                                            |
| mail <br> mailx             | send and receive Internet mail <br> echo test &#124; mail -s "test" -S "smtp=smtp://xx.xx.xx.xx:25" test@example.com                                                                                                                                                                                                              ||
| while                     |                                                                                                                    | while : ; do uptime ; sleep 1 ; done<br> while : ; do uptime >> /tmp/tmp.txt ; sleep 1 ; done<br>  while : ; do ps aux |grep httpd &#124;wc -l ; sleep 1 ; done                                         |
| for                       |                                                                                                                    | for i in 127.0.0.1 192.168.10.1; do ping -c 2 $i; done                                                                                                                                                 |


<br>
# Hardware 
http://cmdref.net/os/linux/command/index.html#Hardware

##Haredware
|Command | Description |Example |
|:-------|:------------|:-------|
| dmesg   | print or control the kernel ring buffer   |dmesg   |
| lspci   | list all PCI devices   |lspci   |

##Module
|Command | Description |Example |
|:-------|:------------|:-------|
| lsmod  | show the status of modules in the Linux Kernel  | lsmod   |
| modinfo  | show information about a Linux Kernel module   | modinfo MODULENAME <br> modinfo bnx2   |
| insmod  | insert a module into the Linux Kernel   |   |
| rmmod  | remove a module from the Linux Kernel   |   |
| modprobe  | add and remove modules from the Linux Kernel    |   |


<br>
# Disk Utilities 
http://cmdref.net/os/linux/command/#disk_utilities

##HDD
|Command | Description |Example |
|:-------|:------------|:-------|
| du  | estimate file space usage                                     | du -sh * <br> du -h --max-depth=1                                       |
| fuser               | identify processes using files or sockets                     | fuser -mv /mnt/test  <- check<br> fuser -mvk /mnt/test <-(-k : Kill processes)  |
| chroot              | run command or interactive shell with special root directory  |                                                                               |
| hdparm              | get/set hard disk parameters                                  |                                                                               |
| dumpe2fs            | dump ext2/ext3/ext4 filesystem information                    |                                                                               |
| badblocks           | search a device for bad blocks                                |                                                                               |

##Partition
|Command | Description |Example |
|:-------|:------------|:-------|
| df      | report file system disk space usage   | df -h  <- (-h : print sizes in human readable format) <br> df -BG <- Bigabyte Unite <br> df -BM <- Megabyte Unite |
| sfdisk  | partition table manipulator for Linux   | sfdisk -l <-(-l : List the partitions of a device.)  |
| fdisk   | manipulate disk partition table   | fdisk -l <- ( -l : List  the  partition  tables)  <br> fdisk -l /dev/sdb <br> fdisk -l  -o +UUID |
| gdisk |Interactive GUID partition table (GPT) manipulator |  |
| parted  | a partition manipulation program   | parted /dev/mapper/mpath0  |
| lsblk   | list block devices  |lsblk  |
| e2label | Change the label on an ext2/ext3/ext4 filesystem   |   |

##Swap
|Command | Description |Example |
|:-------|:------------|:-------|
| mkswap   | set up a Linux swap area                           |                                                      |
| swapon   | enable devices and files for paging and swapping   | swapon -s <- Check <br> swapon -a<br> swapon /dev/xvda3  |
| swapoff  | disable devices and files for paging and swapping  | swapoff -a                                           |

##File Systems
|Command | Description |Example |
|:-------|:------------|:-------|
| mkfs     | build a Linux filesystem  <br> #you must umount the device before mkfs. | mkfs -t xfs /dev/sdb1 <br> mkfs -t ext3 /dev/sdb1 <br> mkfs -t ext4 /dev/sdb1  |
| mkfs.xfs mkfs.ext4 <br> mkfs.ext3   | #you must umount the device before mkfs.   | mkfs.ext4 /dev/sdb1 <br> mkfs.ext3 /dev/sdb1 |
| mkfs2fs  | create an ext2/ext3/ext4 filesyste  <br> #you must umount the device before mkfs.  | mke2fs /dev/sdb1 <- ext2 <br> mke2fs -j /dev/sdb1 <- ext3  |
| xfs_info | |xfs_info /dev/sda1 |
| tune2fs  | adjust tunable filesystem parameters on ext2/ext3/ext4 filesystems    | tune2fs -l /dev/mapper/mpath0 <br> <- (-l : List the contents of the filesystem superblock. <br> tune2fs -l /dev/mapper/mpath0 |egrep "count&#124;interval" <br> tune2fs -i 0 -c 0 /dev/mapper/mpath0 <br> <- (-i : interval, -c : mount count)  |
| fsck     | check and repair a Linux filesystem <br> you must umount the device before fsck. <br> for example single usermode and umount. <br> 'shutdown -r -F now' is force fsck after reboot.   | fsck -p /dev/sda1 <br> (-p : Automatically repair ("preen") the file system.)  |
| fsck.ext4     | check and repair a Linux filesystem   |   |
| e2fsck   | check a Linux ext2/ext3/ext4 file system   |   |
| resize2fs   | ext2/ext3/ext4 file system resizer   | resize2fs /dev/testvg/lvol0   |


##Data
|Command | Description |Example |
|:-------|:------------|:-------|
| dd     | convert and copy a file   | dd if=/dev/zero of=test_100M  bs=1M count=100  |
| sync   | flush file system buffers   |   |
| shred  | overwrite a file to hide its contents, and optionally delete it   |   |

##mount
|Command | Description |Example |
|:-------|:------------|:-------|
| mount    | mount a filesystem   | mount /mnt/test /dev/sda1 <br> mount -o remount /dev/sda1 |
| umount   | unmount file systems   | umount /mnt/test  <br> umount -f /mnt/test  <br> (-f : Force unmount(in case of an unreachable NFS system)) <br> umount -l /mnt/test <br> (-l : Lazy unmount.Detach the filesystem from the filesystem hierarchy now ) |


<br>
# LVM 
http://cmdref.net/os/linux/command/#LVM

##LVM
|Command | Description |Example |
|:-------|:------------|:-------|
|lvm       |LVM2 tools  |  |

##PV (Physical Volume)
|Command | Description |Example |
|:-------|:------------|:-------|
|pvs       |report information about physical volumes  |  |
|pvdisplay |display attributes of a physical volume  |pvdisplay <br> pvdisplay -C  |
|pvcreate  |initialize a disk or partition for use by LVM  |pvcreate /dev/mapper/mpath0p1 <br> pvcreate /dev/mapper/mpath0p1 /dev/mapper/mpath1p1   |
|pvremove  |remove a physical volume  |pvremove /dev/mapper/mpath0p1  |
|pvscan    |scan all disks for physical volumes  |  |

##VG (Volume Group)
|Command | Description |Example |
|:-------|:------------|:-------|
|vgs       |report information about volume groups  | vgs -o +vg_tags <- check tag  |
|vgdisplay |display attributes of volume groups  |vgdisplay <br> vgdisplay -C  |
|vgcreate  |create a volume group  |vgcreate vgdata1 /dev/hdb1 /dev/hdc1  |
|vgremove  |remove a volume group  |vgremove vg01  |
|vgscan    |scan all disks for volume groups and rebuild caches  |  |
|vgchange  |change attributes of a volume group  |vgchange -a y <- activate <br> vgchange -a n <- deactivate <br> vgchange -a y vg01 <br> vgchange -a n vg01 <br> Check : lvdisplay VGDATA |grep Status <br> vgchange  --addtag $(uname -n)  VG_TEST <br> vgchange  --deltag $(uname -n)  VG_TEST |
|vgextend  |add physical volumes to a volume group  |vgextend vg01 /dev/hdd1  |
|vgrename  |rename a volume group  |vgrename oldvg newvg  |

## LV (Logical Volume)
|Command | Description |Example |
|:-------|:------------|:-------|
|lvs       |report information about logical volumes  |  |
|lvdisplay |display attributes of a logical volume  |lvdisplay <br> lvdisplay -C <br> lvdisplay /dev/mapper/VGDATA-lv00|
|lvcreate  |create a logical volume in an existing volume group  |lvcreate -l PENUMBER vgdata <br> lvcreate -L 150G vgdata  |
|lvremove  |remove a logical volume  |lvremove /dev/testvg/lvol0  |
|lvscan    |scan (all disks) for logical volumes  |  |
|lvresize  |resize a logical volume  |lvresize -L +5G /dev/vg0/home  |
|lvextend  |extend the size of a logical volume  |lvextend -L +5G /dev/vg0/home <br> lvextend -l +100%FREE /dev/mapper/Array00-lv00  |
|lvreduce  |reduce the size of a logical volume  |  |
|lvrename  |rename a logical volume  |lvrename /dev/vgdata/lvol0 /dev/vgdata/lvol1  |





<br>
# Performance 
http://cmdref.net/os/linux/command/#Performance

##Performance
|Command | Description |Example |
|:-------|:------------|:-------|
| top          | display Linux processes                                                                                             | top -b -n 4 -d 15   <-  interval 15sec , 4 times                                                                            |
| sar          | Collect, report, or save system activity information.                                                               | sar -f /var/log/sa/sa16 <br> sar (cpu,io) <br> sar -r (memory) <br> sar -q (Loadaverage)                                          |
| vmstat    | Report virtual memory statistics                                                                                    | vmstat 1  <- interval 1sec (cpu, io, memory, swap)<br> vmstat 1 5 <- interval 1sec, 5 times (cpu, io, memory, swap)           |
| iostat    | Report Central Processing Unit (CPU) statistics and input/output statistics for devices and partitions.             | iostat -xtk  1 (cpu, io)  <- interval 1sec                                                                                  |
| mpstat                    | Report processors related statistics.                                                                               | mpstat -P ALL                                                                                                               |
| uptime                    | Tell how long the system has been running.                                                                          | while : ; do uptime ; sleep 1 ; done<br> while : ; do uptime >> /tmp/tmp.txt ; sleep 1 ; done                                 |
| w                         | Show who is logged on and what they are doing.                                                                      |                                                                                                                             |
| free        | Display amount of free and used memory in the system                                                                | free -m <- show output in MB                                                                                                |
| tcpdump  | dump traffic on a network                                                                                           | tcpdump host 192.168.0.10 -n -w /tmp/20110615.pcap <br> tcpdump -r /tmp/20110615.pcap <- -r : Read packets from file          |
| netstat  | Print network connections, routing tables, interface statistics, masquerade connections, and multicast memberships  | netstat -an (-a : Show both listening and non-listening sockets.) <br> netstat -rn (-r : Display the kernel routing tables.)  |

##Load Test

|Command | Description |Example |
|:-------|:------------|:-------|
|fio       |  |  |



<br>
# Software 
http://cmdref.net/os/linux/command/#software

##Software
|Command | Description |Example |
|:-------|:------------|:-------|
| make                                             | GNU make utility to maintain groups of programs  |                                                                                                                                                                      |
| patch                                                              | apply a diff file to an original                 | patch -p1 -N < ../xxx.patch                                                                                                                                          |
| ldd                                                                | print shared library dependencies                | ldd BINARY                                                                                                                                                           |
| yum    | an interactive, rpm based, package manager       | yum repolist <- check enabled repository <br> yum search STRINGS <br> yum info PACKAGE <br> yum install PACKAGE<br> yum --disablerepo=* --enablerepo=test-repo repolist  |
| rpm                                               | RPM Package Manager                              | rpm -ivh PACKAGE.rpm <- install<br> rpm -e PACAGE.rpm  <- uninstall                                                                                                    |
| apt                                                                |                                                  |                                                                                                                                                                      |
| dpkg                                                               |                                                  |                                                                                                                                                                      |
| alien                                                              |                                                  | alien -d package-x.x.x.rpm <br> alien -r package-x.x.x.deb                                                                                                             |
| update-alternatives               |                                                  | update-alternatives --config mta                                                                                                                                 |
| rhn_register                                                       |                                                  | rhn_register --nox --proxy=http://192.168.0.10:9999                                                                                                              |


# etc 
##X Window System

|Command | Description |Example |
|:-------|:------------|:-------|
| startx  | initialize an X session    |startx   |
| xhost  | server access control program for X   | xhost + <- Access is granted to everyone   |
| xauth  | X authority file utility   |   |

##TUI
|Command | Description |Example |
|:-------|:------------|:-------|
| ntsysv  | simple interface for configuring runlevels   |   |
| authconfig-tui  | an interface for configuring system authentication resources   |   |
| system-config-securitylevel  |    |   |
| system-config-network-tui  |    |   |

##etc
|Command | Description |Example |
|:-------|:------------|:-------|
| md5sum  | compute and check MD5 message digest   | find . -type f -exec md5sum {} \; > /tmp/md5.out <br> <- check all files  |
| gpg |OpenPGP encryption and signing tool | |
|screen   |    |   |
| kermit  |    |   |




<br>
http://cmdref.net/os/linux/command/