[Linux] - sort Linux common commands


After I read a lot of bloggers blog found that many bloggers write very good, is feeling confused, I think is also very hard, and now I try to write with a relatively simple statement can strand clear idea of ​​Linux basic commands

1, the basic format of the command

Open your virtual machine, as shown below:
Here Insert Picture Description

2, the contents of the directory inquiry

命令格式 :ls [选项][文件或者目录]
选项:
-a  显示所有文件
-l  查看详情
-d  查看目录属性
-h  显示文件大

3, catalog processing command

  3.1 build directory

mkdir -p [目录名]
-p 表示递归的创建文件夹

例如:mkdir  practice
mkdir -p practice/practice1

Here Insert Picture Description
  3.2 Change directory

cd [目录]
简化操作:
cd~ 进入当前用户目录
cd- 上次目录
cd.. 进入上一级目录
pwd 查看当前目录所在位置

Here Insert Picture Description
  3.3 delete the directory

rmdir [目录]   //删除所有目录

  3.4 Copy directory

cp [选项][源文件目录][目标目录]
选项:
-r 复制目录
-p 连文件属性一起复制

  3.5 Cut, renamed

mv [源文件目录][目标文件目录]
例如:mv practice1 practice2  //将practice1的名字改为practice2

  3.6 Role of the common directory

/ 根目录
/bin 命令保存目录
/boot 启动目录
/dev 设置文件命令
/home 家目录
/lib 系统库保存命令

4, file related commands

  4.1 Create a file

touch [选项][文件名]  //创建一个新文件,刷新时间,若文件不存在,则创建一个空文件,若存在,则刷新文件的时间属性
选项:
-a 只更改存取时间
-m 修改文件的变动时间
-t 使用指定的日期时间,而非现在的时间
-c 如果要修改的文件不存在,则加上-c使得touch不去创建它
-r 把制定文档或者目录的日期时间,统统设定成和参考文档或者目录的日期时间相同
-t 使用指定的日期时间,而非现在的时间

  4.2 Delete Files

rm [选项][文件名]
功能:删除指定文件名或者目录名
常用选项:
-f 即使文件属性为只读,也直接删除
-i 删除前逐一询问确认
-r 删除目录以及以下所有文件

  4.3 cat


【命令作用】
连接文件并在标准输出上输出。这个命令常用来显示文件内容,或者将几个文件连接起来显示,或者从标准输入读取内容并显示,它常与重定向符号配合使用。
【命令语法】
cat    [选项]    [文件名]
【常用选项】
-E  --在每行结束显示 $
-n  --给所有输出行编号
-v  --使用 ^ 和 M- 引用,除了 LFD 和 TAB 之外
# cat 123 456 > 789  //将123和456的内容输入到789里
# cat -E 123  //显示123文件内容和换行符
# cat 123  //显示123文件内容
# cat -n 123  //显示123文件内容和行号

  4.4 echo

【命令作用】
 在显示器上显示一段文字,一般起到一个提示的作用
 补充说明:echo会将输入的字符串送往标准输出。输出的字符串间以空白字符隔开, 并在最后加上换行号。
【命令语法】
 echo    [选项]    [ 需要打印的内容或变量]
【常用选项】
 -e  --允许下面列出的加反斜线转义的字符进行解释
         \n   --换行符
         \f    --换页符
         \t    --水平制表符
         \v   --纵向制表符

【命令示例】
# echo 'Welcome To WCZY'    //文本的直接输入:
# bl="Welcome To WCZY" //输出变量的值:假设定义一个变量
# echo $bl  //解释:bl是定义的变量名,=号后面是赋值,字符串需要用“”括起来。$后面直接跟上变量名即可

  4.5 grep

【命令作用】
文本过滤,模糊查找
【命令语法】
grep    [选项]    [需要查找的内容]    [文件名]
【常用选项】
--color=auto  --对匹配到的文本着色显示
-v  --显示不能够被pattern匹配到的行
-i   --忽略字符大小写
-n  --显示行号
-q  --静默模式,不输出任何信息;
-A #  --after, 后#行
-B #  --before, 前#行
-C #  --context, 前后各#行

【命令示例】
# grep a  /123  //在根目录下的文件123中查找含字母a的行
# grep -i a /123 //在根目录下的文件123中查找含a或者A的行
# grep -n a /123  //在根目录下的文件123中查找含a的行,并显示行号
# grep -v a /123  //在根目录下的文件123中查找不含a的行

  4.6 more

cat命令是整个文件的内容从上到下显示在屏幕上。 more会以一页一页的显示方便使用者逐页阅读,而最基本的指令就是按空白键(space)就往下一页显示,按 b 键就会往回(back)一页显示.
【命令语法】
more    [选项]    [参数]
【常用选项】
无
【参数说明】
文件名
【命令示例】
# more [文件名]  //分屏查看指定文件内容
# more +3 /123  //显示文件中从第3行起的内容
# more +/1a /123 //从文件中查找第一个出现"1a"字符串的行,并从该处前两行开始显示输出 

  4.6 less

【命令作用】
在 more 的时候,我们并没有办法向前面翻, 只能往后面看,但若使用了 less 时,就可以使用 [pageup] [pagedown] 等按键的功能来往前往后翻看文件,更容易用来查看一个文件的内容!
【命令语法】
less    [选项]    [文件名]
【常用选项】
无
【命令示例】
# less 123  //查看文件123内容
# ps -ef |less  //ps查看进程信息并通过less分页显示
# less 123 456  //浏览多个文件

5, file search command

  5.1 locate

locate [文件名]
在系统数据库中查找文件的新建文件,要执行updatedb操作之后才能搜到

  5.2 Command Search

whereis  [选项][命令名]
或者
which [选项][命令名]
选项:
-b 只查找可执行文件
-m 只查找帮助文件

  File Search 5.3

find [搜索范围][选项][条件]
例如:find / name test1.log   //在跟目录下查找名为test1.log的文件
find /var/log -mtime +10   //查找10天前修改的文件
fid /etc -size +20M   //差早文件大于20M的文件

6, compression and decompression command

Common compression formats: .zip, .gz, .bz2, .tar.gz, .tar.bz2

  6.1 zip format

zip  [压缩文件名][源文件]
zip  -r [压缩文件名][源文件]
例如:zip -r jp.zip jp

解压:
unzip [压缩文件名]

  6.2 .gz format

gzip [源文件]  //压缩为gz格式,源文件不保留
gzip -c 源文件 > 压缩文件   //压缩为gz格式,源文件保留
gzip -r 目录 //压缩目录

解压:
gunzip [文件]
guzip -r [目录]

  6.3 tar

tar -cvf  [打包文件名]  [源文件]  //打包
tar -xvf [文件名].tar   //解压

  6.4 .tar.gz format

tar  -zcvf  压缩包名.tar.gz 源文件  //打包
tar  -zxvf 压缩包.tar.gz    //解压

7, network-related

  7.1 ipconfig ip View

例如:ifconfig>> ip.log
cat ip.log  //获取IP地址后打印到终端

  7.2 View network status

netstart [选项]
选项:
-t: 列出tcp协议端口
-u:列出udp协议端口
-n IP地址个端口号
-a 所有

  7.3 View routing list

netstart -rn
或者
route -n

8, vim editor

  8.1 vim mode of operation

commond mode 命令模式
inser tmode 编辑模式
lastline mode 底行模是

  Mode switch 8.2

i 进入编辑模式
esc 键入命令行模式

  8.3 Command Mode

vim [文件]   //键入文件或者创建文件
vim [文件名]  //进入文件尾部
vim +/[字符串][文件名]  //光标定位到第一次出现该字符串的位置

  8.4 line mode

:w 保存
:q 退出
:! 轻质
/[字符串]  光标位置向后搜索该字符串
?[字符串]  光标位置向前搜索该字符串
dd 删除光标所在行
ctrl+f  向下翻页
ctrl+b  向上翻页

9, rights management

Rights Management: UNIX permissions: u (rwx) g (rwx) o (rwx)

Wherein:
R & lt - read permission
w - writable
x - executable permissions

For example: complete information -rwxrw-r- is represented: a file that belongs to a user with read-write executables permission, the group members have read and write permissions, no executable permissions, other users only read access. Specific meaning as shown below:
Here Insert Picture Description
then we use the numbers: r = 4 w = 2 x = 1

For example: rwx = 7 (4 + 2 + 1); rw = 6 (4 + 2 + 0); rw = 5 (4 + 0 + 1); r- = 4 (4 + 0 + 0)

If you give a document conferring a privilege, the statement is as follows:

#chmod 777 test1     //赋予test1可读可写可执行权限
#chmod 755  test2   //赋予文件test2:用户的可读可写可执行权限,所属组的可读可执行权限其他用户可读可执行权限
Published 42 original articles · won praise 13 · views 1760

Guess you like

Origin blog.csdn.net/Vicky_Cr/article/details/105337240