Detailed linux command (2)
View document content processing command
cat: View files
format:
cat filename
Options:
-n: Output line number
Example: Check / etc / passwd file
[root@10 ~]# cat /etc/passwd
tac: View a file, reverse the display file contents
format:
tac file name
more: page display file contents
format:
more filename
q End inquiry
less: page display file contents
format:
less filename
q End inquiry
head: display file contents header (default the first ten lines)
format:
head filename
Options:
-n: n displays the first row of content (n represents a number)
Example: Check / etc / passwd the first ten lines
[root@10 ~]# haed /etc/passwd
tail: display the contents of a file tail (ten lines after default)
format:
tail filename
Options:
-n: n row after displaying contents (n represents a number)
-f: continuous refresh, end the occupation, can be monitored in real time (file is changed, the terminal will show changes), can be abbreviated tailf
3-line review / etc / passwd: Examples
[root@10 ~]# tail -3 /etc/passwd
sort: Sort text file
format:
sort files
Options:
-n: Sort by Digital
-r: Reverse order (ascending order by default)
-u: de-duplication
uniq: the text contents of the file deduplication
format:
sort files
Options:
-c: calculating the number of repetitions
note:
Here is just adjacent to the heavy repeated before going heavy, so it should be first sorted before going heavy
example:
cat / var / log / httpd / access_log view httpd access log
cat / var / log / httpd / access_log | awk '{print $ 1}' Get all IP access
cat / var / log / httpd / access_log | awk '{print $ 1}' | sort sort IP access
cat / var / log / httpd / access_log | awk '{print $ 1}' | sort | uniq -c to calculate the weight and repetitions
cat / var / log / httpd / access_log | awk '{print $ 1}' | sort | uniq -c | sort -n -r Press sorted from high to low
cat / var / log / httpd / access_log | awk '{print $ 1}' | sort | uniq -c | sort -n -r | head -N taking the top N bits (N represents a number)
wc: statistics text messages
Options:
-c: Byte
-w: the number of words
-l: count the number of rows
Extended:
echo "this is ken" Shu wc -c: 12 bytes (including an escape character \ n)
printf "this is ken" Shu wc -c: 11 (not including \ n)
vi / vim: command-line text editor
- See vim editor
Information display command
uname: display information about the operating system (Linux)
format:
uname
Options:
-a: All information
-r: just look at the kernel version
example:
hostname: display or set the hostname of the current system
[Root @ 10 ~]: [username @ hostname of the current directory of the current logged (~ representation in the home directory)]
format:
hostname show hostname
New hostname name: modify the host name (restart failure)
hostnamectl set-hostname new name: the permanent modification (does not take effect immediately)
或echo "NO.1">/etc/hostname
stat: the display state of the file or the file system
format:
stat filename
du: calculate disk space usage
du view the file size (the default display all the files in a directory, and finally there will be the sum of the line size)
format:
of
Options:
-s: Display only the sum
-h: human readable
supplement:
du, and ls -l can view file size
du -h: see a directory (or file) the size of disk space occupied
ls -lh: to see the actual size of the file
example:
du -sh path to view all files under the path sum of the capacity (without path defaults to the current path)
du -sh path / * Check the capacity of each file in the path
df: report file system disk space usage
format:
df
Options:
-h: human readable (size)
example:
uptime: system status
format:
uptime
example:
17:54:30 up 5:23, 1 user, load average: 0.00, 0.01, 0.05
Runtime system system time of the current number of users one minute average load average load average load 5 minutes 15 minutes
View cpu information: cat / proc / cpuinfo
View cpu number of cat / proc / cpuinfo | grep proc | wc -l
supplement:
System load is calculated: Load / Number cpu
free: check the system memory
format:
free
options:
-m: Check the size of the unit to M
-h: human readable
-s <interval seconds> memory usage is continuously observed.
example:
[root@10 ~]# free -h
Each process running on the system view: ps
format:
ps aux (often usage: ps aux | grep service name)
example:
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
User process ID (unique) cpu usage memory usage status start time running time of the start command
top: real-time display system resource usage
format:
top (top = uptime + free + ps aux)
s - change the screen update frequency
l - close or open the top line of the first portion of the first information indicates
t - close or open the first part of the second row and third row Tasks information indicates Cpus
m - close or open a first part of the fourth row and the fifth row Mem information indicates Swap
N - in order to represent the size of the PID process list
P - in the order of magnitude of CPU usage alignment procedure list
M - the order of memory usage size of arrangement process list
h - Displays help
n - set the displayed number of processes in the process list
q - quit top
date: display, set the system time
format:
date: Time Display System
date Time: Set the system time
Options:
-s: The STRING set time (set)
-d plus the time (-1day, + 1day) show yesterday, tomorrow's time
Example 1: Set Time Format
[root@10 ~]# date -s "2019-01-13 13:30:00"
Example 2: The human-readable view time
[root@10 ~]# date "+%Y-%m-%d %H:%M:%S"(2019-01-13 13:30:00)
Or [root @ 10 ~] # data "+% F -% T" (case sensitive)
% Y Year (indicated by 4) (1970 ...)
% M month (represented by two) (01..12)
A few numbers (of the month)% d (expressed by two) (01..31)
% H hour (in 24-hour display, represented by two) (00..23)
% M minutes (represented by two) (00..59)
% S seconds (represented by two) (00..60)
% T time, by the 24-hour display (hh: mm: ss)
Display% F% Y-% m-% d