1th Linux Optimization
1. It is known that the Test.txt file already exists in/tmp, how to execute the command in order to/mnt/test.txt copy to/tmp to cover off the/tmp/test.txt, and let the system not prompt for overwrite (root permission).
[Email protected] ~]# cp/mnt/test.txt/tmp/
Cp:overwrite '/tmp/test.txt '?
Do not prompt for overwrite when copying
#方法1
[Email protected] ~]# \cp/mnt/test.txt/tmp/
Absolute path to #方法2 using commands (full path)
[[email protected] ~]# which CP #命令的绝对路径 (full path)
Alias cp= ' Cp-i '
/bin/cp
[Email protected] ~]# cp/mnt/test.txt/tmp/
Cp:overwrite '/tmp/test.txt '? ^c
[Email protected] ~]#/bin/cp/mnt/test.txt/tmp/
#cp Overwrite
#rm whether to delete
#mv whether to overwrite files
CP = = = Cp-i
RM = = Rm-i
MV = = = Mv-i
The alias of the system is a nickname for the command.
#安全
#省事
1.1 Display aliases in the system
Alias san= ' Cp-i '
Alias zhang= ' Mv-i '
Alias wang= ' Rm-i '
1.2 Setting aliases
Alias wang= ' Rm-i '
Alias aliases = ' Command '
To set an alias for an RM command
#第1个里程碑-Configure RM aliases-Destinations
Target: Execute RM screen to display RM command BNY.
1.3 Configuring RM Aliases-Commands
[[email protected] ~]# Echo RM Command BNY
RM Command BNY
Configure RM aliases-Temporary effect
[[email protected] ~]# alias rm= ' echo RM BNY '
[[email protected] ~]# alias RM
Alias Rm= ' echo RM BNY '
[Email protected] ~]# Rm/tmp/oldboy.txt
RM bny/tmp/oldboy.txt
1.4 Configuring RM Aliases-Permanent
Modify File/etc/profile
[Email protected] ~]# tail-5/etc/profile
Done
unset I
Unset-f Pathmunge
Alias Rm= ' echo RM BNY '
Effect
[Email protected] ~]# Source/etc/profile
[[email protected] ~]# alias RM
Alias Rm= ' echo RM BNY '
1.5 giant Pits
[Email protected] ~]# VIM/ROOT/.BASHRC
. Bashrcuser specific aliases and Functionsalias rm= ' rm-i '
Alias cp= ' Cp-i '
Alias mv= ' Mv-i '
Source Global Definitions
if [-F/ETC/BASHRC]; Then
. /etc/bashrc
Fi
1.6 Log back in and check
[[email protected] ~]# alias RM
Alias Rm= ' echo RM BNY '
How to configure aliases:
1. Command line-temporary entry into force and inspection
Alias Rm= ' echo RM BNY '
Rm/tmp/oldboy.txt
2. Modification of files-permanent entry
Vim/etc/profile
Source/etc/profile
3. Check
4. Pit-RM MV CP
/root/.bashrc
1.7 Configuring aliases:
Input NET displays the contents of the/etc/sysconfig/network-scripts/ifcfg-eth0 file
1.8 Issued after completion
1.alias Net
2./etc/profile last 5 lines
1. Command line-temporary entry into force and inspection
[[email protected] ~]# alias net= ' Cat/etc/sysconfig/network-scripts/ifcfg-eth0 '
[[email protected] ~]# net
Device=eth0
Type=ethernet
Uuid=8fdc5e19-5b35-49fa-b63e-1629a63af1f0
Onboot=yes
Nm_controlled=yes
Bootproto=none
Hwaddr=00:0c:29:59:d4:13
ipaddr=10.0.0.200
Prefix=24
gateway=10.0.0.254
Defroute=yes
Ipv4_failure_fatal=yes
Ipv6init=no
Name= "System eth0"
2. Modification of files-permanent entry
Vim/etc/profile #编辑文件写入最后一行
[Email protected] ~]# Source/etc/profile
[[email protected] ~]# alias net
Alias net= ' Cat/etc/sysconfig/network-scripts/ifcfg-eth0 '
3. Check
Vim shortcut keys
G arrive at the last line of the file
GG arrives at line 1th of the file
10gg arrives at line 10th of the file
O (Small letter O) Insert a blank line below the current line and enter edit mode
U undo
: q! Exit
[Email protected] ~]# RM oldboy.txt
RM BNY Oldboy.txt
[Email protected] ~]# \RM oldboy.txt
[email protected] ~]# ll Oldboy.txt
Ls:cannot access oldboy.txt:No such file or directory
[[email protected] ~]# alias LL
Alias ll= ' Ls-l--color=auto '
# #13 all the files in the/oldboy directory and its subdirectories that end with the extension. sh, the file containing the Oldboy string is all replaced with Oldgirl
Mkdir-p/oldboy/test
Cd/oldboy
echo "Oldboy" >test/del.sh
echo "Oldboy" >test.sh
echo "Oldboy" >t.sh
Touch Oldboy.txt
Touch Alex.txt
# #第1个里程碑-find
[Email protected] oldboy]# find/oldboy/-type f-name "*.sh"
/oldboy/test/del.sh
/oldboy/test.sh
/oldboy/t.sh
# #第2个里程碑-Replace the contents of a file
[email protected] oldboy]# cat t.sh
Oldboy
[[Email protected] oldboy]# sed ' s#oldboy#oldgirl#g ' t.sh
Oldgirl
[[Email protected] oldboy]# sed ' s#oldboy#oldgirl#g ' t.sh
Oldgirl
[email protected] oldboy]# cat t.sh
Oldboy
#sed Modify the contents of the file to replace the Oldboy in the file with Oldgirl
[Email protected] oldboy]# sed-i ' s#oldboy#oldgirl#g ' t.sh
[email protected] oldboy]# cat t.sh
Oldgirl
#第3个里程碑-Pass the file found by the Find command to the SED command
[Email protected] oldboy]# find/oldboy/-type f-name ". Sh "
/oldboy/test/del.sh
/oldboy/test.sh
/oldboy/t.sh
[Email protected] oldboy]# find/oldboy/-type f-name ". sh "|xargs sed ' s#oldboy#oldgirl#g '
Oldgirl
Oldgirl
Oldgirl
[Email protected] oldboy]# find/oldboy/-type f-name ". Sh "|xargs sed-i ' s#oldboy#oldgirl#g '
[Email protected] oldboy]# find/oldboy/-type f-name ". Sh "|xargs cat
Oldgirl
Oldgirl
Oldgirl
2nd Linux Foundation Optimization
2.1 Displaying the version information of the system
[Email protected] oldboy]# cat/etc/redhat-release
CentOS Release 6.9 (Final)
[Email protected] oldboy]# uname-r
2.6.32-696.el6.x86_64
[Email protected] oldboy]# uname-m
x86_64
2.2 Add user settings password Switch user
1. Add Users
[Email protected] oldboy]# Useradd Oldboy
2.password Set Password
[Email protected] oldboy]# passwd Oldboy
Changing password for user Oldboy.
New Password:
Bad Password:it is too simplistic/systematic
Bad Password:is too simple
Retype new Password:
Passwd:all authentication tokens updated successfully.
3. Switch users
Su-oldboy
CTRL + D exits the current user
Optimization and basic optimization of Linux