加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Linu文件处理命令

发布时间:2020-12-14 04:44:19 所属栏目:大数据 来源:网络整理
导读:命令格式:命令? ? [-选项]? ? [参数] 例如:ls -la /etc(多个选项可以写在一起,个别命令不遵循此格式,简化选项只用一个-,完整选项需要写两个--,-a等于--all) 1. 命令格式与目录处理命令ls 功能描述:显示目录文件 执行权限:所有用户(位于/bin/ls)

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

例如:ls -la /etc(多个选项可以写在一起,个别命令不遵循此格式,简化选项只用一个-,完整选项需要写两个--,-a等于--all)

1. 命令格式与目录处理命令ls


功能描述:显示目录文件

执行权限:所有用户(位于/bin/ls)

选项:常用的是-a和-l

-a? 所有文件,包括隐藏文件

-l? ?列出文件详细信息

-d? ?显示当前目录本身信息,而不输出该目录下的文件的一些个信息

-h? ?字节数以Kb显示

-t? ? 以文件修改时间排序

-i? ? 查看文件索引节点(inode),一个文件具有一个节点号。

# ls -l
drwxrwxr-x 2 keegen keegen 4096 4月   9 17:51 test
drwxr-xr-x 2 keegen keegen 4096 3月  26 16:00 test1
-rwxrwxr-x 1 keegen keegen  135 4月   4 21:40 test.sh
-rw-r--r-- 1 keegen keegen  225 3月  26 16:19 test.tar.gz
-rw-r--r-- 1 keegen keegen   83 3月  25 19:36 test.txt

第一列? drwxrwxr-x? ?是文件目录权限。

其中的第1列:(常见的是前三个)

?

文件类型符号 具体含义
- 普通文件
d 目录
l 链接文件
b 块设备文件,如硬盘的存储设备等
C 字符设备文件,如键盘等
s 套接字文件,主要跟网络程序有关
p 管道文件

第2-10列?rw-r--r-- 共9列,每三列为一组,每一组分别代表属主(所有者)权限,属组权限,其他人的权限。每组的三列依次代表可读r可写w可执行x权限。

一个用户可以属于多个组,而每个组的成员可以规定可以或不可以为其他成员所使用,这就是Linux最基本的权限模型。

?

第二列 2?是文件链接数。

第三列 keegen? 是文件的所有者。

第四列 keegen 是文件的所属组。

第五列 4096 是文件所占字节数。

第六-八列?4096 4月 9?是文件修改时间。

第九列?test?是文件名。

# ls -lh
drwxrwxr-x 2 keegen keegen 4.0K 4月   9 17:51 test?
# ls -ld
drwxr-xr-x 23 keegen keegen 4096 6月  14 10:27 .

?2. 目录处理命令


mkdir


?

功能描述:创建新目录

执行权限:所有用户(位于/bin/mkdir)

选项:

?-p? ? 递归创建

 1 [email?protected]:/home/keegen/test# ls
 2 a.out  hello  hello.c
 3 [email?protected]:/home/keegen/test# mkdir test
 4 [email?protected]:/home/keegen/test# ls
 5 a.out  hello  hello.c  test
 6 [email?protected]:/home/keegen/test# mkdir test2/test
 7 mkdir: 无法创建目录"test2/test": 没有那个文件或目录
 8 [email?protected]:/home/keegen/test# mkdir -p test2/test   #加上-p参数后,可以创建上级目录不存在的目录。
 9 [email?protected]:/home/keegen/test# ls -ld test2/test
10 drwxr-xr-x 2 root root 4096 6月  14 18:22 test2/test
11 [email?protected]:/home/keegen/test# mkdir test3 test4     #创建多个目录

?pwd


?

显示当前目录


?

cd


?

切换目录


?

rmdir(在实际中用处不多)


?

删除空目录,只能删除空目录,目录下有东西删不了


?

cp


?

复制文件或目录

用法:cp -rp [原文件或目录] [目标目录]? ? ? (原文件或目录可以有多个)

参数:

-r? 复制目录

-p? ?保留文件属性? (不加该参数的话,文件修改时间就会变化,加上的话,修改时间就不会变化)

复制文件可以不加参数,复制目录需要加上-r参数

 1 [email?protected]:/home/keegen/test# ls
 2 a.out  hello  hello.c  test
 3 [email?protected]:/home/keegen/test# ls test
 4 hello
 5 [email?protected]:/home/keegen/test# mkdir test1
 6 [email?protected]:/home/keegen/test# cp -rp test test1
 7 [email?protected]:/home/keegen/test# ls test1
 8 test
 9 [email?protected]:/home/keegen/test# ls test1/test
10 hello
11 [email?protected]:/home/keegen/test# ls
12 a.out  hello  hello.c  test  test1
13 [email?protected]:/home/keegen/test# cp -r test test2     #复制到以前不存在的目录会自动创建
14 [email?protected]:/home/keegen/test# ls test2      
15 hello

?

mv


?

剪切文件、改名

语法:

mv [原文件或目录] [目标目录]

?

3.文件处理命令


?

4. 链接命令

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读