Linux 文件目录管理(增删改剪切复制移动)操作

本章将学习一下几个知识点:
创建、修改、删除、更名、剪切、复制等操作

1.touch

创建空白文件或设置文件时间 touch [选项] [文件]

对于touch命令来讲,有难度在文件内容的修改时间 (mtime)文件权限 或属性的 更改时间(ctime) 与文件的 读取时间(atime)上面。touch参数及作用介绍如下:

参数 作用
-a 仅修改“读取时间”
-m 仅修改“修改时间”
-d 同时修改atime和mtime
[root@ikings ~]# touch test.txt     //创建空白文件test.txt
[root@ikings ~]# ls -l test.txt        //查看test.txt文件信息
-rw-r--r--. 1 root root 0 Oct 12 18:49 test.txt
[root@ikings ~]# touch -d "2018-10-12 15:00:00" test.txt  //修改文件的修改时间和读取时间
[root@ikings ~]# ls -l test.txt
-rw-r--r--. 1 root root 0 Oct 12 15:00 test.txt
[root@ikings ~]# 

2.mkdir

创建空白目录,mkdir [参数] 目录名称

-p 使用-p参数可以递归创建多层目录。

[root@ikings ~]# mkdir a  //创建空白目录a
[root@ikings ~]# mkdir -p a/b/c/d  //递归创建了多层目录

3.cp

复制文件或目录, cp [选项] 原文件 目标文件

复制操作分为三种情况:
)当目标文件是目录,则会将原文件复制到目标目录中;
)当目标文件是普通文件,则会询问是否覆盖目标文件;
)当目标文件不存在时,正常复制操作;

4.mv

剪切文件或文件重命名,mv [参数] 原文件 [目标路径|目标文件名]

注意:在同一个目录中,使用mv操作代表对文件进行重命名操作。

//查看当前目录文件
[root@ikings a]# ls -l
total 0
-rw-r--r--. 1 root root 0 Oct 12 19:17 test.txt
[root@ikings a]# 


//将test.txt重命名linux.txt
[root@ikings a]# mv test.txt linux.txt
[root@ikings a]# ls -l
total 0
-rw-r--r--. 1 root root 0 Oct 12 19:17 linux.txt
[root@ikings a]# 

//剪切到上一级目录
[root@ikings a]# mv linux.txt ~   //剪切到上一级目录
[root@ikings a]# ls -l  
total 0        //当前a目录中的linux.txt被删除了
[root@ikings a]# cd ~   //返回到上一级目录
[root@ikings ~]# ls -l    //查看当前目录
total 8
drwxr-xr-x. 2 root root    6 Oct 12 19:21 a
-rw-------. 1 root root 1523 Oct 10 20:03 anaconda-ks.cfg
drwxr-xr-x. 2 root root    6 Oct 10 22:50 Desktop
drwxr-xr-x. 2 root root    6 Oct 10 22:50 Documents
drwxr-xr-x. 2 root root    6 Oct 10 22:50 Downloads
-rw-r--r--. 1 root root 1554 Oct 10 22:11 initial-setup-ks.cfg
-rw-r--r--. 1 root root    0 Oct 12 19:17 linux.txt  //剪切到当前目录中
drwxr-xr-x. 2 root root    6 Oct 10 22:50 Music
drwxr-xr-x. 2 root root    6 Oct 10 22:50 Pictures
drwxr-xr-x. 2 root root    6 Oct 10 22:50 Public
drwxr-xr-x. 2 root root    6 Oct 10 22:50 Templates
-rw-r--r--. 1 root root    0 Oct 12 15:00 test.txt
drwxr-xr-x. 2 root root    6 Oct 10 22:50 Videos
[root@ikings ~]# 


5.rm

删除文件或目录,rm [参数] 文件

linux系统在执行删除操作时,默认会询问您是否执行删除操作。如果不想总是反复确认删除信息,可以加-f参数来强制删除。
删除目录需要使用-r,否则不不能目录。

//删除目录
[root@ikings ~]# rm -r a    //删除a目录。
[root@ikings ~]# rm -fr a    //删除a目录,并且忽略确认提示。
[root@ikings ~]# rm test.txt  //删除tes.txt文件。
[root@ikings ~]# rm -f test.txt  //删除tes.txt文件,并且忽略确认提示。

6.dd

按照自定大小和个数的数据块来复制文件或转换文件,dd [参数]

7.file

查看文件的类型,file 文件名

在Linux系统中,文件目录设备文件都统称为文件,而我们不能单凭文件的后缀就知道具体的文件类型,这时就需要使用 file命令来查看文件类型了。

[root@ikings ~]# file a
a: directory    //directory  a: 目录
[root@ikings ~]# 

//
[root@ikings ~]# file anaconda-ks.cfg
anaconda-ks.cfg: ASCII text
[root@ikings ~]# 

你可能感兴趣的:(Linux 文件目录管理(增删改剪切复制移动)操作)