复制 [cp]
1.基础语法使用
[root@hyman-123 ~]# cp file1 /tmp/
2.复制并重新命名
[root@hyman-123 ~]# touch haoyu123
[root@hyman-123 ~]# cp haoyu123 haoyu456
[root@hyman-123 ~]# ls
123.txt aa.sh anaconda-ks.cfg haoyu123 haoyu456 hy123 old pass
3.保持原有的属性不变 [-p]
[root@hyman-123 ~]# cp haoyu123 /tmp
[root@hyman-123 ~]# ll /tmp/haoyu123
-rwxr-xr-x. 1 root root 0 Jul 29 15:24 /tmp/haoyu123
[root@hyman-123 ~]# cp -p haoyu123 /tmp
cp: overwrite ‘/tmp/haoyu123’? y
[root@hyman-123 ~]# ll /tmp/haoyu123
-rwxrwxrwx. 1 abc adc 0 Jul 29 15:15 /tmp/haoyu123
4.递归复制 [-r]
mkdir -p haoyu1/haoyu2/haoyu3
[root@hyman-123 ~]# cd haoyu1/haoyu2/haoyu3
[root@hyman-123 haoyu3]# pwd
/root/haoyu1/haoyu2/haoyu3
[root@hyman-123 ~]# cp haoyu1 haoyu2
cp: omitting directory ‘haoyu1’
[root@hyman-123 ~]# cp -r haoyu1 haoyu2
5.显示详细的复制信息(过程) [-v]
‘haoyu1’ -> ‘haoyu2/haoyu1’
‘haoyu1/haoyu2’ -> ‘haoyu2/haoyu1/haoyu2’
‘haoyu1/haoyu2/haoyu3’ -> ‘haoyu2/haoyu1/haoyu2/haoyu3’
6.拷贝不同路径下的不同文件+不同的目录 至同一个位置,
[root@hyman-123 ~]# cp -rp file1 oldboy1/ file /etc/ /mnt/ /opt/
[root@hyman-123 ~]# ls
/opt/ etc file file1 mnt oldboy1
7.重复复制触发提示
[root@hyman-123 ~]# /bin/cp -r /etc/ /opt/
8.扩展项(复制绝对路径很长的文件时用)
[root@hyman-123 ~]# cp {file5,file5-bak} -v ‘file5’ -> ‘file5-bak’
[root@hyman-123 ~]# cp /etc/sysconfig/networkscripts/{ifcfg-ens32,ifcfg-ens32-bak}
文件管理-查看文件内容 (cat tac less more head tail grep)
cat
#查看文件的所以内容,从头到尾
[root@centos7-day1-10 ~]# cat pass
#查看一个文件有多少行 -n
[root@oldboyedu ~]# cat -n pass
#查看文件的特殊符号, 比如文件中存在tab键
[root@oldboyedu ~]# cat -A pass
cat扩展使用,创建一个文件,并往里写入内容
[root@hyman-123 ~]# cat >> test.txt <<EOF #EOF代表开 始
test1
test2
test3
EOF #EOF 代表结束
[root@hyman-123 ~]# cat test.txt
test1
test2
test3
less、more
less /etc/services #使用光标上下翻动,空格进行翻页,q退 出
more /etc/services #使用回车上下翻动,空格进行翻页,q退 出
head
[root@hyman-123 ~]# head pass #查看头部内容,默认前十行
[root@hyman-123 ~]# head -n5 pass #查看头部5行,使用-n指定
[root@hyman-123 ~]# ps aux | head -5 #了解
tail
tail pass
#查看文件尾部默认十行
[root@hyman-123 ~]# tail -20 /var/log/secure
[root@hyman-123 ~]# tail -f /var/log/messages # -f 查看文 件尾部的变化
[root@hyman-123 ~]# tailf /var/log/messages #查看文件 尾部的变化
[root@hyman-123 ~]# ps aux | tail -5 #了解
grep过滤文件内容
#1. 过滤出pass文件中的root相关的行
[root@hyman-123 ~]# grep "root" pass
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
#2.过滤pass文件中,匹配以root开头的行
[root@hyman-123 ~]# grep "^root" pass
root:x:0:0:root:/root:/bin/bash
#3.过滤pass文件中,匹配以bash结尾的行
[root@hyman-123 ~]# grep "bash$" pass
root:x:0:0:root:/root:/bin/bash
jack:x:1000:1000::/home/jack:/bin/bash
#4.显示行号
[root@hyman-123 ~]# grep -n "bash$" pass
1:root:x:0:0:root:/root:/bin/bash
23:jack:x:1000:1000::/home/jack:/bin/bash
#5.扩展了解
grep -n -A 2 "Failed" /var/log/secure
#匹 配/var/log/secure文件中Failed字符串,并打印它的下2行
grep -n -B 2 "Failed" /var/log/secure
#匹 配/var/log/secure文件中Failed字符串,并打印它的上2行
grep -n -C 2 "Failed" /var/log/secure
#匹 配/var/log/secure文件中Failed字符串
#6.过滤出包含ftp的行
[root@hyman-123 ~]# grep "ftp" pass
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
#7.过滤除了ftp的行,其他的全部显示
[root@hyman-123 ~]# grep -v "ftp" pass
#8.忽略大小写方式
网友评论