1.cp --copy 复制/备份
- cp -p 复制时保持属性不变
[root@oldboy60-zw oldboy]# cp -p lidao.txt lidao1.txt
[root@oldboy60-zw oldboy]# ll
total 664
drwxr-xr-x. 3 root root 19 Mar 23 16:59 alex
-rw-r--r--. 1 root root 0 Mar 23 17:00 lidao1.txt
-rw-r--r--. 1 root root 0 Mar 23 17:00 lidao.txt
-rw-r--r--. 1 root root 11 Mar 30 10:19 oldboy.txt
-rw-r--r--. 1 root root 674761 Mar 30 18:14 test.txt
- cp -d 与软连接有关尚未讲解
- cp -r 递归复制目录
[root@oldboy60-zw oldboy]# cp -r /oldboy/ /oldboy1/
[root@oldboy60-zw oldboy]# ls
alex lidao1.txt lidao.txt oldboy.txt test.txt
[root@oldboy60-zw oldboy]# ls /oldboy1/
alex lidao1.txt lidao.txt oldboy.txt test.txt
- cp -a =cp -pdr
[root@oldboy60-zw /]# cp -a /oldboy/ /oldboy2/
[root@oldboy60-zw /]# ll /oldboy/ /oldboy2/
/oldboy/:
total 664
drwxr-xr-x. 3 root root 19 Mar 23 16:59 alex
-rw-r--r--. 1 root root 0 Mar 23 17:00 lidao1.txt
-rw-r--r--. 1 root root 0 Mar 23 17:00 lidao.txt
-rw-r--r--. 1 root root 11 Mar 30 10:19 oldboy.txt
-rw-r--r--. 1 root root 674761 Mar 30 18:14 test.txt
/oldboy2/:
total 664
drwxr-xr-x. 3 root root 19 Mar 23 16:59 alex
-rw-r--r--. 1 root root 0 Mar 23 17:00 lidao1.txt
-rw-r--r--. 1 root root 0 Mar 23 17:00 lidao.txt
-rw-r--r--. 1 root root 11 Mar 30 10:19 oldboy.txt
-rw-r--r--. 1 root root 674761 Mar 30 18:14 test.txt
2.mv - move 移动/重命名
3.rm - remove 删除,不加参数的情况下默认只能删除文件
- rm -r 递归删除
[root@oldboy60-zw /]# ls
alex bin boot dev etc home lib lib64 media mnt oldboy oldboy1 oldboy2 opt proc root run sbin srv sys tmp usr var
[root@oldboy60-zw /]# rm -r oldboy2/
rm: descend into directory ‘oldboy2/’? y
rm: descend into directory ‘oldboy2/alex’? y
rm: remove directory ‘oldboy2/alex/lidao’? y
rm: remove directory ‘oldboy2/alex’? y
rm: remove regular empty file ‘oldboy2/lidao.txt’? y
rm: remove regular file ‘oldboy2/oldboy.txt’? y
rm: remove regular file ‘oldboy2/test.txt’? y
rm: remove regular empty file ‘oldboy2/lidao1.txt’? y
rm: remove directory ‘oldboy2/’? y
[root@oldboy60-zw /]# ls
alex bin boot dev etc home lib lib64 media mnt oldboy oldboy1 opt proc root run sbin srv sys tmp usr var
- rm -f 强制删除不提示
[root@oldboy60-zw oldboy1]# ls
alex lidao1.txt lidao.txt oldboy.txt test.txt
[root@oldboy60-zw oldboy1]# rm -f test.txt
[root@oldboy60-zw oldboy1]# ls
alex lidao1.txt lidao.txt oldboy.txt
4.mount/umount
- mount 挂载
[root@oldboy60-zw ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 is write-protected, mounting read-only
[root@oldboy60-zw ~]# ls -l /mnt/
total 686
-rw-rw-r--. 1 root root 14 Nov 26 00:01 CentOS_BuildTag
drwxr-xr-x. 3 root root 2048 Nov 26 00:20 EFI
-rw-rw-r--. 1 root root 227 Aug 30 2017 EULA
-rw-rw-r--. 1 root root 18009 Dec 10 2015 GPL
drwxr-xr-x. 3 root root 2048 Nov 26 00:21 images
drwxr-xr-x. 2 root root 2048 Nov 26 00:20 isolinux
drwxr-xr-x. 2 root root 2048 Nov 26 00:20 LiveOS
drwxrwxr-x. 2 root root 663552 Nov 26 07:52 Packages
drwxrwxr-x. 2 root root 4096 Nov 26 07:53 repodata
-rw-rw-r--. 1 root root 1690 Dec 10 2015 RPM-GPG-KEY-CentOS-7
-rw-rw-r--. 1 root root 1690 Dec 10 2015 RPM-GPG-KEY-CentOS-Testing-7
-r--r--r--. 1 root root 2883 Nov 26 07:54 TRANS.TBL
- umount 移除挂载
[root@oldboy60-zw ~]# umount /mnt/
[root@oldboy60-zw ~]# ls /mnt/
5.hostname
- hostname 显示主机名
[root@oldboy60-zw ~]# hostname
oldboy60-zw
- hostname oldboy666 修改主机名 (临时生效,重启失效)
[root@oldboy60-zw ~]# hostname oldboy666
[root@oldboy60-zw ~]# hostname
oldboy666
-CentOS 7专用命令 hostnamectl 即时生效+永久生效
[root@oldboy60-zw ~]# hostnamectl set-hostname oldboy60-zw
[root@oldboy60-zw ~]# hostname
oldboy60-zw
6.修改DNS
/etc/resolv.conf 与网卡配置文件
共同:
1.都可以配置修改DNS
区别:
1.网卡配置文件内DNS名称DNS1和DNS2
2.resolv.conf内DNS名称nameserver nameserver不分1,2
3./etc/resolv.conf配置实时生效,重启网络后被网卡配置文件内的配置替代.
4.主要修改网卡配置文件即可.
7.修改本地hosts
[root@oldboy60-zw ~]# ping taobao.com
PING taobao.com (140.205.94.189) 56(84) bytes of data.
64 bytes from 140.205.94.189 (140.205.94.189): icmp_seq=1 ttl=128 time=26.0 ms
64 bytes from 140.205.94.189 (140.205.94.189): icmp_seq=2 ttl=128 time=26.2 ms
^C
--- taobao.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 26.025/26.113/26.202/0.184 ms
[root@oldboy60-zw ~]# vim /etc/hosts
[root@oldboy60-zw ~]# ping taobao.com
PING taobao.com (10.0.0.200) 56(84) bytes of data.
64 bytes from taobao.com (10.0.0.200): icmp_seq=1 ttl=64 time=0.075 ms
64 bytes from taobao.com (10.0.0.200): icmp_seq=2 ttl=64 time=0.088 ms
^C
--- taobao.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 999ms
rtt min/avg/max/mdev = 0.075/0.081/0.088/0.011 ms
8.查看与修改环境变量
PATH内存放的是命令的路径
环境变量的特点
1.有系统创建好的,可以随意使用的,存放系统信息
2.名称一般都是大写字母组成1.env 查看环境变量
[root@oldboy60-zw etc]# env
XDG_SESSION_ID=1
HOSTNAME=oldboy60-zw
SELINUX_ROLE_REQUESTED=
TERM=xterm
SHELL=/bin/bash
HISTSIZE=1000
SSH_CLIENT=10.0.0.1 58768 22
SELINUX_USE_CURRENT_RANGE=
SSH_TTY=/dev/pts/0
USER=root
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=01;05;37;41:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=01;36:*.au=01;36:*.flac=01;36:*.mid=01;36:*.midi=01;36:*.mka=01;36:*.mp3=01;36:*.mpc=01;36:*.ogg=01;36:*.ra=01;36:*.wav=01;36:*.axa=01;36:*.oga=01;36:*.spx=01;36:*.xspf=01;36:
MAIL=/var/spool/mail/root
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
PWD=/etc
LANG=en_US.UTF-8
SELINUX_LEVEL_REQUESTED=
HISTCONTROL=ignoredups
SHLVL=1
HOME=/root
LOGNAME=root
SSH_CONNECTION=10.0.0.1 58768 10.0.0.200 22
LESSOPEN=||/usr/bin/lesspipe.sh %s
XDG_RUNTIME_DIR=/run/user/0
_=/usr/bin/env
OLDPWD=/etc/profile.d
- 2.$与echo配合显示变量
[root@oldboy60-zw etc]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
- 修改环境变量
[root@oldboy60-zw ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@oldboy60-zw ~]# PATH=/sbin
[root@oldboy60-zw ~]# echo $PATH
/sbin
9.别名
- alias 查看别名
[root@oldboy60-zw etc]# alias
alias cp='cp -i'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias rm='rm -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
10.运行级别
-
- CentOS 6.x/5.x查看修改配置文件/etc/inittab
2.CentOS 7
查看修改运行级别
[root@oldboy60-zw ~]# systemctl get-default
multi-user.target
[root@oldboy60-zw ~]# systemctl set-default
basic.target graphical.target local-fs-pre.target poweroff.target runlevel2.target sockets.target
bluetooth.target halt.target local-fs.target printer.target runlevel3.target sound.target
cryptsetup-pre.target hibernate.target machines.target reboot.target runlevel4.target suspend.target
cryptsetup.target hybrid-sleep.target multi-user.target remote-cryptsetup.target runlevel5.target swap.target
ctrl-alt-del.target initrd-fs.target network-online.target remote-fs-pre.target runlevel6.target sysinit.target
default.target initrd-root-fs.target network-pre.target remote-fs.target shutdown.target system-update.target
emergency.target initrd-switch-root.target network.target rescue.target sigpwr.target timers.target
final.target initrd.target nss-lookup.target rpcbind.target sleep.target time-sync.target
getty-pre.target iprutils.target nss-user-lookup.target runlevel0.target slices.target umount.target
getty.target kexec.target paths.target runlevel1.target smartcard.target
[root@oldboy60-zw ~]# systemctl set-default runlevel5.target
Removed symlink /etc/systemd/system/default.target.
Created symlink from /etc/systemd/system/default.target to /usr/lib/systemd/system/graphical.target.
[root@oldboy60-zw ~]# systemctl get-default
graphical.target
- 运行级别说明
CentOS5/6 runlevel
运行模式:
服务器的不同状态
0 关机状态
1 单用户模式 无网络,一般用来重置root密码
2 多用户模式 没有NFS
3 完全多用户模式/文本模式/命令行模式
4 没有使用/待开发
5 图形化模式/桌面模式/X11
6 重启
CentOS7 target
[root@oldboyedu-zw ~]# ls -l /usr/lib/systemd/system/runlevel*.target
/usr/lib/systemd/system/runlevel0.target -> poweroff.target 关机
/usr/lib/systemd/system/runlevel1.target -> rescue.target 救援模式
/usr/lib/systemd/system/runlevel2.target -> multi-user.target 多用户模式
/usr/lib/systemd/system/runlevel3.target -> multi-user.target 多用户模式
/usr/lib/systemd/system/runlevel4.target -> multi-user.target 多用户模式
/usr/lib/systemd/system/runlevel5.target -> graphical.target 图形化
/usr/lib/systemd/system/runlevel6.target -> reboot.target 重启
11.开机自动挂载列表/etc/fstab
[root@oldboy60-zw etc]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Thu Mar 21 14:42:29 2019
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=70519035-8ccc-439b-9cae-1a8aa68e4b4f / xfs defaults 0 0
UUID=b819bdfc-60b4-4a2c-abf0-a7d014362c7e /boot xfs defaults 0 0
UUID=f3c94fdc-0f06-471e-b549-740a327888f3 swap swap defaults 0 0
[root@oldboy60-zw etc]# blkid
/dev/sda1: UUID="b819bdfc-60b4-4a2c-abf0-a7d014362c7e" TYPE="xfs"
/dev/sda2: UUID="f3c94fdc-0f06-471e-b549-740a327888f3" TYPE="swap"
/dev/sda3: UUID="70519035-8ccc-439b-9cae-1a8aa68e4b4f" TYPE="xfs"
/dev/sr0: UUID="2018-11-25-23-54-16-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos"
12./etc/rc.local 开机自运行脚本/命令
- 完整路径为:/etc/rc.d/rc.local
- 在CentOS 7 中第一次运行前需执行chmod +x /etc/rc.d/rc.local
[root@oldboy60-zw etc]# chmod +x /etc/rc.d/rc.local
[root@oldboy60-zw etc]# ll /etc/rc.d/rc.local
-rwxr-xr-x. 1 root root 473 Oct 31 07:31 /etc/rc.d/rc.local
[root@oldboy60-zw etc]# vim /etc/rc.local
13.修改登录前后自动显示的内容
- /etc/motd --用户登录后显示的内容
- /etc/issue /etc/issue.net --用户登录之前显示的内容, 一般选择清空
14.特殊符号--重定向/输出符号 >
- 与cat 和 echo配合使用
- >符号特点为 先清空再写入
- >>追加重定向 不清空 把信息追加写入到文件的结尾
- 向文件内追加多行内容
cat >>/oldboy/lianxi1.txt<
- 需要注意两个EOF大小写需完全一致
15./var/log 日志存放目录
- /var/log/secure 用户登录的信息
- /var/log/messages 服务与系统的信息
16./proc/
1./proc/cpuinfo --CPU信息
- cat /proc/cpuinfo
[root@oldboy60-zw ~]# cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 158
model name : Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
stepping : 9
microcode : 0x84
cpu MHz : 2808.001
cache size : 6144 KB
physical id : 0
siblings : 1
core id : 0
cpu cores : 1
apicid : 0
initial apicid : 0
fpu : yes
fpu_exception : yes
cpuid level : 22
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch epb fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid rdseed adx smap xsaveopt xsavec xgetbv1 dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp
bogomips : 5616.00
clflush size : 64
cache_alignment : 64
address sizes : 42 bits physical, 48 bits virtual
power management:
processor : 1
vendor_id : GenuineIntel
cpu family : 6
model : 158
model name : Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
stepping : 9
microcode : 0x84
cpu MHz : 2808.001
cache size : 6144 KB
physical id : 2
siblings : 1
core id : 0
cpu cores : 1
apicid : 2
initial apicid : 2
fpu : yes
fpu_exception : yes
cpuid level : 22
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch epb fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid rdseed adx smap xsaveopt xsavec xgetbv1 dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp
bogomips : 5616.00
clflush size : 64
cache_alignment : 64
address sizes : 42 bits physical, 48 bits virtual
power management:
- lscpu
[root@oldboy60-zw ~]# lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 2 ---核心数
On-line CPU(s) list: 0,1
Thread(s) per core: 1
Core(s) per socket: 1
Socket(s): 2 ---物理CPU个数
NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 158
Model name: Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
Stepping: 9
CPU MHz: 2808.001
CPU max MHz: 0.0000
CPU min MHz: 0.0000
BogoMIPS: 5616.00
Hypervisor vendor: VMware
Virtualization type: full
L1d cache: 32K
L1i cache: 32K
L2 cache: 256K
L3 cache: 6144K
NUMA node0 CPU(s): 0,1
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch epb fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid rdseed adx smap xsaveopt xsavec xgetbv1 dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp
2./proc/meminfo --内存信息
- 查看内存信息的命令free -h
[root@oldboy60-zw oldboy]# free -h
total used free shared buff/cache available
Mem: 1.9G 140M 1.6G 9.5M 158M 1.6G
Swap: 1.0G 0B 1.0G
3./proc/loadavg --平均负载
- 常见命令
[root@oldboy60-zw oldboy]# w
16:19:47 up 1:31, 1 user, load average: 0.00, 0.01, 0.05
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/0 10.0.0.1 14:48 3.00s 0.62s 0.05s w
[root@oldboy60-zw oldboy]# uptime
16:19:50 up 1:31, 1 user, load average: 0.00, 0.01, 0.05
[root@oldboy60-zw ~]# cat /proc/loadavg
0.00 0.05 0.05 1/133 7276
- 如果负载数值接近总CPU核心数则表示系统负载高
4./proc/mounts --挂载信息
知识点
- Linux一切从根开始
- Linux下面的目录是一个有层次的倒挂树状结构
- Linux下面的设备必须要有挂载才能使用
- Linux每个目录可以挂载到不同的设备上
- CentOS 7 系统管理命令 systemctl 全称system control
- Linux下常见的软件安装方式
1.yum 需要连接网络
2.rpm 无网络时使用
3.编译安装 - CPU(s) 表示CPU核心数
- Socket(s) 表示物理CPU个数
- processor : 1 第2个核心
- physical id : 1 第2个CPU
- 网卡配置文件
- /etc /sysconfig /network-scripts /ifcfg-ens33
- /系统配置文件/system configure/网络-脚本(管理网卡的命令)/interface configure - ens33