美文网首页Hyman7和他的Linux学习之路
Day04-CentOS7文件管理常用命令

Day04-CentOS7文件管理常用命令

作者: 郝煜_Hyman | 来源:发表于2019-07-30 20:01 被阅读36次

复制 [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.忽略大小写方式

相关文章

  • Linux常用命令

    常用命令 文件管理cp,rm,mv

  • Day04-CentOS7文件管理常用命令

    复制 [cp] 1.基础语法使用 2.复制并重新命名 3.保持原有的属性不变 [-p] 4.递归复制 [-r...

  • Kubectl 常用命令

    常用命令 YAML配置文件管理对象

  • Linux 常用命令(二)

    Linux常用命令(二) Linux文件管理 Linux的文件层次标准 Filesystem Hierarchy ...

  • kubernetes

    kubernetes 安装 常用命令 命令发布nginx ymal配置文件管理 pod的管理 service的管理...

  • Note-git 常用命令

    git 常用命令 初始化仓库 常用命令 大小写敏感 如果报错,可查看文末异常处理 分支管理 tag 管理 文件操作...

  • Linux 常用命令 文件目录管理之touch

    常用命令:文件目录管理 touch 1.命令touch -- 创建文件,改变文件的访问时间和修改时间。 2.使用样...

  • Linux学习

    Linux文件目录 ls常用选项 文本查看常用命令 tar命令 账号管理命令 useradd [username]...

  • php的学习路程

    一.Linux方面 Linux常用命令 1. 文件处理命令 2. 权限管理命令 3. 帮助命令 4. 文件搜索命令...

  • 2018-01-28

    git学习笔记 根据廖雪峰老师教程学习整理的常用命令 git版本库创建 文件管理相关 远程库 分支管理 bug修复...

网友评论

    本文标题:Day04-CentOS7文件管理常用命令

    本文链接:https://www.haomeiwen.com/subject/tvubrctx.html