Primary school students self-study big data Chapter 1 Linux common commands (1)

content

1.vi/vim

1.1 What is

1.2 General Mode

1.3 Edit Mode

1.4 Command Mode

2. Help command

2.1 man

2.2 help

2.3 type

3. File directory class

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 > 和 >>

3.17 ln

3.18 history


1.vi/vim

1.1 What is

VI is the most versatile text editor in Unix and Unix-like operating systems.

The 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 VI editors.

1.2 General Mode

Open a file with vi/vim and go directly to normal mode (this is the default mode)

Common grammar

grammar

Function description

yy

Copy the current line of the cursor

y number y

Copy a section (from line to line)

p

Arrow move to destination line to paste

u

Undo previous step

dd

delete the current line of the cursor

d number d

Delete how many lines after the cursor (inclusive)

x

Cut a letter, equivalent to del

X

Cut a letter, equivalent to Backspace

is

copy a word

dw

delete a word

^

move to line header

$

move to end of line

1+shift+g

move to header, numbers

shift+g

move to footer

number+shift+g

move to target row

1.3 Edit Mode

Common grammar

button

Function

i

before the current cursor

a

after the current cursor

O

the line next to the current cursor line

I

top of the line where the cursor is located

A

the end of the line where the cursor is located

O

line above the current cursor line

1.4 Command Mode

Common grammar

Order

Function

:w

keep

:q

quit

:!

enforce

/word to find

n find next, N look up

:noh

unhighlight

: set no

show line number

:set nonu

close line number

:%s/old/new/g

replace content /g replace all content that matches

2. Help command

2.1 man

basic grammar

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

show description

information

Function

NAME

The name and one-line description of the command

SYNOPSIS

How to use commands

DESCRIPTION

In-depth discussion of command functions

EXAMPLES  

Example of how to use the command

SEE ALSO

Related topics (usually man pages)

2.2 help

basic grammar

help 命令 (功能描述:获得shell内置命令的帮助信息)

2.3 type

基本语法

type 命令 (功能描述:获得shell命令的类型)

[xxxx@hadoop1 ~]$ type cd
cd 是 shell 内  //说明是内嵌命令
[xxxx@hadoop1 ~]$ type ls
ls 是 `ls --color=auto' 的别

 

3.文件目录类

3.1 pwd

基本语法

pwd (功能描述:显示当前工作目录的绝对路径)

[root@hadoop1 opt]# pwd
/opt

 

3.2 ls

基本语法

ls [选项] [目录或是文件]

选项说明

选项

功能

-a

全部的文件,连同隐藏档( 开头为 . 的文件) 一起列出来(常用)

-l

长数据串列出,包含文件的属性与权限等等数据;(常用)等价于“ll”

[root@hadoop1 ~]# ll
总用量 8
-rw-r--r-- 1 root root 2 11月 25 21:22 swappiness~
-rw-r--r-- 1 root root 2 11月 26 10: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
总用量 68
dr-xr-x---.  5 root root 4096 4月   7 18:28 .
dr-xr-xr-x. 20 root root 4096 4月   6 16:03 ..
-rw-r--r--   1 root root 6775 4月   6 19:16 .bash_history
-rw-r--r--.  1 root root   18 12月 29 2013 .bash_logout
-rw-r--r--.  1 root root  176 12月 29 2013 .bash_profile
-rw-r--r--.  1 root root  176 12月 29 2013 .bashrc
-rw-r--r--.  1 root root  100 1

 

3.3 cd

基本语法

cd  [参数]

参数说明

参数

功能

cd 绝对路径

切换路径

cd相对路径

切换路径

cd ~或者cd

回到自己的家目录

cd -

回到上一次所在目录

cd ..

回到当前目录的上一级目录

cd -P

跳转到实际物理路径,而非快捷方式路径

[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

基本语法

mkdir [选项] 要创建的目录

选项说明

选项

功能

-p

创建多层目录

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

 

3.5 rmdir

基本语法

rmdir 要删除的空目录

[root@hadoop1 www]$ rmdir eeee

 

3.6 touch

基本语法

touch 文件名称

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

 

3.7 cp

基本语法

cp [选项] source dest (功能描述:复制source文件到dest)

选项说明

选项

功能

-r

递归复制整个文件夹

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

 

3.8 rm

基本语法

rm [选项] deleteFile (功能描述:递归删除目录中所有内容)

选项说明

选项

功能

-r

递归删除目录中所有内容

-f

强制执行删除操作,而不提示用于进行确认。

-v

显示指令的详细执行过程

[root@hadoop1 test]# rm a.txt
rm:是否删除普通文件 "a.txt"?yes
[root@hadoop1 test]# rm -f b.txt
[root@hadoop1 test]# rm -rf aaaa/

 

3.9 mv

基本语法

mv oldFile newFile (功能描述:重命名)

mv ./aaa/ bbb/ (功能描述:移动文件夹)

mv a.txt aaa/a.txt (功能描述:移动文件)

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

 

3.10 cat

基本语法

cat  [选项] 要查看的文件

选项说明

选项

功能描述

-n

显示所有行的行号,包括空行。

[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

基本语法

more 要查看的文件

操作说明

操作

功能说明

空白键 (space)

代表向下翻一页;

Enter

代表向下翻『一行』;

q

代表立刻离开 more ,不再显示该文件内容。

Ctrl+F

向下滚动一屏

Ctrl+B

返回上一屏

=

输出当前行的行号

:f

输出文件名和当前行的行号

[root@hadoop1 test]# more README.txt

 

3.12 less

基本语法

less 要查看的文件

操作说明

操作

功能说明

空白键

向下翻动一页;

[pagedown]

向下翻动一页

[pageup]

向上翻动一页;

/字串

向下搜寻『字串』的功能;n:向下查找;N:向上查找;

?字串

向上搜寻『字串』的功能;n:向上查找;N:向下查找;

q  

离开 less 这个程序;

[root@hadoop1 test]# less README.txt

3.13 echo

基本语法

echo [选项] [输出内容]

选项:

-e:  支持反斜线控制的字符转换

控制字符  

作用

\\  

输出\本身

\n  

换行符

\t  

制表符,也就是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 "\033[34m 蓝色字 \033[0m" 
 蓝色字 

扩展 带颜色输出:

echo -e "\033[字背景颜色;文字颜色m 字符串 \033[0m" 同时添加字背景颜色和文字颜色

echo -e "\033[文字颜色m 字符串 \033[0m" 仅添加文字颜色

字体颜色

echo -e "\033[30m 黑色字 \033[0m"
echo -e "\033[31m 红色字 \033[0m"
echo -e "\033[32m 绿色字 \033[0m"
echo -e "\033[33m 黄色字 \033[0m"
echo -e "\033[34m 蓝色字 \033[0m" 
echo -e "\033[35m 紫色字 \033[0m" 
echo -e "\033[36m 天蓝字 \033[0m" 
echo -e "\033[37m 白色字 \033[0m"

字背景颜色

echo -e "\033[40;37m 黑底白字 \033[0m"
echo -e "\033[41;37m 红底白字 \033[0m" 
echo -e "\033[42;37m 绿底白字 \033[0m" 
echo -e "\033[43;37m 黄底白字 \033[0m" 
echo -e "\033[44;37m 蓝底白字 \033[0m" 
echo -e "\033[45;37m 紫底白字 \033[0m" 
echo -e "\033[46;37m 天蓝底白字 \033[0m" 
echo -e "\033[47;30m 白底黑字 \033[0m"

最后面控制选项说明

\33[0m 关闭所有属性 
\33[1m 设置高亮度 
\33[4m 下划线 
\33[5m 闪烁 
\33[7m 反显 
\33[8m 消隐 
\33[30m — \33[37m 设置前景色 
\33[40m — \33[47m 设置背景色 
\33[nA 光标上移n行 
\33[nB 光标下移n行 
\33[nC 光标右移n行 
\33[nD 光标左移n行 
\33[y;xH设置光标位置 
\33[2J 清屏 
\33[K 清除从光标到行尾的内容 
\33[s 保存光标位置 
\33[u 恢复光标位置 
\33[?25l 隐藏光标 
\33[?25h 显示光标

  

3.14 head

基本语法

head 文件       (功能描述:查看文件头10行内容)

head -n 5 文件      (功能描述:查看文件头5行内容,5可以是任意行数)

2)选项说明

选项

功能

-n<行数>

指定显示头部内容的行数

[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

基本语法

(1)tail  文件 (功能描述:查看文件尾部10行内容)

(2)tail  -n  5 文件 (功能描述:查看文件尾部5行内容,5可以是任意行数)

(3)tail  -f  文件 (功能描述:实时追踪该文档的所有更新)

(4)tail  -5f  文件 或者 tail  -fn 5 文件 (功能描述:查看文件尾部5行内容,5可以是任意行数 并且 实时追踪该文档的所有更新)

2) 选项说明

选项

功能

-n<行数>

输出文件尾部n行内容

-f

显示文件最新追加的内容,监视文件变化

[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 > 和 >>

基本语法

(1)ls -l  > 文件 (功能描述:列表的内容写入文件a.txt中(覆盖写))

(2)ls -al  >> 文件 (功能描述:列表的内容追加到文件aa.txt的末尾)

(3)cat 文件1 > 文件2 (功能描述:将文件1的内容覆盖到文件2)

(4)echo “内容” >> 文件

[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

基本语法

ln -s [原文件或目录] [软链接名] (功能描述:给原文件创建一个软链接)

经验

删除软链接: rm -rf 软链接名,而不是rm -rf 软链接名/

如果使用 rm -rf 软链接名/  删除,会把软链接对应的真实目录下内容删掉

查询:通过ll就可以查看,列表属性第1位是l,尾部会有位置指向。

[root@hadoop1 test]# rm -rf a.txtln
[root@hadoop1 test]# ln -s aaa aaa.ln
[root@hadoop1 test]# ll
总用量 36
drwxrw-rw- 2 root    root    4096 4月   8 09:32 aaa
lrwxrwxrwx 1 root    root       3 4月   8 10:13 aaa.ln -> aaa

 

3.18 history

基本语法

history (功能描述:查看已经执行过历史命令)

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

 

{{o.name}}
{{m.name}}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324144416&siteId=291194637