目录处理命令

20 篇文章 0 订阅
本文介绍了Linux常用命令ls(列出目录),mkdir(创建目录),cd(切换目录),cp(复制文件)、mv(移动与重命名)、rm(删除文件)的用法、选项和实例。通过实例演示了如何操作并解释了-p选项的作用。
摘要由CSDN通过智能技术生成

ls(list显示目录文件)

所在路径:/bin/ls

命令格式:命令 [-选项] [参数]

例:ls -la /etc

选项:

  • -a 显示所有文件,包括隐藏文件(all)

  • -l 详细信息显示(long)

  • -d 查看目录属性 (directory)

  • -h 适合人类查看(human)

[root@host ~]# ls -l
总用量 12
dr-xr-xr-x. 5 root root 4096 11月 27 15:23 boot
-rw-r--r--. 1 root root    0 11月 27 15:04 feng.txt
drwxr-xr-x. 4 root root   32 11月 27 15:20 guangdong
#文件类型和用户权限  文件系数  所有者  所属组  文件大小(默认B) 最后修改时间 文件名

-rw-r--r--

-:文件类型(-二进制文件,d目录,l软连接文件)

rw- r-- r--

u g o

u所有者 g所属组 o其他人

r读 w写 x执行

mkdir 创建新目录

全称:make directories

所在路径:/bin/mkdir

执行权限:所有用户

语法:mkdir -p [目录名]

  • -p 递归创建

cd 切换目录

全称:change directory

所在路径:shell内置命令

语法:cd [目录]

  • cd ..回到上一级目录

pwd 显示当前目录

全称:print working directory

所在路径:/bin/pwd

执行权限:所有用户

语法:pwd

  • -p 显示物理路径,忽视符号链接

    • 什么是符号链接?

      • 符号链接类似于Windows中的快捷方式

rmdir 删除空目录

全称:remove empty directories

所在路径:/bin/rmdir

执行权限:所有用户

语法:rmdir [目录名]

[root@host lianxi]# ls
a.out       chenlu7 
[root@host lianxi]# cd chenlu7
[root@host chenlu7]# ls
[root@host chenlu7]# cd ..
[root@host lianxi]# rmdir chenlu7
[root@host lianxi]# ls、
a.out 

cp 复制文件或目录

全称:copy

所在路径:/bin/cp

执行权限:所有用户

语法:cp -rp [源文件或目录] [目标目录]

  • -r 复制目录

  • -p 保留文件属性

#cp
[root@host lianxi]# ls
1.txt       chenlu5  
[root@host lianxi]# cp 1.txt chenlu5
[root@host lianxi]# cd chenlu5
[root@host chenlu5]# ls
1.txt
#cp -r
[root@host lianxi]# cp -r aa/bb/cc chenlu8
[root@host lianxi]# ls chenlu8
cc
#cp -r复制&改名
[root@host lianxi]# cp -r aa/bb/cc chenlu8/dd
[root@host lianxi]# ls chenlu8
dd
#cp -p
[root@host lianxi]# ls -l a.py
-rw-r--r--. 1 root root 159 12月  5 16:13 a.py
[root@host lianxi]# cp a.py chenlu1
[root@host lianxi]# ls -l chenlu1/a.py
-rw-r--r--. 1 root root 159 2月  22 18:49 chenlu1/a.py
[root@host lianxi]# cp -p a.py chenlu9
[root@host lianxi]# ls -l chenlu9/a.py
-rw-r--r--. 1 root root 159 12月  5 16:13 chenlu9/a.py
#个人理解:如果不用-p复制过来,最后一次修改会记录成这次复制,如果加上-p复制过来的时候,所有属性东西全部原封不动复制过来

mv 剪切文件、改名

全称:move

命令所在路径:/bin/mv

执行权限:所有用户

语法:mv [原文件或目录] [目标目录]

#剪切
[root@host lianxi]# ls chenlu5
1.txt
[root@host lianxi]# ls chenlu6
[root@host lianxi]# mv /lianxi/chenlu5/1.txt chenlu6
[root@host lianxi]# ls chenlu5
[root@host lianxi]# ls chenlu6
1.txt
#改名
[root@host lianxi]# mv chenlu6/1.txt chenlu5/2.txt
[root@host lianxi]# ls chenlu6
[root@host lianxi]# ls chenglu5
2.txt

rm 删除文件

全称:remove

命令所在路径:/bin/rm

执行权限:所有用户

语法:rm -rf [文件或目录]

  • -r 删除目录

  • -强制执行

[root@host lianxi]# cd chenlu5
[root@host chenlu5]# rm 2.txt 
rm:是否删除普通文件 "2.txt"?y
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值