Beginner Linux may appear to forget the command, this time should be a few common commands to write down, so that every day can knock, the days will be a long time in the mind has a deep impression. Here is my record of the common Linux commands, as well as the configuration of the service, are very practical, but for a bit of basic people:
I. Some information about Linux system logs, log configuration file syslog.conf
System logs are generally present under/var/log
The usual system logs are as follows:
Core Boot log:/VAR/LOG/DMESG
System error log:/var/log/messages
Mail system log:/var/log/maillog
FTP System log:/var/log/xferlog
Security information and System login and network connection information:/bar/log/secure
Login record:/var/log/wtmp
News log:/var/log/spooler
RPM Package:/var/log/rpmpkgs
XFree86 log:/var/log/xfree86.0.log
Boot log:/var/log/boot.log
Cron (custom task Log) log:/var/log/cron
Network:/etc/sysconfig/network-scrip/ifcif-etho
Ii. Common Commands
Find./-mtime 0: Returns files that have been modified in the last 24 hours./Represents the folder you need to find
/ETC/MOTD displaying a message when Telnet
Sed-n ' 5,10p ' filename so you can view only the lines 5th through 10th of the file.
Yum instll xxx Install XXX pack
/etc/inittab System kernel Commands
MKFS-T ext3-c/DEV/SDB3 formatted partition
Fdisk-l Disk Details
FDISK/DEV/SDB1 | Fdisk-l Disk Partitioning
chkconfig [Service]--list status|stop service turned off
/etc/fstab Expansion Slot Boot mount
/etc/sysconfig/iptables//Firewall configuration file
Service Iptables Stop/start//Startup and shutdown
-A input-s 192.168.0.3-p tcp--dport 22-j ACCEPT firewall configuration: Only allow this machine to connect with SSH
Iptables-i input-s 59.151.119.180-j DROP//IP connection,
Iptables-i input-s 211.1.0.0/16-j DROP//IP segment
Ulimit-f 10240 Limit the capacity of users to create files
Parted/dev/sdb Print View divider slot
cp/etc/skel/. {BASH_PROFILE,BASHRC}
Ifconfig | grep ' inet addr ' | awk ' {print $} ' | Sed ' s/addr://g ' View a column field
Read-p Man-Machine interaction, enter a value to execute
NETSTAT-T-u L-P Network tracking
DMESG | Grep-i HD ETH Analytics core message
Vmstat-a-fs-s-d-p System resource change, detection
Vim ~/.BASHRC BASHRC can set shortcut commands
Alias so= ' source ~/.BASHRC ' Save settings
alias ps11= ' echo ps1= ' [\[email protected]\h \w \a #\#]\$ "' terminal display
alias sk= ' Echo cp/etc/skel/.{ BASG_PROFILE,BASHRC} ~ Works when terminal displays an error
alias grep= ' grep--color=auto ' grep display color
Alias Al= ' vim ~/.BASHRC ' alias shortcut variable
export | set View Variables
setup Supplemental Note: Setup is a setup utility that provides a graphical interface for how to do this
Cal 2017 8 to view calendar
Usermod-g stdent (group) index (user) change user-owned group
Chgrp stdent (group) ipconfig (file) Change file owning group
Chown Liu (user) ipconfig (file) change file user
useradd create user
groupadd Creating a group
Path= "$PATH":/root shortcut PATH usage
rpm-ivh xx.rpm Install RMP package
DD if=/dev/hdc1 of=/tmp/boot.whole.disk backup
restore-t-f/root/boot.dump Restore files or directories
Three, detailed settings
Firewall configuration
IPTABLES-F//Clear Configuration
/etc/rc.d/init.d/iptables
1) effective after reboot
Open: Chkconfig iptables on
OFF: Chkconfig iptables off
2) immediate effect, failure after reboot
Open: Service iptables start
Close: Service iptables stop
It should be stated that for other services under Linux, the above command can be used to perform the open and close operations.
When the firewall is turned on, make the following settings, open the relevant port,
Modify the/etc/sysconfig/iptables file to add the following:
-A rh-firewall-1-input-m state--state new-m tcp-p TCP--dport 80-j ACCEPT
-A rh-firewall-1-input-m state--state new-m tcp-p TCP--dport 22-j ACCEPT
Network settings:
/etc/sysconfig/network-scripts/ifcfg-eth0 Network Configuration
Onboot=yes//boot up
Bootrpoto=static//Static IP
dns1=192.168.1.1//dns
ipaddr=172.16.2.1
netmask=255.255.255.0//Subnet mask
gateway=172.16.1.1//Gateway
Service Network Restart Restart Network
To restrict IP logons:
/etc/hosts.deny Deny Login list
/etc/hosts.allow Allow Login List
Generally use the Deny login list to set all IP
Like what
Sshd:all
Then set the IP you want to allow in the Allow login list
Like what
sshd:10.10.10.1
Sshd:192.168.1.1:allow
Crontab Scheduled Tasks
Crontab-l//List
CRONTAB-E//Edit
crontab-d//delete
Service Crond.service
Basic format:
* * * * * command
Time-sharing Weekly command
The 1th column represents minutes 1~59 per minute with * or */1
The 2nd column represents the hour 1~23 (0 means 0 points)
The 3rd column represents the date 1~31
The 4th column represents the month 1~12
5th Column Identification Number Week 0~6 (0 = Sunday)
6th List of commands to run
Shell L Script Debugging method
-N
Read the command in the script but not execute it to check for syntax errors in the script
-V
Executes scripts while printing executed script commands to standard error output
-X
Provides trace execution information and prints each command and result that executes sequentially
Touch command (useful when writing scripts)
CC means century
YY represents the year
MM Indicates the month
DD represents the day
HH denotes hours
mm = minutes
SS = Seconds
201001311200.34
CCYYMMDDHHMM SS
Touch xxxx//create XXX Text
-T: can be followed by time, in the format described above
-D: Follow-up time
-A: Only modify access time//state changes, such as executed, or read
-C: Modify only the CTime time without creating the file//permissions and attributes being changed
-M: Modify only Mtime//content changes
Change issue file date to 2008/07/15 13:13
Touch-t 0807151313/etc/issue
Touch-m-D 0807151313/etc/issue
touch-acmr/bin/ls/etc/sh.conf time to change the last time to a previous file
Usage of Yum
Yum Install all installed
Yum Install Package1 installs the specified installation package Package1
Yum groupinsall group1 Installer group group1
Yum Remove & #124; Erase Package1 Remove Package Package1
Yum groupremove group1 Remove a program group group1
Yum deplist package1 Viewing program package1 dependencies
Yum Install Setuptool installs setup, but only authentication configuration is available after installation using Run Setup.
If you want to configure IP, install System-config-network-tui.
Yum Install System-config-firewall-tui installs the graphical firewall configuration tool.
Yum list system-config* all installed.
Display of dates
Date ' date +%y%m%d-%k ' = 20160531//' This is the key above the TAB key, not the single quotation mark
%a: Day of the Week (Sun. Sat)
%A: Day of the Week (Sunday). Saturday)
%b: Month (Jan). DEC)
%B: Month (January). December)
%c: Displays the date and time directly
%d: Day (01..31)
%d: Show date directly (MM/DD/YY)
%h: With%b
%j: The first day of the Year (001..366)
%m: Month (01..12)
%u: Week of the Year (00..53) (in Sunday as the first day of the week)
%w: The day of the Week (0..6)
%W: Week of the Year (00..53) (with Monday as the first day of the week)
%x: Show date directly (MM/DD/YY)
%y: Last two digits of the year (00.99)
%Y: Full year (0000..9999)
%: Print out
%%n: Next line
%t: Jump Grid
%H: Hours (00..23)
%I: Hours (01..12)
%k: Hours (0..23)
%l: Hours (1..12)
%M: minutes (00..59)
%p: Show local AM or PM
%r: Direct Display time (12-hour format, HH:MM:SS [ap]m)
%s: The number of seconds from January 1, 1970 00:00:00 UTC to date%s: seconds (00..61)
%T: Direct Display time (24-hour system)
%x: Equivalent to%h:%m:%s
%Z: Show Time zone
File comparison operations (useful when writing scripts)
-e filename true if filename exists [-e/var/log/syslog]
-D filename True if filename is a directory [-d/tmp/mydir]
-F filename True if filename is a regular file [-f/usr/bin/grep]
-L filename True if filename is a symbolic link [-l/usr/bin/grep]
-R filename True if filename is readable [-r/var/log/syslog]
-W filename if filename is writable, true [-w/var/mytmp.txt]
-X filename is true if filename is executable [-l/usr/bin/grep]
Filename1-nt filename2 If filename1 is newer than filename2, then true [/tmp/install/etc/services-nt/etc/services]
Filename1-ot filename2 If filename1 is older than filename2, then true [/boot/bzimage-ot Arch/i386/boot/bzimage]
String comparison operators (note the use of quotation marks, which is a good way to prevent whitespace from disturbing the code)
-Z String True if string length is zero [-Z $myvar]
-N String if string length is nonzero, true [-N $myvar]
string1 = string2 true if string1 is the same as string2 [$myvar = one of the three]
String1! = string2 true if string1 is different from string2 [$myvar! = one, three]
Arithmetic comparison operators
Num1-eq num2 equals [3-eq $mynum]
Num1-ne num2 Not equal to [3-ne $mynum]
Num1-lt num2 less than [3-lt $mynum]
Num1-le num2 less than or equal to [3-le $mynum]
NUM1-GT num2 greater than [3-GT $mynum]
Num1-ge num2 greater than or equal to [3-ge $mynum]
Iv. Text Manipulation commands
SED usage:
Sed ' 1d ' ab delete line 1th
Sed ' $d ' ab delete last line
Sed ' 1,2d ' ab #删除第一行到第二行
Sed-n ' 1p ' ab #显示第一行
Sed-n ' $d ' ab #显示最后一行
Sed ' 1,3a drink tea ' ab #第一行到第三行后增加字符串 "Drink Tea"
SED ' 1c Hi ' AB #第一行代替为Hi
Sed-n '/ruby/p ' ab | Sed ' s/ruby/bird/g ' #替换ruby为bird
Sed-n '/ruby/p ' ab | Sed ' s/ruby//g ' #删除ruby
Sed-i ' $a bye ' ab #在文件ab中最后一行直接输入 "Bye"
awk usage:
Awk: Performs an operation on a single line of the file in solitude.
Awk-f ":" ' {print $1,$4} ': Use ': ' to split the line and print the first fourth field in this row
<, <=, = =,! =, >=, ~ match regular expressions,!~ mismatched regular expressions
Match: awk ' {if ($4~/asima/) print $} ' temp indicates that if the fourth field contains Asima, the entire bar will be printed
Exact match: awk ' $3== ' {print $} ' temp only prints records with Field 3 equal to ' 48 '
Mismatch: awk ' $!~/asima/' temp prints entire records that do not contain Asima
Not equal to: awk ' $! = ' Asima ' temp
Less than: awk ' {if ($1<$2) print $ "is smaller"} ' temp
Set case: awk '/[gg]reen/' temp prints a whole strip of records containing green, or green
Any character: awk ' ~/^...a/' temp prints the fourth character in the 1th field is a record, the symbol ' ^ ' represents the beginning of the line, conforms to '. ' Represents any character
or relationship matching: awk ' $0~/(ABC) | (EFG)/' temp ' when using |, the statement needs to be enclosed
and relationship: awk ' {if ($1== "a" && $2== "B") print $} ' Temp
Or or relationship: awk ' {if ($1== "a" | | $1== "B") print $} ' Temp
Cut usage:
-B: Split in bytes. These byte locations will ignore multibyte character boundaries unless the-n flag is also specified.
-C: Split in characters.
-D: Custom delimiter, default is tab.
-F: Used with-D to specify which area to display.
-N: Cancels splitting multibyte characters. Used only with the-B flag. If the last byte of the character falls within the range of <br/> indicated by the List parameter of the-B flag, the character will be written out;
Who|cut-b 3 #每行第三个字节
Who|cut-b 3-5,8 #第三到五, and eighth byte
Cat Tab_space.txt |cut-d '-F 1 #区域以空格为分割, take the first paragraph
Sort usage:
To sort by a unit of action, by comparison, by the beginning of a letter.
-U Remove Duplicate rows
-R Descending
Sort-r number.txt-o number.txt #重定向文件要-O
V. Decompression/Compression commands
TAR-ZXF apr-1.4.5.tar.gz
. tar
Unpacking: Tar xvf Filename.tar
Package: Tar cvf filename.tar DirName
(Note: Tar is packaged, not compressed!) )
———————————————
. gz
Decompression 1:gunzip filename.gz
Decompression 2:gzip-d filename.gz
Compression: gzip FileName
. tar.gz and. tgz
Decompression: Tar zxvf FileName.tar.gz
Compression: Tar zcvf FileName.tar.gz DirName
———————————————
. bz2
Decompression 1:bzip2-d filename.bz2
Decompression 2:BUNZIP2 filename.bz2
Compression: Bzip2-z FileName
. tar.bz2
Decompression: Tar jxvf FileName.tar.bz2
Compression: Tar jcvf FileName.tar.bz2 DirName
———————————————
. BZ
Decompression 1:bzip2-d filename.bz
Decompression 2:BUNZIP2 filename.bz
Compression: Unknown
. tar.bz
Decompression: Tar jxvf FileName.tar.bz
Compression: Unknown
———————————————
. Z
Decompression: uncompress filename.z
Compression: Compress FileName
. Tar. Z
Decompression: Tar zxvf filename.tar.z
Compression: Tar zcvf filename.tar.z DirName
———————————————
. zip
Decompression: Unzip Filename.zip
Compression: Zip Filename.zip DirName
Linux basic commands