This is the 7th day of my participation in Gwen Challenge

4. Time and date classes

4.1 Displaying the current time

The basic grammar

(1) date (2) date +%Y (3) Date +%m (4) Date +% D (4) Date +% D (5) Date "+%Y-%m-%d %H:% m :%S" date "+%Y-%m-%d %H:% m :%S"Copy the code
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:03Copy the code

4.2 Displaying the non-current time

The basic grammar

Date -d '1 days ago' date -d '-1 days ago'Copy the code
[root@hadoop1 test]# date 2021 10:19:21 CST [root@hadoop1 test]# Date -d "-1 days ago 10:22:10 CST [root@hadoop1 test]# date -d "2 days agoCopy the code

4.3 Setting the System Time

The basic grammar

Date -s Specifies the string timeCopy the code
date -s "2021-03-19 20:22:22"
Copy the code

4.4 Synchronizing system Time

Yum -y install utp ntpdate Synchronize the system time with the network time ntpdate cn.pool.ntp.org Write the system time to the hardware time hwclock --systohc Set the time zone on the server Timedatectl set-timezone Asia/ShanghaiCopy the code

4.5 CAL Viewing the Sunset

The basic grammar

CAL [option] (No option, display calendar of this month)Copy the code

Option to show

options function
For a particular year Displays the calendar for the year
[root@hadoop1 test]# CAL April 2021 one two three four five six 1 2 3 4 5 6 7 8 9 10 omission...... [root@hadoop1 test]# CAL 2020 2020 January February March one two three four five six one two three four five six one two three four five six omit......Copy the code

5. User management

5.1 useradd

The basic grammar

Useradd User name (Add a new user) useradd -g Group name User name (add a new user to a group)Copy the code
[root@hadoop1 test]# useradd test123 [root@hadoop1 test]# id test123 UID =1003(test123) GID =1003(test123) group =1003(test123)  [root@hadoop1 test]# useradd -g test123 test666 [root@hadoop1 test]# id test666 uid=1004(test666) gid=1003(test123) Group = 1003 (test123)Copy the code

5.2 the passwd

The basic grammar

Passwd User name (Set a password)Copy the code
[root@hadoop1 test]# passwd test123 Change the password of user test123. New password: Invalid password: Password is a palindrome Re-enter new password: passwd: All authentication tokens have been successfully updated.Copy the code

5.3 id

The basic grammar

Id User name (Check whether the user exists)Copy the code
[root@hadoop1 test]# id test666 uid=1004(test666) GID =1003(test123) group =1003(test123) [root@hadoop1 test]# id 666 ID: 666: no such userCopy the code

5.4 cat /etc/passwd Check the created users

[root@hadoop1 ~]# cat  /etc/passwd
Copy the code

5.5 the su

The basic grammar

Su - User name (After switching to a user, you can only obtain the execution permission of the user but not the environment variables)Copy the code
[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 apr 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/mo Dule/hadoop - 2.7.2 / sbin, / home/test123 / local/bin: / home/test123 / binCopy the code

5.6 userdel

The basic grammar

Userdel User name (Delete the user but save the user's home directory) userdel -r User name (delete both the user and home directory)Copy the code

Option to show

options function
-r When you delete a user, delete all files related to the user
[root@hadoop1 test]# userdel test666
[root@hadoop1 test]# userdel -r test66
Copy the code

5.7 the who

The basic grammar

Whoami (Function description: display user name) who AM I (Function description: display user name and login time) WHO (Function description: display user name and login time)Copy the code
[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)Copy the code

5.8 sudo

The basic grammar

Sudo commandCopy the code

Configure the sudo permission

vim /etc/sudoers ## Allow root to run any commands anywhere root ALL=(ALL) ALL test123 ALL=(ALL) NOPASSWD: ## NOPASSWD: ALL indicates that no password is requiredCopy the code

If /etc/sudoers is not configured, sudo cannot be used

[test123@hadoop1 test]$CD /root bash: CD: /root: insufficient permissions [test123@hadoop1 test]$sudo /root We trust that you have learned the daily precautions from your system administrator. It all boils down to these three points: #1) Respect other people's privacy. #2) Consider (consequences and risks) before entering. #3) With great power comes great responsibility. [sudo] test123 password: test123 is not in the sudoers file. The matter will be reportedCopy the code

It can be used after being configured

[test123@hadoop1 test]$ls -al /root/ls: Failed to open directory /root/: [test123@hadoop1 test]$sudo ls -al /root/total amount 72 dr-xr-x--. 5 root root 4096 4月 8 11:11.dr -xr-xr-x. 20 root Root 4096 April 6 16:03.. -rw-r--r-- 1 root root 11326 April 7 23:11.bash_historyCopy the code

5.9 usermod

The basic grammar

Usermod -g User group user nameCopy the code

Option to show

options function
-g Modifies the user’s initial login group. The given group must exist. The default group ID is 1
[root@hadoop1 test]# id test123 UID =1003(test123) gid=1003(test123) group =1003(test123) [root@hadoop1 test]# usermod -g Test1 test123 [root@hadoop1 test]# id test123 uid=1003(test123) gid=1001(test1)Copy the code

6. Manage user groups

6.1 groupadd

The basic grammar

Groupadd group nameCopy the code
[root@hadoop1 test]# groupadd test2
Copy the code

6.2 groupmod

The basic grammar

Groupmod -n New group name Old group nameCopy the code

Option to show

options Functional description
-n< new group name > Specifies a new group name for the workgroup
[root@hadoop1 test]# groupmod -n test22 test2
Copy the code

6.3 groupdel

The basic grammar

Groupdel group nameCopy the code
[root@hadoop1 test]# groupdel test22
Copy the code

6.4 Viewing All Groups

The basic grammar

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

7. File permission classes

7.1 File Properties

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 April 7 19:26 aaA.tar.gzCopy the code
  • Ten characters from left to right

    • If bits 1-9 do not have permission, a minus [-] sign will appear.
  • The 0 digit indicates the type

    • In Linux, the first character indicates whether the file is a directory, file, link file, etc

      • – Representative file

      • D is for directory

      • L Link file;

  • Bits 1-3 determine that the owner (the owner of the file) has permissions on the file. —User

  • Bits 4-6 determine that the owner Group (the same Group of users as the owner) has permissions on the file, –Group

  • Bits 7-9 confirm that Other users have permissions on the file -Other

RXW functions for different interpretations of files and directories

  • Applied to files:

    [r] stands for read: to read, to view

    [w] indicates Write: A file can be modified but cannot be deleted. A file can be deleted only when you have the write permission on the directory where the file resides.

    [x] indicates execute: can be executed by the system

  • Apply to directories:

    [r] stands for read: the directory can be read

    [w] indicates Write: you can create, delete, and rename directories in a directory

    [x] indicates execute: The directory can be accessed

7.2 chmod

The basic grammar

Chmod [{ugoa}{+-=}{RWX}] file or directory chmod [mode=421]Copy the code

[root@hadoop1 test]# chmod g+wx b.tb [root@hadoop1 test]# chmod g-wx b.tb [root@hadoop1 test]# Chmod g= rwxb.t ## 7=4+2+1 ## 4= read 2= write 1= execute [root@hadoop1 test]# chmod 777 b.tCopy the code

7.3 chwon

The basic grammar

Chown [option] [End user] [file or directory]Copy the code

Option to show

options function
-R Recursion operation
[root@hadoop1 test]# chown test123 b.testt [root@hadoop1 test]# chown -r test123./b ## test123:test123 [root@hadoop1 test]# chown -R test123:test123 ./bCopy the code

7.4 the CHGRP

The basic grammar

Chown [option] [End user] [file or directory]Copy the code

Option to show

options function
-R Recursion operation
[root@hadoop1 test]# chgrp -R test123 b.txt
Copy the code