集团主站
欢迎来到成都达内官方网站!达内—美国上市公司 亿元级外企IT培训企业!
成都it培训哪家好
成都it培训哪家好
全国服务监督电话:400-111-8989  |   联系客服   |
当前位置:主页 > 培训课程 > Linux >

成都linux云计算培训班:文件目录管理命令

发布者: 成都达内     浏览次数:     发布时间:2021-04-14 10:30:18

成都linux云计算培训班:touch命令用于创建空白文件或设置文件的时间,语法格式为:“touch [参数] 文件名称...

  touch命令用于创建空白文件或设置文件的时间,语法格式为:“touch [参数] 文件名称

  [root@localhost mnt]# ls

  [root@localhost mnt]# touch bing

  [root@localhost mnt]# ls

  bing

  # vim linux 使用vim编辑一个不存在的文件,修改保存后,该会自动建立

  [root@localhost mnt]# vim linux

  [root@localhost mnt]# ls

  bing linux

  --------------------------------------------------------------------------------------------------------------

  mkdir命令用于创建空白的目录,英文全称为:“make directory”,语法格式为:“mkdir [参数] 目录名称”

  [root@localhost mnt]# mkdir linux-b

  [root@localhost mnt]# ls

  bing linux linux-b

  mkdir -p /mnt/linux-c/bing/geely/7dct 创建递增层次的文件

  [root@localhost mnt]# mkdir -p /mnt/linux-c/bing/geely/7dct

  [root@localhost mnt]# ls

  bing linux linux-b linux-c

  [root@localhost mnt]# cd /mnt/linux-c/bing/geely/7dct

  [root@localhost 7dct]# pwd

  /mnt/linux-c/bing/geely/7dct

  --------------------------------------------------------------------------------

  cp命令用于复制文件或目录,英文全称为:“copy”,语法格式为:“cp [参数] 源文件名称 目标文件名称”

  语法: cp 源… 目的

  复制目录时,多个-r 选项:

  # cp -r newdir/ /tmp/ 目标目录存在,则将源目录放在该目录下

  # cp -r newdir /tmp/olddir 目标目录不存在,类似复制过去后重命名

  # cp -r /run/media/admin/RHEL-7.0Server.x86_64/. /mnt/redhat7/ 复制/run/media/admin/RHEL-7.0Server.x86_64/下所有文件到/mnt/redhat7/下

  [root@localhost mnt]# ls

  bing linux linux-b linux-c

  [root@localhost mnt]# cp bing bing1

  [root@localhost mnt]# ls

  bing bing1 linux linux-b linux-c

  [root@localhost mnt]# cp -r linux-b /mnt/linux-c

  [root@localhost mnt]# cd linux-c

  [root@localhost linux-c]# ls

  bing linux-b

  --------------------------------------------------------------------------------

  mv命令用于剪切或重命名文件,英文全称为:“move”,语法格式为:“mv [参数] 源文件名称 目标文件名称”

  [root@localhost mnt]# ls

  bing bing1 linux linux-b linux-c

  [root@localhost mnt]# mv bing1 bing2

  [root@localhost mnt]# ls

  bing bing2 linux linux-b linux-c

  [root@localhost mnt]# mv bing2 /mnt/linux-b

  [root@localhost mnt]# cd linux-b

  [root@localhost linux-b]# ls

  bing2

  --------------------------------------------------------------------------------

  rm命令用于删除文件或目录,英文全称为:“remove”,语法格式为:“rm [参数] 文件名称”

  rm -f 强制删除文件

  rm -rf 强制删除目录文件

  [root@localhost mnt]# rm linux

  rm: remove regular file 'linux'? y

  [root@localhost mnt]# ls

  bing linux-b linux-c

  [root@localhost mnt]# rm -f bing

  [root@localhost mnt]# ls

  linux-b linux-c

  [root@localhost mnt]# rm -rf linux-b

  [root@localhost mnt]# ls

  linux-c

  --------------------------------------------------------------------------------

  dd命令用于按照指定大小的数据块个数来复制文件或转换文件

  if input file 输入文件

  of output file 输出文件

  bs 设置每个“块”的大小

  count 设置要复制“块”的个数

  语法格式为:“dd if=参数值 of=参数值 count=参数值 bs=参数值”

  --------------------------------------------------------------------------------

  file命令用于查看文件的类型,语法格式为:“file 文件名称”

  [root@localhost mnt]# file linux-c/

  linux-c/: directory

  --------------------------------------------------------------------------------

  (考试命令tar)

  tar命令用于对文件进行打包压缩或解压,语法格式为:“tar 参数 文件名称

  [root@localhost mnt]# tar czvf etc.tar.gz /etc

  [root@localhost mnt]# ls

  etc.tar.gz linux-c

  z ---tar.gz

  j ---tar.bz2

  tar czvf 压缩包.tar.gz

  tar xjvf 压缩包.tar.bz2

  参数 作用

  -c 创建压缩文件

  -x 解开压缩文件

  -t 查看压缩包内有哪些文件

  -z 用Gzip压缩或解压

  -j 用bzip2压缩或解压

  -v 显示压缩或解压的过程

  -f 目标文件名

  -p 保留原始的权限与属性

  -P 使用绝对路径来压缩

  -C 指定解压到的目录

  --------------------------------------------------------------------------------

  grep命令用于在文本中执行关键词搜索,并显示匹配的结果,格式为“grep [选项] [文件]”

  [root@localhost mnt]# grep /sbin/nologin /etc/passwd

  bin:x:1:1:bin:/bin:/sbin/nologin

  ........

  [root@localhost mnt]# grep -c /sbin/nologin /etc/passwd

  48

  参数 作用

  -b 将可执行文件(binary)当作文本文件(text)来搜索

  -c 仅显示找到的行数

  -i 忽略大小写

  -n 显示行号

  -v 反向选择——仅列出没有“关键词”的行。

  --------------------------------------------------------------------------------

  find命令用于按照指定条件来查找文件,格式为“find [查找路径] 寻找条件 操作”

  [root@localhost mnt]# find /etc -name "host*" -print

  /etc/opa/hosts

  /etc/host.conf

  /etc/hosts

  /etc/hosts.allow

  /etc/hosts.deny

  /etc/avahi/hosts

  /etc/hostname

  ---------------------------------------------------

  重定向符(<、<<、>、>>) 命令与文件的关系

  管道符 ( | ) 命令与命令的关系

  输入重定向(文件到命令)

  命令 < 文件 将文件作为命令的标准输入

  命令 << 分界符 从标准输入中读入,直到遇见分界符才停止

  -------------------------------

  输出重定向(命令到文件)

  符号 作用

  命令 > 文件 将标准输出重定向到一个文件中(清空写入 )

  命令 2> 文件 将错误输出重定向到一个文件中(追加写入)

  命令 >> 文件 将标准输出重定向到一个文件中(清空写入 )

  命令 2>> 文件 将错误输出重定向到一个文件中(追加写入)

  命令 &> 文件 将标准输出与错误输出共同写入到文件中(清空写入 )

  命令 &>> 文件 将标准输出与错误输出共同写入到文件中(追加写入 )

  [root@localhost mnt]# ls -l > test

  [root@localhost mnt]# cat test

  total 6548

  -rw-r--r--. 1 root root 6701472 Apr 10 12:49 etc.tar.gz

  drwxr-xr-x. 4 root root 33 Apr 10 12:31 linux-c

  -rw-r--r--. 1 root root 0 Apr 10 13:12 test

  [root@localhost mnt]# ls -l bing > test

  ls: cannot access 'bing': No such file or directory

  [root@localhost mnt]# ls -l bing 2> test

  [root@localhost mnt]# cat test

  ls: cannot access 'bing': No such file or directory

  [root@localhost mnt]# ls -l 2> test

  total 6548

  -rw-r--r--. 1 root root 6701472 Apr 10 12:49 etc.tar.gz

  drwxr-xr-x. 4 root root 33 Apr 10 12:31 linux-c

  -rw-r--r--. 1 root root 0 Apr 10 13:14 test

  [root@localhost mnt]# cat test

  [root@localhost mnt]#

  [root@localhost mnt]# ls -l &>> test

  [root@localhost mnt]# ls -l geely &>> test

  [root@localhost mnt]# cat test

  ls: cannot access 'geely': No such file or directory

  total 6552

  -rw-r--r--. 1 root root 6701472 Apr 10 12:49 etc.tar.gz

  drwxr-xr-x. 4 root root 33 Apr 10 12:31 linux-c

  -rw-r--r--. 1 root root 53 Apr 10 13:18 test

  ls: cannot access 'geely': No such file or directory

  ------------------------------------------------------------

  管道符

  grep /sbin/nologin /etc/passwd | wc -l

  grep搜索命令的输出值传递给wc统计命令,即把原本要输出到屏幕的用户信息列表再交给wc命令作进一步的加工

  [root@localhost mnt]# grep -c /sbin/nologin /etc/passwd

  48

  [root@localhost mnt]# grep /sbin/nologin /etc/passwd | wc -l

  48

  把管道符和passwd命令的--stdin参数相结合,可以用一条命令来完成密码重置操作

  echo "root" | passwd --stdin root

  [root@localhost mnt]# echo "root" | passwd --stdin root

  Changing password for user root.

  passwd: all authentication tokens updated successfully.

(责任编辑:范老师)
下一篇:没有了
相关文章
最新开班
  • 成都Java培训班
    免费试听名额发放中...
  • 成都C++培训班
    免费试听名额发放中...
  • 成都PHP培训班
    免费试听名额发放中...
  • 成都网络工程培训班
    免费试听名额发放中...
  • 成都Unity3D培训班
    免费试听名额发放中...
  • 成都大数据培训班
    免费试听名额发放中...
  • 成都uid培训班
    免费试听名额发放中...
  • 成都会计培训班
    免费试听名额发放中...
  • 成都Python培训班
    免费试听名额发放中...
  • 成都嵌入式培训班
    免费试听名额发放中...
  • 成都web培训班
    免费试听名额发放中...
  • 成都软件测试培训班
    免费试听名额发放中...
在线留言
提交

校区地址:成都市锦江区东大街紫东楼端35号明宇金融广场19楼1906室

联系电话:400-111-8989

公交路线:芷泉街(18路;21路;43路;48路;104路;152路;335路 ) 地铁路线:东门大桥站(地铁2号线)

校区地址:成都市高新区奥克斯广场蜀锦路209号一楼商铺

联系电话:400-111-8989

公交路线:益州大道锦城大道口(18路;21路;43路;48路;104路;152路;335路 ) 地铁路线:孵化园(地铁1号线)

校区地址:成都锦江区东大街芷泉街229号东方广场C座3楼303

联系电话:400-111-8989

公交路线:芷泉街(188路;115路;515路;236路;505路;501路;84路 ) 地铁路线:东门大桥站(地铁2号线)

校区地址:成都市武侯区佳灵路3号红牌楼广场2号写字楼11楼1115号

联系电话:400-111-8989

公交路线:红牌楼东(11路;92路;100路;111路;139路;g28路;快速公交K1/K2) 地铁路线:红牌楼站(地铁3号线)

校区地址:成都市锦江区红星路二段70号四川日报大厦502-2

联系电话:400-111-8989

公交路线:市二医院站(6路;49路;102路;5路;37路;g92路;) 地铁路线:地铁市二医院(地铁3号线)

校区地址:成都市锦江区东大街芷泉段229号东方广场C座16层

联系电话:400-111-8989

公交路线:芷泉街(18路;21路;43路;48路;104路;152路;335路 ) 地铁路线:东门大桥站(地铁2号线)

校区地址:四川省成都市武侯区高新科技孵化园9号园区E座7楼

联系电话:400-111-8989

公交路线:益州大道锦城大道口(18路;21路;43路;48路;104路;152路;335路 ) 地铁路线:孵化园(地铁1号线)

了解达内动态
关注成都达内教育公众号

首页 | 关于达内 | 课程中心 | 专家师资 | 视频教程 | 学员空间 | 校企合作 | 新闻资讯 | 就业指导 | 网站地图

2016-2025 达内时代科技集团有限公司 版权所有 京ICP证8000853号-56 蜀ICP备18021046号-3