小学生 自学大数据 第一章linux常用命令 (二)

目录

上期:小学生 自学大数据 第一章linux常用命令 (一)

4.时间日期类

4.1 显示当前时间

4.2 显示非当前时间

4.3 设置系统时间

4.4 同步系统时间

4.5 cal 查看日落

5.用户管理类

5.1 useradd

5.2 passwd

5.3 id

5.4 cat  /etc/passwd 查看创建了哪些用户

5.5 su

5.6 userdel

5.7 who

5.8 sudo

5.9 usermod

6.用户组管理

6.1 groupadd

6.2 groupmod

6.3 groupdel

6.4 查看所有组

7.文件权限类

7.1文件属性

7.2 chmod

7.3 chwon

7.4 chgrp


上期:

         小学生 自学大数据 第一章linux常用命令 (一)


4.时间日期类

4.1 显示当前时间

基本语法

(1)date (功能描述:显示当前时间)

(2)date +%Y (功能描述:显示当前年份)

(3)date +%m (功能描述:显示当前月份)

(4)date +%d (功能描述:显示当前是哪一天)

(5)date "+%Y-%m-%d %H:%M:%S" (功能描述:显示年月日时分秒)

[root@hadoop1 test]# date
2021年 04月 08日 星期四 10:19:21 CST
[root@hadoop1 test]# date +%Y
2021
[root@hadoop1 test]# date +%Y-%m-%d
2021-04-08
[root@hadoop1 test]# date "+%Y-%m-%d %H:%M:%S"
2021-04-08 10:20:03

 

4.2 显示非当前时间

基本语法

(1)date -d '1 days ago' (功能描述:显示前一天时间)

(2)date -d '-1 days ago' (功能描述:显示明天时间)

[root@hadoop1 test]# date
2021年 04月 08日 星期四 10:19:21 CST
[root@hadoop1 test]# date -d "-1 days ago"
2021年 04月 09日 星期五 10:22:10 CST
[root@hadoop1 test]# date -d "2 days ago"
2021年 04月 06日 星期二 10:22:14 CST

4.3 设置系统时间

基本语法

date -s 字符串时间

date -s "2021-03-19 20:22:22"

 

4.4 同步系统时间

安装utpdate工具
yum -y install utp ntpdate
设置系统时间与网络时间同步
ntpdate cn.pool.ntp.org
将系统时间写入硬件时间
hwclock --systohc

服务器时区设置
timedatectl set-timezone Asia/Shanghai # 设置系统时区为上海

 

4.5 cal 查看日落

基本语法

cal [选项] (功能描述:不加选项,显示本月日历)

选项说明

选项

功能

具体某一年

显示这一年的日历

[root@hadoop1 test]# cal
      四月 2021     
日 一 二 三 四 五 六
             1  2  3
 4  5  6  7  8  9 10
省略......
[root@hadoop1 test]# cal 2020
                               2020                               
        一月                   二月                   三月        
日 一 二 三 四 五 六   日 一 二 三 四 五 六   日 一 二 三 四 五 六
省略......

 

5.用户管理类

5.1 useradd

基本语法

useradd 用户名 (功能描述:添加新用户)

useradd -g 组名 用户名 (功能描述:添加新用户到某个组)

[root@hadoop1 test]# useradd test123
[root@hadoop1 test]# id test123
uid=1003(test123) gid=1003(test123) 组=1003(test123)
[root@hadoop1 test]# useradd -g test123 test666
[root@hadoop1 test]# id test666
uid=1004(test666) gid=1003(test123) 组=1003(test123)

 

5.2 passwd

基本语法

passwd 用户名 (功能描述:设置用户密码)

[root@hadoop1 test]# passwd test123
更改用户 test123 的密码 。
新的 密码:
无效的密码: 密码是一个回文
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。

 

5.3 id

基本语法

id 用户名 (功能描述:查看用户是否存在)

[root@hadoop1 test]# id test666
uid=1004(test666) gid=1003(test123) 组=1003(test123)
[root@hadoop1 test]# id 666
id: 666: no such user

 

5.4 cat  /etc/passwd 查看创建了哪些用户

[root@hadoop1 ~]# cat  /etc/passwd

 

5.5 su

基本语法

su 用户名称   (功能描述:切换用户,只能获得用户的执行权限,不能获得环境变量)

su - 用户名称 (功能描述:切换到用户并获得该用户的环境变量及执行权限)

[root@hadoop1 test]# su test123
[test123@hadoop1 test]$ echo $PATH
/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/opt/module/jdk1.8.0_144/bin:/opt/module/hadoop-2.7.2/bin:/opt/module/hadoop-2.7.2/sbin:/home/weipeng/.local/bin:/home/weipeng/bin:/opt/module/jdk1.8.0_144/bin:/opt/module/hadoop-2.7.2/bin:/opt/module/hadoop-2.7.2/sbin:/opt/module/jdk1.8.0_144/bin:/opt/module/hadoop-2.7.2/bin:/opt/module/hadoop-2.7.2/sbin
[test123@hadoop1 test]$ exit
exit
[root@hadoop1 test]# su - test123
上一次登录:四 4月  8 10:59:21 CST 2021pts/0 上
[test123@hadoop1 ~]$ echo $PATH
/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/opt/module/jdk1.8.0_144/bin:/opt/module/hadoop-2.7.2/bin:/opt/module/hadoop-2.7.2/sbin:/home/test123/.local/bin:/home/test123/bin

 

5.6 userdel

基本语法

(1)userdel  用户名 (功能描述:删除用户但保存用户主目录)

(2)userdel -r 用户名 (功能描述:用户和用户主目录,都删除)

选项说明

选项

功能

-r

删除用户的同时,删除与用户相关的所有文件。

[root@hadoop1 test]# userdel test666
[root@hadoop1 test]# userdel -r test66

 

5.7 who

基本语法

(1)whoami (功能描述:显示自身用户名称)

(2)who am i (功能描述:显示登录用户的用户名以及登陆时间)

(3)who (功能描述:显示登录用户的用户名以及登陆时间)

[root@hadoop1 test]# who
wei  pts/0        2021-04-08 09:10 (121.69.11.250)
[root@hadoop1 test]# whoami
root
[root@hadoop1 test]# who am i
wei  pts/0        2021-04-08 09:10 (121.69.11.250)

 

5.8 sudo

基本语法

sudo 命令

配置sudo权限

vim /etc/sudoers
## Allow root to run any commands anywhere
root       ALL=(ALL)     ALL
test123    ALL=(ALL)     NOPASSWD: ALL .  ## 添加需要配置的用户
## NOPASSWD: ALL 表示不需要输入密码

 

不配置 /etc/sudoers 的情况下 ,没有权限使用 sudo

[test123@hadoop1 test]$ cd /root
bash: cd: /root: 权限不够
[test123@hadoop1 test]$ sudo /root

我们信任您已经从系统管理员那里了解了日常注意事项。
总结起来无外乎这三点:

    #1) 尊重别人的隐私。
    #2) 输入前要先考虑(后果和风险)。
    #3) 权力越大,责任越大。

[sudo] test123 的密码:
test123 不在 sudoers 文件中。此事将被报告

配置后 可以使用

[test123@hadoop1 test]$ ls -al /root/
ls: 无法打开目录/root/: 权限不够
[test123@hadoop1 test]$ sudo ls -al /root/
总用量 72
dr-xr-x---.  5 root root  4096 4月   8 11:11 .
dr-xr-xr-x. 20 root root  4096 4月   6 16:03 ..
-rw-r--r--   1 root root 11326 4月   7 23:11 .bash_history

 

5.9 usermod

基本语法

usermod -g 用户组 用户名

选项说明

选项

功能

-g

修改用户的初始登录组,给定的组必须存在。默认组id是1。

[root@hadoop1 test]# id test123
uid=1003(test123) gid=1003(test123) 组=1003(test123)
[root@hadoop1 test]# usermod -g test1 test123
[root@hadoop1 test]# id test123
uid=1003(test123) gid=1001(test1) 组=1001(test1)

 

6.用户组管理

6.1 groupadd

基本语法

groupadd 组名

[root@hadoop1 test]# groupadd test2

 

6.2 groupmod

基本语法

groupmod -n 新组名 老组名

选项说明

选项

功能描述

-n<新组名>

指定工作组的新组名

[root@hadoop1 test]# groupmod -n test22 test2

 

6.3 groupdel

基本语法

groupdel 组名

[root@hadoop1 test]# groupdel test22

 

6.4 查看所有组

基本语法

cat /etc/group

[root@hadoop1 test]# cat /etc/group
root:x:0:
bin:x:1:

 

7.文件权限类

7.1文件属性

drwxrw-rw- 2 root    root    4096 4月   8 09:32 aaa
lrwxrwxrwx 1 root    root       3 4月   8 10:13 aaa.ln -> aaa
-rw-r--r-- 1 root    root     123 4月   7 19:26 aaa.tar.gz

从左到右的10个字符表示

如果1-9位没有权限,就会出现减号[ - ]而已。

(1)0首位表示类型

     在Linux中第一个字符代表这个文件是目录、文件或链接文件等等

     - 代表文件

     d 代表目录

     l 链接文档(link file);

(2)第1-3位确定属主(该文件的所有者)拥有该文件的权限。---User

(3)第4-6位确定属组(所有者的同组用户)拥有该文件的权限,---Group

(4)第7-9位确定其他用户拥有该文件的权限 ---Other

rxw作用文件和目录的不同解释

(1)作用到文件:

    [ r ]代表可读(read): 可以读取,查看

    [ w ]代表可写(write): 可以修改,但是不代表可以删除该文件,删除一个文件的前提条件是对该文件所在的目录有写权限,才能删除该文件.

    [ x ]代表可执行(execute):可以被系统执行

(2)作用到目录:

    [ r ]代表可读(read): 可以读取,ls查看目录内容

    [ w ]代表可写(write): 可以修改,目录内创建+删除+重命名目录   

    [ x ]代表可执行(execute):可以进入该目录

 

7.2 chmod

基本语法

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

chmod  [mode=421 ]  [文件或目录]

## +加权限 -减权限 =覆盖之前的权限
[root@hadoop1 test]# chmod g+wx b.txt
[root@hadoop1 test]# chmod g-wx b.txt
[root@hadoop1 test]# chmod g=rwx b.txt

## 7=4+2+1
## 4=读 2=写 1=执行
[root@hadoop1 test]# chmod 777 b.txt

 

7.3 chwon

基本语法

chown [选项] [最终用户] [文件或目录] (功能描述:改变文件或者目录的所有者)

选项说明

选项

功能

-R

递归操作

[root@hadoop1 test]# chown test123 b.txt
[root@hadoop1 test]# chown -R test123 ./b
## test123:test123 同时修改所有者和所属组
[root@hadoop1 test]# chown -R test123:test123 ./b

 

7.4 chgrp

基本语法

chown [选项] [最终用户] [文件或目录] (功能描述:改变文件或者目录的所有者)

选项说明

选项

功能

-R

递归操作

[root@hadoop1 test]# chgrp -R test123 b.txt

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值