linux删除目录不弹出y,Linux目录、文件的创建与删除

目录的创建:

mkdir - make directories

使用示例及说明:[root@localhost ~]# mkdir /root/x/y/z

mkdir: cannot create directory `/root/x/y/z': No such file or directory

如果直接创建层级目录,是不能创建的。[root@localhost ~]# mkdir -p /root/x/y/z

如果带上“-p”就可以了,“-p”的意思是如果父目录不存在则创建父目录。[root@localhost ~]# tree /root

/root

|-- Desktop

|-- anaconda-ks.cfg

|-- install.log

|-- install.log.syslog

`-- x

`-- y

`-- z

4 directories, 3 files

tree命令可以查看目录树状结构。[root@localhost ~]# mkdir -pv /root/test/{x/y,z}

mkdir: created directory `/root/test'

mkdir: created directory `/root/test/x'

mkdir: created directory `/root/test/x/y'

mkdir: created directory `/root/test/z'

说明:/root/test/{x/y,z}等于/root/test/x/y /root/test/z}

-v:当创建目录后显示信息。[root@localhost ~]# rmdir -p /root/x/y/z

rmdir: /root: Directory not empty

说明:rmdir用于删除空目录,如果目录非空则不能删除;

-p:用于删除目录和它的父目录(如果父目录是空的),此为选项。

可以从本例中看出,删除z目录时,x和y目录一并被删除,但是因为/root非空无法将其删除。

可以通过tree命令查看:[root@localhost ~]# tree /root

/root

|-- Desktop

|-- anaconda-ks.cfg

|-- install.log

|-- install.log.syslog

`-- test

|-- x

|   `-- y

`-- z

5 directories, 3 files

从本例可以看出/root非空。

***********************分割线*************************

文件的创建于删除:[root@localhost ~]# touch /root/test/hello

[root@localhost ~]# ls -l /root/test/hello

-rw-r--r-- 1 root root 0 Dec  7 03:42 /root/test/hello

touch本来的用途是用来修改文件的时间戳,却同时也可以用来创建空文件,如上例所示:

用# touch /root/test/hello创建了hello空文件,用ls -l /root/test/hello可以查看hello文件信息;

同时也可以使用stat查看文件状态:[root@localhost ~]# stat /root/test/hello

File: `/root/test/hello'

Size: 0         Blocks: 8          IO Block: 4096   regular empty file

Device: fd00h/64768dInode: 29851728    Links: 1

Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)

Access: 2014-12-07 03:42:22.000000000 +0800

Modify: 2014-12-07 03:42:22.000000000 +0800

Change: 2014-12-07 03:42:22.000000000 +0800

可以看到hello的的访问(access)、修改(modify)、change(改变)时间一样;[root@localhost test]# touch -a hello

[root@localhost test]# stat hello

File: `hello'

Size: 0         Blocks: 8          IO Block: 4096   regular empty file

Device: fd00h/64768dInode: 29851728    Links: 1

Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)

Access: 2014-12-07 03:51:22.000000000 +0800

Modify: 2013-12-07 12:50:30.000000000 +0800

Change: 2014-12-07 03:51:22.000000000 +0800

使用-a选项可以修改文件的访问时间,同时改变时间也一并修改。

(注意我已经使用cd命令切换到了/test目录,所以才能直接把参数输入为“hello”)[root@localhost test]# touch -m -t 201312071250.30 hello

[root@localhost test]# stat hello

File: `hello'

Size: 0         Blocks: 8          IO Block: 4096   regular empty file

Device: fd00h/64768dInode: 29851728    Links: 1

Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)

Access: 2012-12-07 12:50:30.000000000 +0800

Modify: 2013-12-07 12:50:30.000000000 +0800

Change: 2014-12-07 03:47:35.000000000 +0800

说明:-m用来修改文件的修改时间

-t用来直接设置时间,如果没有则使用当前时间,格式:[[CC]YY]MMDDhhmm[.ss]

使用nano命令可以编辑文件,比较简单,大家可以自行尝试。

[root@localhost test]# rm hello

rm: remove regular empty file `hello'? y

rm命令用来删除文件。

删除后找不到hello文件了:[root@localhost test]# tree

.

|-- a_c

|-- a_d

|-- b_c

|-- b_d

|-- x

|   `-- y

`-- z

7 directories, 0 files

[root@localhost test]# rm -rf /root/test

选项-r递归地删除/test及其包含的所有文件和目录,

-f强制删除不提示。

可以看到/test目录已经没有了:[root@localhost ~]# tree

.

|-- Desktop

|-- anaconda-ks.cfg

|-- install.log

`-- install.log.syslog

1 directory, 3 files

谢谢!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值