LinuxCommand Optimization1th Chapter 13Supplementary Questions
in the/oldboy directory and its subdirectories, all files that end with the extension. SH are replaced with a string that contains Oldboy. Oldgirl
1.1Method1
[Email protected] ~]# find/oldboy/-type f-name "*.sh"
/oldboy/test/del.sh
/oldboy/test.sh
/oldboy/t.sh
[Email protected] ~]# find/oldboy/-type f-name "*.sh" |xargs ls-l
-rw-r--r--. 1 root root 8 Jul 17:48/oldboy/test/del.sh
-rw-r--r--. 1 root root 8 Jul 17:48/oldboy/test.sh
-rw-r--r--. 1 root root 8 Jul 17:48/oldboy/t.sh
1.2Method2
Ready Posture
[Email protected] ~]# which mkdir
/bin/mkdir
[Email protected] ~]# ll/bin/mkdir
-rwxr-xr-x. 1 root root 50056 Mar 2017/bin/mkdir
[Email protected] ~]# ll which mkdir
Ls:cannot access which:no such file or directory
Ls:cannot access mkdir:no such file or directory
[[email protected] ~]# ll $ (which mkdir)
-rwxr-xr-x. 1 root root 50056 Mar 2017/bin/mkdir
#$() run the command inside the parentheses first and then execute the other commands.
#$() `` Anti-Quote
find/oldboy/-type f-name "*.sh" and Ls-l
ll $ (find/oldboy/-type f-name "*.sh")
1.3Method3
[Email protected] ~]# find/oldboy/-type f-name "*.sh"-exec ls-l {} \;
-rw-r--r--. 1 root root 8 Jul 17:48/oldboy/test/del.sh
-rw-r--r--. 1 root root 8 Jul 17:48/oldboy/test.sh
-rw-r--r--. 1 root root 8 Jul 17:48/oldboy/t.sh
Summary:
Find command to find the file to give to other commands (LS sed rm)
1 , find/oldboy/-type f-name "*.sh" |xargs ls-l
2 , LL $ (find/oldboy/-type f-name "*.sh")
3 , find/oldboy/-type f-name "*.sh"-exec ls-l {} \;
2nd Chapter |with the|xargsdifference
| Piping Pass the previous command result through a pipeline to a later command passing text text
|xargs turn the previous command result passing through a pipeline to a later command The file name is passed
[Email protected] ~]# sed-i ' s#old#young#g '
Sed:no input Files
[Email protected] ~]# find/oldboy/-type f-name "*.sh"
/oldboy/test/del.sh
/oldboy/test.sh
/oldboy/t.sh
[Email protected] ~]# find/oldboy/-type f-name "*.sh" |sed-i ' s#old#you#g '
Sed:no input Files
[Email protected] ~]# find/oldboy/-type f-name "*.sh" |xargs sed-i ' s#old#you#g '
#find +|xargs
3rd Chapter PS13.1Environment Variables
variables
x + y = ten, known x=11 y=?
Environment variables
1. Uppercase
2. Can be used in most parts of the system meaning basically unchanged
3. System creation
PS1 ===== Martial Arts cheats (sunflower Treasure)
echo $PS 1 ===== reading
Ps1= ' [\[email protected]\h \w]\$ ' ===== write content " if you want to practice this work, you will be able to succeed from the palace."
3.2 PS1control command line appearance3.2.1 #Temporary
Export ps1= ' [\[email protected]\h \w]\$ '
3.2.2 #Permanent
Vim/etc/profile #编辑文件
[Email protected]/data]# tail-2/etc/profile
Alias net= ' Cat/etc/sysconfig/network-scripts/ifcfg-eth0 '
Export ps1= ' [\[email protected]\h \w]\$ '
#生效
Source/etc/profile
Summary:
1. characteristics of environmental variables
2. View environment variable contents
4th Chapter # #SElinux
NSA
4.1CloseSElinux
4.1.1permanently closedSElinux-takes effect after server restart
/etc/selinux/config
# selinux= can take one of these three values:
# Enforcing default SELinux open in Run
# permissive SELinux shutdown warning message
# disabled SELinux completely shut down
Selinux=enforcing
Don't give yourself any reason to restart the server
Vim
U
C Delete the cursor to the end of the line and enter edit mode
4.1.2temporarily closedselinux–
[Email protected] ~]# getenforce
Enforcing
[Email protected] ~]# setenforce
Usage:setenforce [Enforcing | Permissive | 1 | 0]
[Email protected] ~]# setenforce 0
[Email protected] ~]# getenforce
Permissive
4.1.3CloseSElinux:
Pre-operation backup, post-operation check
0. Backup
1. Temporary
2. Permanent
3. Check
esc+. ( dot ) Use the last thing on the previous command
5th Chapter SEDmodify files and back up
[Email protected]/oldboy]# cat t.sh
Yougirl
[[email protected]/oldboy]# sed ' s#girl#boy#g ' t.sh
Youboy
[Email protected]/oldboy]# sed-i.bak ' s#girl#boy#g ' t.sh
[[email protected]/oldboy]# #-i.bak first back up the file T.sh.bak
[[Email protected]/oldboy]# # then modify the contents of the file
[Email protected]/oldboy]# cat t.sh
Youboy
[Email protected]/oldboy]# cat T.sh.bak
Yougirl
CentOS 5.x 6.x Firewall iptables
CentOS 7.x FIREWALLD
Work application:
Firewall Server has public IP address Open
Firewall Server only intranet IP address off
when it's high concurrency,
5.1CloseIptables 5.1.1 #1.Temporary
[[email protected]/oldboy]# /etc/init.d/iptables Stop
Iptables:setting chains to Policy Accept:filter [OK]
iptables:flushing firewall rules: [OK]
iptables:unloading modules: [OK]
[[email protected]/oldboy]# /etc/init.d/iptables Stop
[Email protected]/oldboy]# /etc/init.d/iptables status
Iptables:firewall is not running.
5.1.2 #2.permanently closed-
Turn off boot from The software runs automatically at boot time
post-boot software management commands
[Email protected]/oldboy]# chkconfig iptables off
[Email protected]/oldboy]# chkconfig |grep IPT
Iptables 0:off 1:off 2:off 3:off 4:off 5:off 6:off
6th ChapterCloseIptablesSummary:6.1Temporary-failed after restarting server
/etc/init.d/iptables stop
6.2.Permanent-takes effect after restarting the server
# turn off boot from start
chkconfig iptables off
6.3Check
/etc/init.d/iptables status
Chkconfig |grep IPT
GBK National Standard
UTF-8 Universal Code
6.3.1View Character Sets
[Email protected]/oldboy]# echo $LANG
en_US. UTF-8
[[email protected]/oldboy]# #en_US language
[[email protected]/oldboy]# #UTF-8 Character Set
[Email protected]/oldboy]# #语言. Character Set
6.3.2.Modifying character sets-Temporary
[[email protected]/oldboy]# export. UTF-8
[Email protected]/oldboy]# echo $LANG
Zh_cn. UTF-8
6.3.3permanently modify character sets
[Email protected]/oldboy]# cat/etc/sysconfig/i18n
Lang= "en_US. UTF-8 "
Sysfont= "Latarcyrheb-sun16"
[Email protected]/oldboy]# source/etc/sysconfig/i18n
[Email protected]/oldboy]# echo $LANG
en_US. UTF-8
Linux display in Chinese garbled:
the character set of the 1.linux system is different from the Remote connection tool
Summary:
1.find command to find the file to give to other commands (LS rm sed) three kinds
2. environment variable: PS1 LANG (must be modified)
3. Turn off SELinux and Iptables
4. How to modify the character set
Linux Basic optimization