Linux之day7 文件目录管理命令

在linux系统的日常运维工作中,需要掌握文件的创建、修改、复制、剪贴、更名与删除等操作。

1.touch

用于创建空白文件或者设置文件的时间

格式:touch 选项 文件

参数:

-a 仅修改读取时间

-b 仅修改修改时间

-d 同时修改atime与mtime

[root@linuxprobe ~]# ls -l anaconda-ks.cfg
-rw-------. 1 root root 1241 May 25 03:53 anaconda-ks.cfg
[root@linuxprobe ~]# echo "Visit the LinuxProce.com to learn linux skills">>anacoda-ks.cfg
[root@linuxprobe ~]# ls -l anaconda-ks.cfg
-rw-------. 1 root root 1241 May 25 03:53 anaconda-ks.cfg
[root@linuxprobe ~]# touch -d "2017-02-04 15:44" anaconda-ks.cfg
[root@linuxprobe ~]# ls -l anaconda-ks.cfg
-rw-------. 1 root root 1241 Feb  4  2017 anaconda-ks.cfg

2. mkdir

用于创建空白目录

格式:mkdir 选项 目录

[root@linuxprobe ~]# mkdir linuxprobe
[root@linuxprobe ~]# cd linuxprobe
[root@linuxprobe linuxprobe]# mkdir -p a/b/c/d/e
[root@linuxprobe linuxprobe]# cd a
[root@linuxprobe a]# cd b
[root@linuxprobe b]# 

3.cp

用于复制文件或目录

cp 选项 源文件 目标文件

->如果目标文件是目录,则会把源文件复制到该目录中

->如果目标文件是也是普通文件,则会询问是否要覆盖它

->如果目标文件不存在,则执行正常复制操作

参数:

-p 保留原始文件的属性

-d 若对象为链接文件,则保留该链接文件的属性

-r 递归持续复制(用于目录)

-i 若目标文件存在则询问是否覆盖

-a 相当于-pdr 

[root@linuxprobe ~]# touch install.log
[root@linuxprobe ~]# cp install.log x.log
[root@linuxprobe ~]# ls
anacoda-ks.cfg   initial-setup-ks.cfg  linuxprobe
anaconda-ks.cfg  install.log           x.log

4.mv

用于剪贴文件或将文件重命名

格式:mv 选项 源文件 [目标路径|目标文件名]

[root@linuxprobe ~]# mv x.log linux.log
[root@linuxprobe ~]# ls
anacoda-ks.cfg   initial-setup-ks.cfg  linux.log
anaconda-ks.cfg  install.log           linuxprobe

5.rm

用于删除文件或目录

格式:rm选项 文件

[root@linuxprobe ~]# rm install.log
rm: remove regular empty file ‘install.log’? y
[root@linuxprobe ~]# rm -f linux.log
[root@linuxprobe ~]# ls
anacoda-ks.cfg  anaconda-ks.cfg  initial-setup-ks.cfg  linuxprobe

6.dd

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

格式:dd 参数

参数

if 输入的文件名称

of 输出的文件名称

bs 设置每个块的大小

count 设置要复制块的个数

[root@linuxprobe ~]# dd if=/dev/zero of=560_file count=1 bs=560M
1+0 records in
1+0 records out 
1+0 records in
1+0 records out
587202560 bytes (587 MB) copied, 100.326 s, 5.9 MB/s

如果想把光驱设备中的光盘制作成iso格式的镜像文件

[root@linuxprobe ~]# dd if=/dev/cdrom of=REHL-server-7.0-x86_6-linuxProbe.Com.iso
7311360+0 records in
7311360+0 records out
3743416320 bytes (3.7 GB) copied, 150.751 s, 24.8 MB/s

7.file命令

file命令用于查看文件类型

格式:file 文件名

[root@linuxprobe ~]# file anaconda-ks.cfg
anaconda-ks.cfg: ASCII text
[root@linuxprobe ~]# file /dev/sda
/dev/sda: block special

猜你喜欢

转载自blog.csdn.net/dop102/article/details/80651676