Primary school students learn big data by themselves Chapter 1 common commands of linux

catalogue

1.vi/vim

1.1 what is it

1.2 general mode

1.3 editing mode

1.4 command mode

2. Help command

2.1 man

2.2 help

2.3 type

3. File directory

3.1 pwd

3.2 ls

3.3 cd

3.4 mkdir

3.5 rmdir

3.6 touch

3.7 cp

3.8 rm

3.9 mv

3.10 cat

3.11 more

3.12 less

3.13 echo

3.14 head

3.15 tail

3.16 > and > >

3.17 ln

3.18 history

1.vi/vim

1.1 what is it

VI is the most common text editor in Unix operating system and Unix like operating system.

VIM editor is a more powerful text editor developed from VI. It can actively identify the correctness of grammar by font color, which is convenient for program design. VIM is fully compatible with the VI editor.

1.2 general mode

Open a file with vi/vim and directly enter the general mode (this is the default mode)

Common grammar

grammar

Function description

yy

Copy the current line of the cursor

Y number y

Copy a paragraph (from line to line)

p

Move arrow to destination line paste

u

Undo previous step

dd

Delete current line of cursor

D number d

How many lines after deleting cursor (including)

x

Cut a letter, equivalent to del

X

Cut a letter, which is equivalent to Backspace

yw

Copy a word

dw

Delete a word

^

Move to line header

$

Move to end of line

1+shift+g

Move to header, number

shift+g

Move to end of page

Number + shift+g

Move to target row

1.3 editing mode

Common grammar

Key

function

i

Before the current cursor

a

After the current cursor

o

The next line of the current cursor line

I

The front of the line where the cursor is located

A

Last line of cursor

O

The previous line of the current cursor line

1.4 command mode

Common grammar

command

function

:w

preservation

:q

sign out

:!

Enforcement

/Words to find

N find next, n find up

:noh

set nohlsearch

:set nu

set number

:set nonu

Close line number

:%s/old/new/g

Replace content / g replace all matching content

2. Help command

2.1 man

Basic grammar

man [command or configuration file] (function description: get help information)

Display description

information

function

NAME

Name and single line description of the command

SYNOPSIS

How to use commands

DESCRIPTION

In depth discussion of command functions

EXAMPLES  

Examples of how to use commands

SEE ALSO

Related topics (usually man pages)

2.2 help

Basic grammar

Help command (function description: get help information of shell built-in commands)

2.3 type

Basic grammar

Type command (function description: get the type of shell command)

[xxxx@hadoop1 ~]$ type cd
cd yes shell within  //Description is an embedded command
[xxxx@hadoop1 ~]$ type ls
ls yes `ls --color=auto' No, don't

 

3. File directory

3.1 pwd

Basic grammar

pwd (function description: displays the absolute path of the current working directory)

[root@hadoop1 opt]# pwd
/opt

 

3.2 ls

Basic grammar

ls [options] [directory or file]

Option description

option

function

-a

All files are listed together with hidden files (files starting with). Commonly used)

-l

Long data string listing, including file attributes, permissions and other data; (commonly used) equivalent to "ll"

[root@hadoop1 ~]# ll
 Total consumption 8
-rw-r--r-- 1 root root 2 11 May 25-21:22 swappiness~
-rw-r--r-- 1 root root 2 11 October 26:28 swappinesz~
[root@hadoop1 ~]# ls
swappiness~  swappinesz~
[root@hadoop1 ~]# ls -a
.              .bash_logout   .cshrc    .mysql_history     .ssh         .tcshrc
..             .bash_profile  .history  .oracle_jre_usage  swappiness~  .viminfo
.bash_history  .bashrc        .lesshst  .pki               swappinesz~
[root@hadoop1 ~]# ls -al
 Total dosage 68
dr-xr-x---.  5 root root 4096 4 July 18:28 .
dr-xr-xr-x. 20 root root 4096 4 June 16:03 ..
-rw-r--r--   1 root root 6775 4 June 19:16 .bash_history
-rw-r--r--.  1 root root   18 12 September 29, 2013 .bash_logout
-rw-r--r--.  1 root root  176 12 September 29, 2013 .bash_profile
-rw-r--r--.  1 root root  176 12 September 29, 2013 .bashrc
-rw-r--r--.  1 root root  100 1

 

3.3 cd

Basic grammar

cd [parameter]

Parameter description

parameter

function

cd absolute path

Switch path

cd relative path

Switch path

cd ~ or cd

Go back to your home directory

cd -

Return to the previous directory

cd ..

Return to the previous directory of the current directory

cd -P

Jump to the actual physical path instead of the shortcut path

[root@hadoop1 opt]# cd /root/
[root@hadoop1 ~]# cd -
/opt
[root@hadoop1 opt]# cd ../
[root@hadoop1 /]# cd /root/
[root@hadoop1 ~]# cd ~
[root@hadoop1 ~]# cd ../
[root@hadoop1 /]# cd

 

3.4 mkdir

Basic grammar

mkdir [options] directory to create

Option description

option

function

-p

Create multi tier directory

[xxxxx@hadoop1 test]$ mkdir qqq
[xxxxx@hadoop1 test]$ mkdir -p qqq/www/eeee

 

3.5 rmdir

Basic grammar

rmdir empty directory to delete

[root@hadoop1 www]$ rmdir eeee

 

3.6 touch

Basic grammar

touch file name

[root@hadoop1 qqq]$ touch 1.txt
[root@hadoop1 qqq]$ touch ./www/1.txt

 

3.7 cp

Basic grammar

cp [options] source dest (function description: copy source file to dest)

Option description

option

function

-r

Copy entire folder recursively

[root@hadoop1 test]# cp a.txt ./aaa
[root@hadoop1 test]# cp -r aaa aaaa

 

3.8 rm

Basic grammar

rm [options] deleteFile (function description: recursively delete all contents in the directory)

Option description

option

function

-r

Recursively delete all contents in the directory

-f

Force deletion without prompting for confirmation.

-v

Displays the detailed execution of the instruction

[root@hadoop1 test]# rm a.txt
rm: Delete normal file "a.txt"?yes
[root@hadoop1 test]# rm -f b.txt
[root@hadoop1 test]# rm -rf aaaa/

 

3.9 mv

Basic grammar

mv oldFile newFile (function description: rename)

mv ./aaa/ bbb / (function description: move folder)

mv a.txt aaa/a.txt (function description: moving files)

[root@hadoop1 aaa]# mv a.txt b.txt
[root@hadoop1 aaa]# mv ./b/ ../
[root@hadoop1 aaa]# mv b.txt ../

 

3.10 cat

Basic grammar

cat [options] files to view

Option description

option

Function description

-n

Displays the line numbers of all lines, including blank lines.

[root@hadoop1 test]# cat README.txt 
For the latust information about Hadoop, please visit our website at:
 
http://hadoop.apache.org/core/   
[root@hadoop1 test]# cat -n README.txt 
 1	For the latust information about Hadoop, please visit our website at:
 2	
 3	http://hadoop.apache.org/core/

 

3.11 more

Basic grammar

more files to view

Operating instructions

operation

Function description

Space key

Represents turning down a page;

Enter

Represents turning down "one line";

q

The representative leaves more immediately and no longer displays the contents of the file.

Ctrl+F

Scroll down one screen

Ctrl+B

Return to previous screen

=

Output the line number of the current line

:f

Output file name and line number of the current line

[root@hadoop1 test]# more README.txt

 

3.12 less

Basic grammar

less files to view

Operating instructions

operation

Function description

Blank key

Turn down a page;

[pagedown]

Turn down a page

[pageup]

Turn up a page;

/String

Search down for the function of "string"; n: Look down; N: Look up;

? string

The function of searching "string" upward; n: Look up; N: Look down;

q  

Leave the less program;

[root@hadoop1 test]# less README.txt

3.13 echo

Basic grammar

echo [options] [output content]

Options:

-e: Support character conversion controlled by backslash

Control character

effect

\\  

Output \ itself

\n  

Line feed

\t  

Tab, or tab

[root@hadoop1 test]# echo 666
666
[root@hadoop1 test]# echo "4444"
4444
[root@hadoop1 test]# echo -e "666\t666"
666	666
[root@hadoop1 test]# echo -e "3[34m blue words \ 033[0m" 
 Blue word 

Extended output with color:

echo -e "3 [word background color; text color M string \ 033[0m" add word background color and text color at the same time

echo -e "3 [text color M string \ 033[0m" add text color only

Font color

echo -e "\033[30m Black characters \033[0m"
echo -e "\033[31m Red character \033[0m"
echo -e "\033[32m Green word \033[0m"
echo -e "\033[33m Yellow character \033[0m"
echo -e "\033[34m Blue word \033[0m" 
echo -e "\033[35m Purple character \033[0m" 
echo -e "\033[36m Sky blue character \033[0m" 
echo -e "\033[37m White words \033[0m"

Word background color

echo -e "\033[40;37m White characters on black background \033[0m"
echo -e "\033[41;37m White characters on red background \033[0m" 
echo -e "\033[42;37m White characters on green background \033[0m" 
echo -e "\033[43;37m Yellow characters on a white background \033[0m" 
echo -e "\033[44;37m White characters on blue background \033[0m" 
echo -e "\033[45;37m White characters on purple background \033[0m" 
echo -e "\033[46;37m White characters on blue background \033[0m" 
echo -e "\033[47;30m Black characters on white background \033[0m"

Description of the last control option

\33[0m Close all properties 
\33[1m Set high brightness 
\33[4m Underline 
\33[5m twinkle 
\33[7m Reverse display 
\33[8m Blanking 
\33[30m — \33[37m set foreground color  
\33[40m — \33[47m Set background color 
\33[nA Move cursor up n that 's ok 
\33[nB Cursor down n that 's ok 
\33[nC Move cursor right n that 's ok 
\33[nD Move cursor left n that 's ok 
\33[y;xH Set cursor position 
\33[2J Clear screen 
\33[K Clears the contents from the cursor to the end of the line 
\33[s Save cursor position 
\33[u restore cursor position  
\33[?25l hide cursor 
\33[?25h Display cursor

  

3.14 head

Basic grammar

head file (function description: view the 10 lines of the file header)

head -n 5 # file (function description: view the contents of 5 lines in the file header, and 5 can be any number of lines)

2) Option description

option

function

-N < number of lines >

Specifies the number of rows to display header content

[root@hadoop1 test]# head README.txt 
For the latust information about Hadoop, please visit our website at:
   http://hadoop.apache.org/core/
   http://wiki.apache.org/hadoop/
and our wiki, at:
ribution  
[root@hadoop1 test]# head -n 1 README.txt 
For the latust information about Hadoop, please visit our website at:

 

3.15 tail

Basic grammar

(1) tail} file (function description: view the contents of the last 10 lines of the file)

(2) tail - n # 5 # file (function description: view the contents of 5 lines at the end of the file, and 5 can be any number of lines)

(3) tail - f# file (function description: track all updates of the document in real time)

(4) Tail - 5f # file or tail - fn 5 # file (function description: view the contents of 5 lines at the end of the file, 5 can be any number of lines, and track all updates of the document in real time)

2) Option description

option

function

-N < number of lines >

n lines at the end of the output file

-f

Display the newly added contents of the file and monitor the changes of the file

[root@hadoop1 test]# tail README.txt 
The following providus more details on the included cryptographic
software:
  Hadoop usus usus the SSL librarius from the Jetty project written 
by mortbay.org.
[root@hadoop1 test]# tail -n 1 README.txt 
by mortbay.org.
[root@hadoop1 test]# tail -fn 2 README.txt 
  Hadoop usus usus the SSL librarius from the Jetty project written 
by mortbay.org.
^C
[root@hadoop1 test]# tail -2f README.txt 
  Hadoop usus usus the SSL librarius from the Jetty project written 
by mortbay.org.
^C

 

3.16 > and > >

Basic grammar

(1) ls -l > file (function description: write the contents of the list into the file a.txt (overwrite write))

(2) ls -al > > file (function description: the contents of the list are appended to the end of the file aa.txt)

(3) cat file 1 > file 2 (function description: overwrite the contents of file 1 to file 2)

(4) echo "content" > > file

[root@hadoop1 test]# ls -l > b.txt 
[root@hadoop1 test]# ls -l >> b.txt 
[root@hadoop1 test]# cat README.txt >> b.txt 
[root@hadoop1 test]# echo "66666" >> b.txt

3.17 ln

Basic grammar

ln -s [original file or directory] [soft link name] (function description: create a soft link to the original file)

experience

Delete soft link: rm -rf soft link name instead of rm -rf soft link name/

If rm -rf soft link name / delete is used, the contents in the real directory corresponding to the soft link will be deleted

Query: you can view it through ll. The first bit of the list attribute is l, and there will be a position point at the end.

[root@hadoop1 test]# rm -rf a.txtln
[root@hadoop1 test]# ln -s aaa aaa.ln
[root@hadoop1 test]# ll
 Total consumption 36
drwxrw-rw- 2 root    root    4096 4 August 9:32 aaa
lrwxrwxrwx 1 root    root       3 4 August 10:13 aaa.ln -> aaa

 

3.18 history

Basic grammar

History (function description: view the history commands that have been executed)

[root@hadoop1 test]# history
    1  2020-11-21 14:20:05 root hostname

 

Added by phpknight on Wed, 09 Mar 2022 17:33:51 +0200