Common Linux Commands

A user.

  • Super administrator root: This account is not used by common employees
  • The average user

2. The command

Format: Command [options*][arguments*

project describe
Command to the command What is the system assigned to do
Options for the options Is a modifier that specifies how the command is run. The option begins with “-“
Parameters of the arguments Specify where the command works (file, directory, or text)

Common commands

function The command The instance
Operating System Information uname
Output hardware platform uname -i
Help information about a command, such as uname uname --help

A very common

function The command The instance
View the current operation path pwd
In the home cd ~
Clear the screen clear
Return current time date
View current Calendar cal
View the specified time calendar cal 07 2020
Setting the System Time sudo date -s “2021-01-21 10:52”
Switch the user from normal user to super administrator (password is Hadoop) Su root
The user is changed from the super administrator to a common user su hadoop
Auto-complete intelligent button “TAB”

Linux directory commands

Directory switching and creation

function The command The instance
Switch to the opt directory under the root path (“/” indicates the root path) cd /opt
Viewing the Current Path pwd
Switch to the parent directory cd ..
Switch to the current user’s home cd ~
Creating a directory (absolute path) mkdir /opt/data
Create a directory (you can also create multilevel directories based on the current path) mkdir -p data2
Switch based on absolute strength cd /opt/data
Switch based on relative strength (make sure you are already under the parent folder of the folder to be switched) cd /data

Directory to view

function The command The instance
#-a: Displays information about all files and directories, including hidden content ls -a /opt
#-l: indicates that directories and file details are displayed in a long list ls -l /opt
The equivalent ofls -l ll /opt
All contents under opt, including hidden contents, are displayed in a long list ls -al /opt

File creation

function The command The instance
Create empty file [touch], create two empty files touch file1.txt file2.txt
[echo] > echo “hello world”>hello.txt Create the file if it doesn’t exist
[echo] >> echo “i am a girl”>>hello.txt
View file contents [cat] cat hello.txt
【 VI editor 】 [hadoop@hadoop01 data]$vi hello. TXT # Open existing file [hadoop@hadoop01 data]$vi hi. TXT # Create new file--->Enter edit mode: enter I or enter A2) After editing, how to "save" the file and exit? 2.1) Press "Esc" to exit the editing mode and enter the command mode. 2.2) Enter the command :wq 2.3) Enter the file and press Enter.3) How do I exit without saving the file after editing? 3.1) Press "ESC" to exit the editing mode and enter the command mode 3.2) Enter the command :q! 3.3) After all information is entered, press EnterCopy the code
1) Line no. :set nu Display line no. :set nonu Cancel line no. :set nonu cancel line noCopy the code

2) Copy (based on the cursor position) Copy the current line 1 line: YY Copy the current line to the bottom N line: NYY (for example: 4YY) Note: there is no colon, just press YY 3) Paste (based on the cursor position) P(lowercase) : paste the cursor position down P(uppercase) : paste the cursor position upCopy the code

3 yy: input

According to the p

5) Position cursor :set nu # to display line number 5.1) Position position to the first line: GG 5.2) Position position to the last line: G 5.3) Position position to the specified line: NG (e.g. : 20G) 6) Search syntax: / Search content # Search down from the cursor for content such as: /propertyCopy the code

S /oldword/newword$: indicates the last line$s/property/ property; $s/property/ propertyCopy the code

File and directory replication [cp]

note The command The instance
Copy file 1 to file 2. Cp file 1 File 2
Copy a. TXT, b.log to p path cp a.txt b.txt p
Copy the non-empty directory p to another directory /home/log cp -r p /home/log

File, directory move, rename [mv]

Command: [hadoop@hadoop01 data]$mv hello.txt newhello.log The destination address of the file is inconsistent with the original address. [hadoop@hadoop01 data]$mv hi. TXT /opt/data/1 [hadoop@hadoop01 data]$ll 1 Total amount 4 drwxrwxr-x 3 Hadoop Hadoop 15 1月 18 14:31 2 -rw-rw-r-- 1 Hadoop hadoop 45 1月 18 15:11 hi.txtCopy the code

Delete files and directories

[hadoop@hadoop01 data]$rm -i newhello.log # delete file 'newhello.log' N [hadoop@hadoop01 data]$rm -r logs # delete directory -r: recursive delete information [hadoop@hadoop01 data]$rm -ri orderlog/ #-i: query before deleteCopy the code

The file to view

【cat】 View all, [hadoop@hadoop01 data]$cat hdfs-site. XML [wc] [hadoop@hadoop01 data]$wc -l Hadoanode-hadoop01.log #-l:line [hadoop@hadoop01 data]$head -2 hdFs-site. XML [tail]$head -2 hdFs-site. XML [tail]$head -2 hdFs-site. XML [tail] Tail -1 hadoop-hadoop-datanode-hadoop01.log # Check the last line of the logCopy the code

User management

User group operation

[hadoop@hadoop01 data]$sudo vi /etc/group # query group [hadoop@hadoop01 data]$sudo groupadd hainan02 # create group [hadoop@hadoop01 Data]$sudo vi /etc/group. hainan02:x:1004: [hadoop@hadoop01 data]$sudo groupdel hainan02 # delete a groupCopy the code

The user action

[hadoop@hadoop01 data]$sudo vi /etc/passwd # query user list [add tianqi to hainan02] [hadoop@hadoop01 data]$sudo useradd Tianqi - 1004 # 1004 g group number [hadoop @ hadoop01 data] $sudo vi/etc/passwd tianqi: x: 1004-1004: : / home/tianqi: / bin/bash: X (encrypted password) 1004:1004 -> first 1004(user number), the latter 1004(assigned group number) /home/tianqi -> home of the current user Hainan03 [hadoop@hadoop01 data]$sudo groupAdd hainan03 [hadoop@hadoop01 data]$sudo usermod tianqi -g 1005 # Tianqi: x: : 1004-1005: / home/tianqi: / bin/bash # after the adjustment effect 【 password 】 [hadoop @ hadoop01 data] $sudo passwd tianqi [delete a user, [hadoop@hadoop01 data]$sudo userdel -r tianqiCopy the code

Linux file permission management

Introduction to File Permissions

Log -rw-rw-r-- (1,3,3,3): file type, file permission 1) File type d: Yes directory -: Yes file L: yes File hyperlink 2) File permission (r:read read w: write write x:execute) RW-RW-r -- 2.1) rw-: indicates the permission of the current owner on the file 2.2) rw-: indicates the permission of the current owner on the file. Current owning Group member's permissions on this file 2.3) r--: Permissions of other users on this fileCopy the code

The first line of information is drwxrwxr-x 2 hadoop Hadoop 6 January 21 11:18 data

D for data is a directory class

First RWX: the current owner has read, write, and execute permissions on this file.

Two Hadoop representatives: The proponents of this file are Hadoop users, Hadoop groups

Therefore, hadoop users can read, write and execute the data directory

Second RWX: indicates that the file can be read, written, and executed by the members of the current owning group, which is a Hadoop group

Part III R-x: indicates that other users can read, write and execute the file

Modify file permissions [chmod]

U, G, O or 4, 2, 1

[hadoop@hadoop01 data]$PWD /opt/ data-rw-r --r-- 1 hadoop Hadoop 1380 1月 18 15:33 hdFs-site.xml U: user g: group O: other users [hadoop@hadoop01 data]$sudo chmod g+w hdfs-site. XML [hadoop@hadoop01 data]$sudo chmod g-r,o+w,u+x hdfs-site.xml Read :4 Write :2 execute:1 4+2+1=7 Read, write, and execute [hadoop@hadoop01 data]$sudo chmod 777 hdfs-site.xml Read, write, and execute for all#Each 7 represents a role, and 7 represents full permissions

Copy the code

Modify file or directory owner [chown]

Requirement 1: Make hdFS-site. XML belong to tianqi user and Hainan02 group.#Change the effect before-rwxrwxrwx 1 hadoop hadoop 1380 January 18 15:33 hdfs-site.xml#Implement changes
[hadoop@hadoop01 data]$ sudo chown tianqi:hainan02 hdfs-site.xml
#The effect after the change-rwxrwxrwx 1 tianqi hainan02 1380 1月 18 15:33 hdFs-site.xml [hadoop@hadoop01 data]$sudo chown -r tianqi:hainan02Copy the code