linux常用命令 目录操作(cd,mkdir,rmdir,mv,cp,rm)

linux常用命令 目录操作(cd,mkdir,rmdir,mv,cp,rm)

cd

有一个特殊的目录被称为根目录,是整个文件系统形成的这棵树的根节点,在Linux系统中用一个单独的 “/”符号表示。
因此一个目录的绝对路径可以表示为“/d2/d3”这样的形式。
当前目录表示用户目前正在工作的目录。为了切换到文件系统中的某个目录,可以使用“cd”命令。
假设当前目录为“/d2/d3”,下图给出了cd命令的几种形式,以及执行命令之后的当前目录。
在这里插入图片描述

mkdir

mkdir // 创建文件夹(make directory)
语法 mkdir [目录名称]
eg: [root@localhost ~]# mkdir hello
	[root@localhost ~]# ls
	anaconda-ks.cfg  hello
	[root@localhost ~]# 
mkdir -p //通过递归创建多级目录
eg: [root@localhost ~]# mkdir -p k1/k2
	[root@localhost ~]# ls
	anaconda-ks.cfg  hello  k1
	[root@localhost ~]# 

rmdir

rmdir // 删除空文件夹(remove empty directory)
eg:	[root@localhost ~]# ls -lh
	total 12K
	-rw-------. 1 root root 1.5K Jan 19 20:27 anaconda-ks.cfg
	drwxr-xr-x. 2 root root 4.0K Jan 20 17:39 hello
	drwxr-xr-x. 3 root root 4.0K Jan 20 17:41 k1
	[root@localhost ~]# rmdir hello
	[root@localhost ~]# ls
	anaconda-ks.cfg  k1
	[root@localhost ~]# 

mv

mv // 剪切和重命名操作(move)
1.重命名
eg: [root@localhost ~]# ls
	anaconda-ks.cfg  hello  k1
	[root@localhost ~]# mv hello hi
	[root@localhost ~]# ls
	anaconda-ks.cfg  hi  k1
	[root@localhost ~]# 
2.剪切
	语法:mv [当前路径][目标路径]
eg :[root@localhost ~]# ls
	anaconda-ks.cfg  hello  k1
	[root@localhost ~]# mv k1 /tmp
	[root@localhost ~]# ls /tmp
	k1
	[root@localhost ~]# ls
	anaconda-ks.cfg  hello
	[root@localhost ~]# 

cp

cp //拷贝(copy)
	语法:cp [原文件或目录][目标目录]
			-r //复制目录
			-p //保留原文件属性
eg:拷贝文件夹
	[root@localhost ~]# ls
	anaconda-ks.cfg  hello
	[root@localhost ~]# ls /tmp
	k1
	[root@localhost ~]# cp /tmp/k1 /root
	cp: omitting directory ‘/tmp/k1’
	[root@localhost ~]# ls
	anaconda-ks.cfg  hello
	[root@localhost ~]# cp -r /tmp/k1 /root
	[root@localhost ~]# ls
	anaconda-ks.cfg  hello  k1
eg:保留原文件属性
	[root@localhost ~]# ls
	anaconda-ks.cfg  hello  k1
	[root@localhost ~]# ls -l
	total 12
	-rw-------. 1 root root 1462 Jan 19 20:27 anaconda-ks.cfg
	drwxr-xr-x. 2 root root 4096 Jan 20 17:45 hello //原时间
	drwxr-xr-x. 3 root root 4096 Jan 20 17:57 k1    //原时间
	[root@localhost ~]# cp -r hello /tmp
	[root@localhost ~]# cp -rp k1 /tmp
	[root@localhost ~]# ls -l /tmp
	total 8
	drwxr-xr-x. 2 root root 4096 Jan 20 18:04 hello //时间改变
	drwxr-xr-x. 3 root root 4096 Jan 20 17:57 k1	//时间仍然为原文件时间
	[root@localhost ~]# 

rm

rm //删除文件或文件夹(remove)
	语法:rm [文件或目录]
			-f //强制删除
			-r //删除文件夹
eg: [root@localhost ~]# ls /tmp
	hello  k1
	[root@localhost ~]# cp -r /tmp/hello /root
	[root@localhost ~]# ls
	anaconda-ks.cfg  hello  k1
	[root@localhost ~]# rm hello
	rm: cannot remove ‘hello’: Is a directory
	[root@localhost ~]# rm -r hello
	rm: remove directory ‘hello’? y
	[root@localhost ~]# rm -rf k1
	[root@localhost ~]# ls
	anaconda-ks.cfg
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值