Linux基础命令(一)文件、用户管理、用户权限

目录

一、文件

二、用户管理

三、用户权限


一、文件

1.cd 切换目录

2.ls 展开目录下的文件 ls ./ 展示目录下所有文件 ls ../展示上一级目录下的文件

3.touch 创建文件

[root@localhost home]# cd
[root@localhost ~]# ls
anaconda-ks.cfg
[root@localhost ~]# ls ./
anaconda-ks.cfg
[root@localhost ~]# touch test1
[root@localhost ~]# ls
anaconda-ks.cfg  test1

4.mkdir 创建路径和目录名

5.cp 【源文件】 【目标文件夹】复制源文件到目录文件夹下

6.cp -r 【源文件】 【目标文件夹】 (-r递归)

[root@localhost ~]# mkdir test2
[root@localhost ~]# ls
anaconda-ks.cfg  test1  test2
[root@localhost ~]# cp test1 test2
[root@localhost ~]# cd test2
[root@localhost test2]# ls
test1
[root@localhost test2]# cd
[root@localhost ~]# ls
anaconda-ks.cfg  test1  test2

7.mv 【源文件】 【目标文件夹】 移动源文件到目标文件夹下

8.mv 【源文件名】 【重命名的名字】把源文件重命名

9.rm 【目标文件名】 删除目标文件  rm -rf/-r 【目标文件名】强制删除

[root@localhost ~]# mkdir test3
[root@localhost ~]# ls
anaconda-ks.cfg  test1  test2  test3
[root@localhost ~]# mv test1 test3
[root@localhost ~]# cd test3
[root@localhost test3]# ls
test1
[root@localhost test3]# mv test1 1.txt
[root@localhost test3]# ls
1.txt
[root@localhost test3]# rm -rf 1.txt
[root@localhost test3]# ls

10.vim 【文件名】 打开文件,如果文件不存在则自动创建并打开 (打开文件之后点 i 输入内容,退出点击[esc  :   w q]  保存并退出,[esc : q!]强制退出内容不会保存)

11.cat 【文件名】查看文件内容

[root@localhost ~]# vim 1.sh
[root@localhost ~]# sh 1.sh
hello world!
[root@localhost ~]# cat 1.sh
#!/bin/bash
echo "hello world!"

12.head 【-数字】【文件名】查看文件前几行内容

13.tail 【-数字 / 文件名】 查看文件后几行内容

[root@localhost ~]# head -5 /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
[root@localhost ~]# tail -1 /etc/passwd
chrony:x:998:996::/var/lib/chrony:/sbin/nologin

14.more 看文件内容

[root@localhost ~]# more
Usage: more [options] file...

Options:
  -d        display help instead of ring bell
  -f        count logical, rather than screen lines
  -l        suppress pause after form feed
  -p        do not scroll, clean screen and display text
  -c        do not scroll, display text and clean line ends
  -u        suppress underlining
  -s        squeeze multiple blank lines into one
  -NUM      specify the number of lines per screenful
  +NUM      display file beginning from line number NUM
  +/STRING  display file beginning from search string match
  -V        output version information and exit

15.grep 过滤关键字

[root@localhost ~]# grep "root" /etc/passwd
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
[root@localhost ~]# grep "^root" /etc/passwd
root:x:0:0:root:/root:/bin/bash

16.ls -l 【文件名】 查看文件的详情

[root@localhost ~]# ls -l
total 8
-rw-r--r--. 1 root root   32 Sep 11 00:35 1.sh
-rw-------. 1 root root 1420 Aug 23 05:49 anaconda-ks.cfg
drwxr-xr-x. 2 root root    6 Sep 11 00:32 test2
drwxr-xr-x. 2 root root    6 Sep 11 00:30 test3
[root@localhost ~]# ls -l /etc/
total 1044
-rw-r--r--.  1 root root       16 Aug 23 05:48 adjtime
-rw-r--r--.  1 root root     1529 Apr  1  2020 aliases
-rw-r--r--.  1 root root    12288 Aug 23 05:51 aliases.db
drwxr-xr-x.  2 root root      236 Aug 23 05:46 alternatives
-rw-------.  1 root root      541 Aug  8  2019 anacrontab
-rw-r--r--.  1 root root       55 Aug  8  2019 asound.conf

二、用户管理

1. .代表当前目录  ..代表上一级目录

2./etc/passwd #用户基本信息文件

3./etc/shadow #用户密码信息文件

4./etc/group #组信息文件

[root@localhost ~]# cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
[root@localhost ~]# cat /etc/shadow
bin:*:18353:0:99999:7:::
daemon:*:18353:0:99999:7:::
[root@localhost ~]# cat /etc/group
root:x:0:
bin:x:1:

5.useradd 【用户名】#添加用户

6.id 【用户名】 #查看用户创建成功与否

7.passwd 【用户名】#修改用户密码

8.userdel -r 【用户名】#删除用户

[root@localhost ~]# useradd user1
[root@localhost ~]# id user1
uid=1000(user1) gid=1000(user1) groups=1000(user1)
[root@localhost ~]# userdel -r user1
[root@localhost ~]# id user1
id: user1: no such user

9.usermod -s/sbin/nologin 【用户名】#修改用户属性

10.groupadd 【组名】#创建用户组

11.cat /etc/group #查看组是否创建成功

12.groupdel 【组名】#删除组

[root@localhost ~]# groupadd user1
[root@localhost ~]# cat /etc/group
user1:x:1000:
[root@localhost ~]# groupdel user1

13.su - root  #切换到root用户

14.exit #退出当前用户

15.sudo

三、用户权限

1.基本权限

属主:U  属组:G  其他:O

权限的三种类型:rwx(读写执行)

(1)chown 【用户名.组名】【文件】#设置一个文件属于谁

[root@localhost ~]# touch 1.txt
[root@localhost ~]# ls -l 1.txt
-rw-r--r--. 1 root root 0 Sep 11 01:59 1.txt
[root@localhost ~]# chown user1.user1 1.txt
[root@localhost ~]# ls -l 1.txt
-rw-r--r--. 1 user1 user1 0 Sep 11 01:59 1.txt

(2)chown 【.用户名】【文件】#只改属组

[root@localhost ~]# chown .root 1.txt
[root@localhost ~]# ls -l 1.txt
-rw-r--r--. 1 user1 root 0 Sep 11 01:59 1.txt

(3)chgrp 【组名】【文件】#改文件属组

(4)chgrp -R 【组名】【文件】#修改文件属组 -R是递归

[root@localhost ~]# chgrp user1 1.txt
[root@localhost ~]# ls -l 1.txt
-rw-r--r--. 1 user1 user1 0 Sep 11 01:59 1.txt

2.基本权限ACL(限制用户对文件的访问)

ACL文件权限管理:设置不同用户,不同的基本权限(r,w,x),对象数量不同

UGO设置基本权限:只能一个用户,一个组或其他

语法:setfacl -m [用户名/组名]:[用户名]:[权限]  [文件对象]  #设置文件权限

(1)setfacl -x 【用户名:组名】【文件对象】#删除组的ACL权限

(2)setfacl -b 【文件对象】 #删除所有ACL权限

(3)getfacl 【文件名】#查看文件有哪些ACL权限

(4)watch -n1 'ls -l 文件名/路径' #查看文件的详细信息

(5)watch -n1 'getfacl 【文件名】'

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值