Linux文件管理常用命令

文件管理常用命令:

ls mkdir cd pwd cp rm mv touch chmod chown chgrp

目录信息查看命令: ls

英文愿意:list

所在路径:/bin/ls

执行权限:所有用户

参数:

a 显示所有文件及目录 (. 开头的隐藏文件也会列出)

[root@localhost test]# ls -a
.  ..  123  1.txt  2.txt  3.txt

注意:~ 路径,也就是 root 目录

l 将文件型态、权限、拥有者、文件大小等资讯详细列出

[root@localhost test]# ls -l
总用量 12
-rw-r--r--. 1 root root   0 1014 22:29 123
-rw-r--r--. 1 root root  95 109 23:31 1.txt
-rw-r--r--. 1 root root  55 109 23:08 2.txt
-rw-r--r--. 1 root root 145 109 23:09 3.txt

i 检查i节点(inode)

i节点:每个文件和目录都有自己的id号,系统就是靠这个索引号来搜索查询文件

[root@localhost test]# ls -i
33790422 123  33790380 1.txt  33790384 2.txt  33790388 3.txt

d direct 显示当前目录本身

[root@localhost test]# ls -d
.

创建文件夹命令: mkdir

英文愿意:make directories

所在路径:/bin/mkdir

执行权限:所有用户

eg:

[root@localhost test]# mkdir test
[root@localhost test]# ls
123  1.txt  2.txt  3.txt  test

参数:

-p 递归创建目录(例如先创目录a,再在a里创个目录b)

意思:确保目录名称存在,不存在就建一个

[root@localhost test]# mkdir -p test1/test2/test3
[root@localhost test]# ls test1/test2
test3

-v 显示创建过程

[root@localhost test]# mkdir -pv test2/test3/test4
mkdir: 已创建目录 "test2"
mkdir: 已创建目录 "test2/test3"
mkdir: 已创建目录 "test2/test3/test4"

-m 修改权限

[root@localhost test]# ll
总用量 12
drwxrwxrwx. 2 root root   6 1021 14:37 1

注:linux中文件权限解释见博客

https://blog.csdn.net/Simon_coder/article/details/78660978/

属主、属组、其他的权限可用数字表示

r = 4
w = 2
x = 1
- = 0

补充:

mkdir命令可以连续创建目录

mkdir test1 test2

创建带有空格的目录

mkdir "t est"

切换目录命令:cd

命令原意: change directories

所在的路径:shell 内置命令

执行权限:所有用户

参数:

cd …

进入当前目录

cd …/ 进入上一级目录

cd ~ 进入当前用户的主目录

cd - 返回进入此目录之前的目录

cd 进入当前用户的主目录


显示当前目录命令: pwd

命令原意:print working directories

执行权限:所有用户

所在路径:/usr/bin/pwd


文件拷贝命令: cp

原意:copy

命令所在路径: /bin/cp

执行权限:所有用户

eg:

[root@localhost test]# touch 1.txt
[root@localhost test]# cp 1.txt 2.txt
[root@localhost test]# ls
1.txt  2.txt

参数:

-r 复制目录

[root@localhost test]# cp -r test1 test2
[root@localhost test]# ls
1.txt  2.txt  test1  test2

-p 保留文件的属性

如图所示两份文件所有时间都一样,包括时间

[root@localhost test]# cp -p 2.txt 3.txt
[root@localhost test]# ll
总用量 0
drwxr-xr-x. 2 root root 6 1021 14:39 test1
drwxr-xr-x. 2 root root 6 1021 14:39 test2

-rp [源文件或目录] [目标目录]

补充:

可以用cp一次性复制多个文件

[root@localhost test]# cp 1.txt 2.txt test1
[root@localhost test]# ls test1
1.txt  2.txt

文件删除命令:rm

愿意:remove

命令所在路径: /bin/rm

执行权限:所有用户

参数:

-f (force) 表示将在不要求确认的情况下强行删除文件

$ rm -f testfile

-rf (recursion) 递归删除目录以及该目录中的所有内容

$ rm -rf testdirectory
  • 通配符        删除所有以linux为前缀的文件
    
$ rm -rf linux*

rmdir 只有在目录为空时才会删除该目录

$ rmdir testdirectory

移动文件或者重命名命令 mv

原意:move

文件所在的路径:/bin/mv

执行权限:所有用户

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

功能:移动文件、剪切文件、修改文件名称

eg:

改名:将源文件名 source_file 改为目标文件名 dest_file

mv source_file(文件) dest_file(文件)

剪切:将文件 source_file 移动到目标目录 dest_directory 中

mv source_file(文件) dest_directory(目录)

文件创建命令 touch

命令所在路径:/bin/touch

执行权限:所有用户

功能:创建空文件

补:修改文件或者目录的时间属性,包括存取时间和更改时间。若文件不存在,系统会建立一个新的文件。

补充:

创建带有空格的文件

touch "program files"

权限管理命令:chmod

命令愿意:change the permissions mode of a file

所在路径:/usr/bin/chmod

执行权限:所有用户

功能描述:改变文件或目录权限

命令语法:

chmod [{ugoa} {+-=}] [文件或目录]
			[mode = 421]  [文件或目录]

参数:

-R 递归修改

-v 显示执行过程

u: user 文件或目录的所有者

g: group 文件或目录的所属组

o: other 除了文件或目录的所有者和所属组都是其他人

a: all 代表所有者,所属组,其他人

r: 读取权限,数字代号是4

文件:可以查看文件内容

目录:可以列出目录里中的内容

w:写入权限,数字代号2

文件:可以修改文件内容

目录:可以在目录中创建、删除文件

x:执行权限,数字代号1

文件:可以执行文件

目录:可以进入目录

-:没有权限,数字代号0

+:在原有的基础上增加权限

-:在原有的基础上取消权限

=:文件或目录唯一权限

例子:

修改文件权限:

[root@localhost test]# chmod 777 1.txt
[root@localhost test]# ll
总用量 0
-rwxrwxrwx. 1 root root  0 1021 14:38 1.txt

对文件t2添加执行权限:

[root@localhost test]# ll
总用量 0
-rw-r--r--. 1 root root  0 1021 14:39 2.txt
[root@localhost test]# chmod u+x 2.txt
[root@localhost test]# ll
总用量 0
-rwxr--r--. 1 root root  0 1021 14:39 2.txt

更改文件属主命令:chown

命令的英文原意:change file ownership

命令所在的路径:/bin/chown

执行权限:所有用户

语法:chown [用户] [文件或者目录]


属组管理命令:chgrp

命令英文的原意:change file group ownership

命令所在的路径:/bin/chgrp

执行权限:所有用户

语法:chgrp [用户组] [文件或目录]

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值