linux基础之二

命令目录

/usr/bin存放普通用户及管理员可以执行的基础命令如ls,cat,grep
/usr/sbin存放管理员命令 比如useradd userdel groupadd等
查看用户和用户组相关的命令有哪些
[root@chen ~]# ll /usr/sbin/user*
-rwxr-x— 1 root root 118192 Nov 6 2016 /usr/sbin/useradd
-rwxr-x— 1 root root 80360 Nov 6 2016 /usr/sbin/userdel
-rwxr-x— 1 root root 113840 Nov 6 2016 /usr/sbin/usermod
-rwsr-xr-x 1 root root 11296 Apr 13 2017 /usr/sbin/usernetctl
[root@chen ~]# ll /usr/sbin/group*
-rwxr-x— 1 root root 65480 Nov 6 2016 /usr/sbin/groupadd
-rwxr-x— 1 root root 57016 Nov 6 2016 /usr/sbin/groupdel
-rwxr-x— 1 root root 57064 Nov 6 2016 /usr/sbin/groupmems
-rwxr-x— 1 root root 76424 Nov 6 2016 /usr/sbin/groupmod

新增用户

useradd ruoze 新增用户会连同用户组一起新建,并在home目录下新增这个用户家目录
在这里插入图片描述
用户存储信息 /etc/passwd
用户组 /etc/group

新增用户组

groupadd bigdata

修改用户组

usermod -a -G bigdta
[ruoze@chen ~]$ id
uid=1003(ruoze) gid=1003(ruoze) groups=1003(ruoze),1004(bigdata)

[root@chen home]# usermod --help
Usage: usermod [options] LOGIN

Options:
-c, --comment COMMENT new value of the GECOS field
-d, --home HOME_DIR new home directory for the user account
-e, --expiredate EXPIRE_DATE set account expiration date to EXPIRE_DATE
-f, --inactive INACTIVE set password inactive after expiration
to INACTIVE
-g, --gid GROUP force use GROUP as new primary group
-G, --groups GROUPS new list of supplementary GROUPS
-a, --append append the user to the supplemental GROUPS
mentioned by the -G option without removing
him/her from other groups
-h, --help display this help message and exit
-l, --login NEW_LOGIN new value of the login name
-L, --lock lock the user account
-m, --move-home move contents of the home directory to the
new location (use only with -d)
-o, --non-unique allow using duplicate (non-unique) UID
-p, --password PASSWORD use encrypted password for the new password
-R, --root CHROOT_DIR directory to chroot into
-s, --shell SHELL new login shell for the user account
-u, --uid UID new UID for the user account
-U, --unlock unlock the user account
-Z, --selinux-user SEUSER new SELinux user mapping for the user account

修改文件用户属组

[ruoze@chen home]$ chown ruoze:bigdata 11.txt
[ruoze@chen home]$ ll
total 88
-rw-r–r-- 1 ruoze bigdata 98 Apr 21 14:33 11.txt
-rw-r–r-- 1 root root 186 Nov 2 2018 1.json

设置密码 passwd

[root@chen ~]# passwd
Changing password for user root.
New password:

切换用户 su

su ruoze 会停留在当天目录
su - ruoze
代表该用户切换到家目录,且执行环境变量文件

sudo 普通用户临时使用root最大权限

vi /etc/sudoers
ruoze ALL=(root) NOPASSWD:ALL

/etc/passwd文件

设置禁用用户登录
ruoze❌1004:1005::/home/ruoze:/sbin/nologin 提示
ruoze❌1004:1005::/home/ruoze:/usr/bin/false 没提示

权限

-rw-r–r-- 1 root root 1 Apr 20 16:56 2.txt
drwx------. 3 centos centos 70 Jun 28 2017 centos
第一个字母:d文件夹 -文件 l连接
后面9个字母,3个字母为一组:
rw- r-- r–
r: read 读权限 4
w: write 写权限 2
x: 执行 1
-: 没权限 0 占位

7=4 2 1
5=4 1
6=4 2
rw- 第一组 6 代表文件或文件夹的所属用户,读写权限
r-- 第二组 4 代表文件或文件夹的所属用户组,读权限
r-- 第三组 4 代表其他用户组的用户对这个文件或文件夹,读权限

rw-r–r-- root root 22.log

关于权限:
chmod -R 777 文件或文件夹
chown -R 用户:用户组 文件或文件夹

查看文件大小

大小
文件: ll -h 、du -sh
文件夹: du -sh

查找文件 find

[root@chen home]# find ./ -name “*.txt”
./1.txt
./11.txt
./23.txt
./231.txt
./2.txt

vi命令

  • 正常退出 并保存 :wq
  • 强制退出保存:wq!
  • 退出不保存:q!
  • 显示行号,输入冒号 :敲下面命令
    set nu 设置行号
    set nonu 取消行号
    f 也是可以显示 当前光标的所在的行
  • 常用快捷方式
    dd 删除当前行
    dG 删除当前及以下所有行
    ndd 删除当前及以下n行 比如5dd
    gg 跳转到第一行的第一个字母
    G 跳转到最后一行的第一个字母
    shift+$ 当前行行尾
    yy 拷贝当前行
    p 复制yy拷贝的行
    查找
    / 文本
    /继续上一步查找
    /行号调转
    替换 :s/old/new/g
    场景:
    清空这个文件内容,从另外一个文件内容 拷贝过来
    gg–》dG --》 i -->鼠标右键单击 粘贴上
    也可以1,$d --》 i -->鼠标右键单击 粘贴上
    清空文件
    cat /dev/null > 1.log 0字节
    echo “” > 2.log 非 0字节
    true > 1.log 也是清空文件内容 0字节
    gg–》dG 0字节
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值