创建、删除文件和目录:mkdir / rm / rmdir 0 个改进

mkdir 用于创建新的空目录:

[ andrew@pc01 ex ]$ ls && mkdir c && ls
a  b
a  b  c

你可以使用 rm 删除任何文件——但是要注意,这是不可恢复的!

[ andrew@pc01 ex ]$ rm a && ls
b  c

你可以使用 -i 标签来询问用户是否删除:

[ andrew@pc01 ex ]$ rm -i b
rm: remove regular empty file 'b'? y

使用 rmdir 删除一个空目录。如果你在空目录下使用命令 ls -a ,你应该只能看到对目录本身的引用 . 和对其父目录的引用 ..

[ andrew@pc01 ex ]$ rmdir c && ls -a
.  ..

rmdir 仅删除空目录:

[ andrew@pc01 ex ]$ cd .. && ls test/
*.txt  0.txt  1.txt  a  a.txt  b  c

[ andrew@pc01 ~ ]$ rmdir test/
rmdir: failed to remove 'test/': Directory not empty

但是你可以使用 rm -rf 删除目录及其目录下所有内容( -r = 递归,-f = 强制):

[ andrew@pc01 ~ ]$ rm –rf test

参考:https://dev.to/awwsmm/101-bash-commands-...

本文为 Wiki 文章,邀您参与纠错、纰漏和优化
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!