01基础命令

Linux基础命令

了解linux基本原则

Linux的基本原则

  • 由目的单一的小程序组成,组合小程序完成复杂任务;
  • 一切皆文件;
  • 配置文件保存为纯文本格式。

什么是shell

shell(外壳),广义的shell可以理解为是用户的工作环境,在windows看来桌面就是一个shell,在linux看来终端就是shell

常见的shell有两种,一种是图形界面,即GUI,一种是命令行终端,即CLI。

常见的shell有哪些

常用的GUI:Graphic User Interface

  • Windows
  • X-Window
  • Gnome
  • KDE
  • Xface

常用的CLI:Command Line Interface

  • bash
  • sh
  • csh
  • zsh
  • ksh
  • tcsh

了解bash的特性

Bash的特性

  • 支持命令历史、命令补全、路径补全
[root@localhost ~]# history 
    1  cd /etc/sysconfig/network-scripts/
    2  ls
    3  vi ifcfg-ens33
    4  ip ad
[root@localhost ~]# !2
ls
anaconda-ks.cfg

  • 支持管道、重定向
[root@localhost ~]# cat anaconda-ks.cfg
。。。

[root@localhost ~]# cat anaconda-ks.cfg | grep pwpolicy
pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
[root@localhost ~]# cat anaconda-ks.cfg | grep pwpolicy > 123
[root@localhost ~]# ls
123  anaconda-ks.cfg
[root@localhost ~]# cat 123
pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty

  • 支持命令别名
[root@localhost ~]# alias 1='cd /etc/sysconfig/network-scripts/'
[root@localhost ~]# 1
[root@localhost network-scripts]# cd
[root@localhost ~]# alias 
alias 1='cd /etc/sysconfig/network-scripts/'
alias cp='cp -i'
  • 支持命令行编辑

  • 这个有手就能明白!!!

  • 支持命令行展开

[root@localhost ~]# mkdir -p a/{b/{d,e},c} 
[root@localhost ~]# tree a
a
├── b
│   ├── d
│   └── e
└── c

  • 支持文件名通配
[root@localhost ~]# ls
123  a  anaconda-ks.cfg
[root@localhost ~]# ls a*
anaconda-ks.cfg

a:
b  c

  • 支持变量
[root@localhost ~]# a=1
[root@localhost ~]# echo $a
1

  • 支持编程

Bash支持的引号

  • 反引号,键盘左上角Esc下面的键,用于命令替换
  • 双引号,弱引用,可以实现变量替换
  • 单引号,强引用,不完成变量替换
  • eg:
[root@localhost ~]# echo $a
1
[root@localhost ~]# echo '$a'
$a
[root@localhost ~]# echo "$a"
1
[root@localhost ~]# echo $(pwd)
/root
[root@localhost ~]# echo `$a`                   
-bash: 1: 未找到命令

[root@localhost ~]# echo `pwd`
/root

Bash常用操作技巧之光标跳转

  • Ctrl+a 跳到命令行首
  • Ctrl+e 跳到命令行尾
  • Ctrl+u 删除光标至命令行首的内容
  • Ctrl+k 删除光标至命令行尾的内容
  • Ctrl+<-- 光标定位到离自己最近的一个单词前面
  • Ctrl+l 清屏

Bash常用操作技巧之命令历史

[root@localhost ~]# history         //命令用于查看命令历史
    1  history 
    2  ls
    3  cd
    4  history 
[root@localhost ~]# history -d 3        //删除第n条命令的历史

[root@localhost ~]# history 
    1  history 
    2  ls
    3  history 
    4  history -d 3
    5  history 
[root@localhost ~]# history -w          //保存命令历史至历史文件~/.bash_history中
[root@localhost ~]# history -c          //清空命令历史

Bash常用操作技巧之命令历史(二)

[root@localhost ~]# !-2                 //执行第二条历史
ls
123  a  anaconda-ks.cfg
[root@localhost ~]# history 
    1  history 
    2  ls
    3  history 
    4  history -d 3
    5  history 
    6  history -w
    7  ! 2
    8  ls
    9  ! 2
   10  ls
   11  history 
[root@localhost ~]# 
[root@localhost ~]# 
[root@localhost ~]# !-4                 //执行倒数第四条历史
ls
123  a  anaconda-ks.cfg
[root@localhost ~]# history 
    1  history 
    2  ls
    3  history 
    4  history -d 3
    5  history 
    6  history -w
    7  ! 2
    8  ls
    9  ! 2
   10  ls
   11  history 
   12  ls
   13  history 
   14  cd
   15  history 
[root@localhost ~]# !c          //执行命令历史中最近一个以指定字符串c开头的命令
cd
[root@localhost ~]# ltrtrgfgftghubuh  ls
-bash: ltrtrgfgftghubuh: 未找到命令
[root@localhost ~]# !$          //引用前一条命令的最后一个参数
ls
123  a  anaconda-ks.cfg

  • esc+.:按下ESC键松开后立即按 . 键,引用前一条命令的最后一个参数

Bash常用操作技巧之命令补全

  • 搜索PATH环境变量所指定的每个路径下以我们给出的字符串开头的可执行文件,如果多于一个,敲2次tab键将会得到一个以我们给出的字符串开头的文件列表,否则将直接补全。

Bash常用操作技巧之路径补全

  • 摁TAb就完事了!!!

Bash常用操作技巧之命令别名

[root@localhost ~]# alias 1='cd /etc/sysconfig/network-scripts/'
[root@localhost ~]# 1
[root@localhost network-scripts]# cd
[root@localhost ~]# alias 
alias 1='cd /etc/sysconfig/network-scripts/'
alias cp='cp -i'

Bash常用操作技巧之命令替换

[root@localhost ~]# echo $(pwd)
/root
[root@localhost ~]# echo `$a`                   
-bash: 1: 未找到命令

[root@localhost ~]# echo `pwd`
/root

Bash常用操作技巧之命令行展开

[root@localhost ~]# mkdir -p a/{b/{d,e},c} 
[root@localhost ~]# tree a
a
├── b
│   ├── d
│   └── e
└── c

Bash环境变量介绍

  • PATH:命令搜索的路径
[root@localhost ~]# which ls
alias ls='ls --color=auto'
	/usr/bin/ls
[root@localhost ~]# /usr/bin/ls
123  a	anaconda-ks.cfg
[root@localhost ~]# ls
123  a  anaconda-ks.cfg
[root@localhost ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

  • HISTSIZE:定义命令历史最多能存多少条,默认为1000条
  • SHELL:当前系统使用的shell
[root@localhost ~]# echo $HISTSIZE
1000
[root@localhost ~]# HISTSIZE=5          //临时修改
[root@localhost ~]# history 
   38  echo $HISTSIZE
   39  history = 5
   40  echo $HISTSIZE
   41  HISTSIZE=5
   42  history 
   
   
   [root@localhost ~]# echo $SHELL          //查看当前系统使用的shell
/bin/bash

 

掌握linux常用基础命令

命令语法

  • <命令> [选项] [参数]
  • 选项:(可以有0个或多个)
  • 短选项:-
    多个选项可以组合: -a -b = -ab
  • 长选项:–
    长选项通常不能组合
  • 参数:命令的作用对象(可以有0个或多个)

命令类型

  • 内部命令:shell内置
  • 外部命令:在文件系统的某个路径下有一个与命令名称相对应的可执行文件
  • type 用来查看某条命令是何种类型
[root@localhost ~]# type ls
ls 是 `ls --color=auto' 的别名
[root@localhost ~]# type cd
cd 是 shell 内嵌
[root@localhost ~]# type echo
echo 是 shell 内嵌

基础命令之ls

  • ls命令用于列出指定目录的内容
  • -l:这里是小写的L,不是数字1,长格式显示
[root@localhost ~]# ls -l
总用量 8
-rw-r--r--. 1 root root  224 9月   7 15:23 123
drwxr-xr-x. 4 root root   24 9月   7 15:41 a
-rw-------. 1 root root 1412 9月   3 15:02 anaconda-ks.cfg

  • -h:做单位转换
[root@localhost ~]# ls -lh          //一般组合用
总用量 8.0K
-rw-r--r--. 1 root root  224 9月   7 15:23 123
drwxr-xr-x. 4 root root   24 9月   7 15:41 a
-rw-------. 1 root root 1.4K 9月   3 15:02 anaconda-ks.cfg

  • -a:显示隐藏文件
[root@localhost ~]# ls -a
.  ..  123  a  anaconda-ks.cfg  .bash_history  .bash_logout  .bash_profile  .bashrc  .cshrc  .tcshrc
[root@localhost ~]# ls
123  a  anaconda-ks.cfg

  • -d:显示目录自身的属性
[root@localhost ~]# ls -dl a
drwxr-xr-x. 4 root root 24 9月   7 15:41 a
[root@localhost ~]# ls -d a
a

  • -t:以时间排序
[root@localhost ~]# ls -l
总用量 8
-rw-r--r--. 1 root root  224 9月   7 15:23 123
drwxr-xr-x. 4 root root   24 9月  10 18:53 a
-rw-------. 1 root root 1412 9月   3 15:02 anaconda-ks.cfg
-rw-r--r--. 1 root root    0 9月  10 18:53 b
[root@localhost ~]# ls -lt
总用量 8
-rw-r--r--. 1 root root    0 9月  10 18:53 b
drwxr-xr-x. 4 root root   24 9月  10 18:53 a
-rw-r--r--. 1 root root  224 9月   7 15:23 123
-rw-------. 1 root root 1412 9月   3 15:02 anaconda-ks.cfg

  • -r:逆序显示
[root@localhost ~]# ls -l
总用量 8
-rw-r--r--. 1 root root  224 9月   7 15:23 123
drwxr-xr-x. 4 root root   24 9月  10 18:53 a
-rw-------. 1 root root 1412 9月   3 15:02 anaconda-ks.cfg
-rw-r--r--. 1 root root    0 9月  10 18:53 b
[root@localhost ~]# ls -lt
总用量 8
-rw-r--r--. 1 root root    0 9月  10 18:53 b
drwxr-xr-x. 4 root root   24 9月  10 18:53 a
-rw-r--r--. 1 root root  224 9月   7 15:23 123
-rw-------. 1 root root 1412 9月   3 15:02 anaconda-ks.cfg

  • 常见文件类型

  • -普通文件

  • d目录文件

  • c字符设备文件

  • b块设备文件

  • l链接文件

  • s套接字

[root@localhost ~]# ls -l /dev
总用量 0
crw-rw----. 1 root video    10, 175 9月   7 11:29 agpgart
crw-------. 1 root root     10, 235 9月   7 11:29 autofs
drwxr-xr-x. 2 root root         160 9月   7 11:29 block
drwxr-xr-x. 2 root root          80 9月   7 11:29 bsg
crw-------. 1 root root     10, 234 9月   7 11:29 btrfs-control
drwxr-xr-x. 3 root root          60 9月   7 11:29 bus
lrwxrwxrwx. 1 root root           3 9月   7 11:29 cdrom -> sr0
drwxr-xr-x. 2 root root        2880 9月   7 11:29 char
crw-------. 1 root root      5,   1 9月   7 11:29 console
lrwxrwxrwx. 1 root root          11 9月   7 11:29 core -> /proc/kcore
drwxr-xr-x. 4 root root         100 9月   7 11:29 cpu
crw-------. 1 root root     10,  61 9月   7 11:29 cpu_dma_latency
crw-------. 1 root root     10,  62 9月   7 11:29 crash
drwxr-xr-x. 6 root root         120 9月   7 11:29 disk
brw-rw----. 1 root disk    253,   0 9月   7 11:29 dm-0
brw-rw----. 1 root disk    253,   1 9月   7 11:29 dm-1
drwxr-xr-x. 2 root root          80 9月   7 11:29 dri
crw-rw----. 1 root video    29,   0 9月   7 11:29 fb0
lrwxrwxrwx. 1 root root          13 9月   7 11:29 fd -> /proc/self/fd

常用基础命令(一)

  • cd:切换目录
  • pwd:打印当前工作目录
[root@localhost ~]# cd /etc/sysconfig/network-scripts/ 
[root@localhost network-scripts]# cd
[root@localhost ~]# pwd     //打印工作目录  等同于 echo $PWD
/root
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# cd ~          //切换到家目录
[root@localhost ~]# cd -            //在两个目录直接来回切换
/etc/sysconfig/network-scripts
[root@localhost network-scripts]# cd -
/root
[root@localhost ~]# cd .
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# cd .
[root@localhost network-scripts]# cd ..     //切换到上一目录
[root@localhost sysconfig]# 

  • mkdir:创建目录
  • -p:创建目录时若父目录不存在则自动创建
  • -v:显示创建目录的过程
[root@localhost sysconfig]# mkdir -pv a/b/c/d/
mkdir: 已创建目录 "a"
mkdir: 已创建目录 "a/b"
mkdir: 已创建目录 "a/b/c"
mkdir: 已创建目录 "a/b/c/d/"

  • touch:创建空文件或更新时间戳
[root@localhost ~]# ls -l
总用量 8
-rw-r--r--. 1 root root  224 9月   7 15:23 123
drwxr-xr-x. 4 root root   24 9月  10 18:53 a
-rw-------. 1 root root 1412 9月   3 15:02 anaconda-ks.cfg
-rw-r--r--. 1 root root    0 9月  10 18:53 b
[root@localhost ~]# touch c
[root@localhost ~]# ls
123  a  anaconda-ks.cfg  b  c
[root@localhost ~]# touch b
[root@localhost ~]# ls -l
总用量 8
-rw-r--r--. 1 root root  224 9月   7 15:23 123
drwxr-xr-x. 4 root root   24 9月  10 18:53 a
-rw-------. 1 root root 1412 9月   3 15:02 anaconda-ks.cfg
-rw-r--r--. 1 root root    0 9月  10 19:34 b
-rw-r--r--. 1 root root    0 9月  10 19:34 c

  • stat:显示文件或文件系统的状态
[root@localhost ~]# stat b
  文件:"b"
  大小:0         	块:0          IO 块:4096   普通空文件
设备:fd00h/64768d	Inode:33575025    硬链接:1
权限:(0644/-rw-r--r--)  Uid:(    0/    root)   Gid:(    0/    root)
环境:unconfined_u:object_r:admin_home_t:s0
最近访问:2019-09-10 19:34:16.691621517 +0800
最近更改:2019-09-10 19:34:16.691621517 +0800
最近改动:2019-09-10 19:34:16.691621517 +0800
创建时间:-

  • rm:删除文件
  • -r:递归删除,删除目录时必须使用此选项
  • -f:强制删除,不询问
[root@localhost ~]# ls
123  a  anaconda-ks.cfg  b  c
[root@localhost ~]# rm b
rm:是否删除普通空文件 "b"?y
[root@localhost ~]# ls
123  a  anaconda-ks.cfg  c
[root@localhost ~]# rm -f c
[root@localhost ~]# ls
123  a  anaconda-ks.cfg
[root@localhost ~]# rm a
rm: 无法删除"a": 是一个目录
[root@localhost ~]# rm -f a
rm: 无法删除"a": 是一个目录
[root@localhost ~]# rm -r a         //删除目录必需加-r
rm:是否进入目录"a"? y
rm:是否进入目录"a/b"? y
rm:是否删除目录 "a/b/d"?y
rm:是否删除目录 "a/b/e"?y
rm:是否删除目录 "a/b"?n
rm:是否删除目录 "a/c"?n
[root@localhost ~]# tree a
a
├── b
└── c

2 directories, 0 files
[root@localhost ~]# rm -rf a        
[root@localhost ~]# ls
123  anaconda-ks.cfg

  • cp:复制文件,一个文件到一个文件,多个文件到一个目录
  • -a:归档复制,常用于备份
  • -r:递归拷贝,拷贝目录时必须使用此选项
  • -p:拷贝时保留原权限
[root@localhost ~]# ls
1  2  3  4  a  anaconda-ks.cfg  b  cc
[root@localhost ~]# cp 1 11         //两个文件
[root@localhost ~]# ls
1  11  2  3  4  a  anaconda-ks.cfg  b  cc
[root@localhost ~]# cp 1 2 3        //三个文件
cp: 目标"3" 不是目录
[root@localhost ~]# cp 1 2 a        //两个文件后面跟目录
[root@localhost ~]# tree a
a
├── 1
└── 2

0 directories, 2 files
[root@localhost ~]# cp a aa         //两个目录
cp: 略过目录"a"
[root@localhost ~]# cp -r a aa      //目录相关操作必需加-r
[root@localhost ~]# ls
1  11  2  3  4  a  aa  anaconda-ks.cfg  b  cc
[root@localhost ~]# cp -p b bb
cp: 略过目录"b"
[root@localhost ~]# cp -rp b bb     //拷贝时保留原权限
[root@localhost ~]# ll
总用量 4
-rw-r--r--. 1 root root    0 9月  11 14:26 1
-rw-r--r--. 1 root root    0 9月  11 14:27 11
-rw-r--r--. 1 root root    0 9月  11 14:26 2
-rw-r--r--. 1 root root    0 9月  11 14:26 3
-rw-r--r--. 1 root root    0 9月  11 14:26 4
drwxr-xr-x. 2 root root   24 9月  11 14:27 a
drwxr-xr-x. 2 root root   24 9月  11 14:28 aa
-rw-------. 1 root root 1412 9月   3 15:02 anaconda-ks.cfg
drwxr-xr-x. 2 root root    6 9月  11 14:26 b
drwxr-xr-x. 2 root root    6 9月  11 14:26 bb
-rw-r--r--. 1 root root    0 9月  11 14:21 cc

  • mv:移动文件
[root@localhost ~]# ls
2  a  anaconda-ks.cfg  b
[root@localhost ~]# mv 2 1      //同一位置移动,重命名
[root@localhost ~]# ls
1  a  anaconda-ks.cfg  b
[root@localhost ~]# mv 1 anaconda-ks.cfg b  //两个及以上文件,后面必需接目录
[root@localhost ~]# ls b
1  anaconda-ks.cfg
[root@localhost ~]# mv a b
[root@localhost ~]# ls b
1  a  anaconda-ks.cfg
[root@localhost ~]# ls
b
[root@localhost ~]# ls b
1  a  anaconda-ks.cfg
[root@localhost ~]# mv b/anaconda-ks.cfg ~
[root@localhost ~]# ls
anaconda-ks.cfg  b

常用基础命令(二)

  • cat:拼接文件内容并输出至标准输出(屏幕)
  • -n:显示行号
[root@localhost ~]# ls
1  2  3  anaconda-ks.cfg
[root@localhost ~]# echo 'wangwei' >1
[root@localhost ~]# echo 'wangwei' >2
[root@localhost ~]# cat 1
wangwei
[root@localhost ~]# cat 1 2
wangwei
wangwei
[root@localhost ~]# cat 3
[root@localhost ~]# cat 1 2 > 3
[root@localhost ~]# cat 3
wangwei
wangwei
[root@localhost ~]# cat -n 3
     1	wangwei
     2	wangwei

  • tac:连接文件并倒序打印内容至标准输出
[root@localhost ~]# cat 3
ajmdoj
wangwei
[root@localhost ~]# tac 3
wangwei
ajmdoj

  • more:全屏查看文本文件内容,只能从前往后看,看完自动退出
  • less:全屏查看文本文件内容,可从前往后看亦可从后往前看,看完不会自动退出

功能相同,less不会自动退出,需要按q,more不能前后翻。

  • head:从文件首部开始打印文件内容,默认打印10行
  • -n 15:查看文件前15行的内容
  • tail:从文件尾部开始打印文件内容,默认打印10行
  • -n 15:查看文件尾部15行的内容
  • -f:实时查看文件的更新
[root@localhost ~]# cat -n anaconda-ks.cfg | head -3        //查看文件前三行
     1	#version=DEVEL
     2	# System authorization information
     3	auth --enableshadow --passalgo=sha512
[root@localhost ~]# cat -n anaconda-ks.cfg | tail -3        //查看文件最后三行
    47	pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
    48	pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
    49	%end
[root@localhost ~]# cat -n anaconda-ks.cfg | head -5 | tail -1  //查看文件第五行
     5	repo --name="Server-ResilientStorage" --baseurl=file:///run/install/repo/addons/ResilientStorage
     
     
     
[root@localhost ~]# echo 'wang111' >>3
[root@localhost ~]# cat 3
ajmdoj
wangwei
wang111
[root@localhost ~]# echo 'sandlajnspd1' >>3
重开的第二个终端:
[root@localhost ~]# tail -f 3
ajmdoj
wangwei
wang111
sandlajnspd1
^H^H^C                  //ctrl+c 退出监控
[root@localhost ~]# tailf 3     //等同于tail -f 3
ajmdoj
wangwei
wang111
sandlajnspd1
^C

常用基础命令(三)

  • wc:文本统计
  • -c:统计文本字节数
  • -w:统计文本单词数
  • -l:统计文本行数
[root@localhost ~]# ls
1  2  3  anaconda-ks.cfg
[root@localhost ~]# wc -l anaconda-ks.cfg 
49 anaconda-ks.cfg
[root@localhost ~]# wc -c anaconda-ks.cfg 
1412 anaconda-ks.cfg
[root@localhost ~]# wc -w anaconda-ks.cfg 
125 anaconda-ks.cfg

  • du:查看文件或目录占用的磁盘空间大小
  • -s:显示总的占用空间大小
  • -h:单位转换,以更友好的方式显示大小
[root@localhost ~]# ls
1  2  3  a  anaconda-ks.cfg
[root@localhost ~]# tree a
a
├── b
│   └── d
└── c
    └── d

4 directories, 0 files
[root@localhost ~]# du a
0	a/b/d
0	a/b
0	a/c/d
0	a/c
0	a
[root@localhost ~]# echo 'sjadoaishdoash' >a
-bash: a: 是一个目录
[root@localhost ~]# mv 3 a
[root@localhost ~]# du -s a
4	a
[root@localhost ~]# du -sh a
4.0K	a

  • df:报告文件系统磁盘空间使用情况
  • -h:单位转换,以更友好的方式显示大小
[root@localhost ~]# df 
文件系统                 1K-块    已用     可用 已用% 挂载点
/dev/mapper/rhel-root 17811456  995160 16816296    6% /
devtmpfs               1921592       0  1921592    0% /dev
tmpfs                  1932652       0  1932652    0% /dev/shm
tmpfs                  1932652    8800  1923852    1% /run
tmpfs                  1932652       0  1932652    0% /sys/fs/cgroup
/dev/sda1              1038336  145812   892524   15% /boot
tmpfs                   386532       0   386532    0% /run/user/0
/dev/sr0               3963760 3963760        0  100% /mnt
[root@localhost ~]# df -h
文件系统               容量  已用  可用 已用% 挂载点
/dev/mapper/rhel-root   17G  972M   17G    6% /
devtmpfs               1.9G     0  1.9G    0% /dev
tmpfs                  1.9G     0  1.9G    0% /dev/shm
tmpfs                  1.9G  8.6M  1.9G    1% /run
tmpfs                  1.9G     0  1.9G    0% /sys/fs/cgroup
/dev/sda1             1014M  143M  872M   15% /boot
tmpfs                  378M     0  378M    0% /run/user/0
/dev/sr0               3.8G  3.8G     0  100% /mnt

常用基础命令(四)

  • hostname:查看或临时修改主机名,重开终端有效,重启失效
[root@localhost ~]# hostname 
localhost.localdomain
[root@localhost ~]# hostname wangwei
[root@localhost ~]# hostname 
wangwei
[root@localhost ~]# bash        //子shell
[root@wangwei ~]#           //重开终端生效

  • hostnamectl:查看或永久修改主机名,重开终端有效,重启依然有效
[root@wangwei ~]# hostnamectl set-hostname localhost        //永久修改
[root@wangwei ~]# cat /etc/hostname         //查看
localhost
[root@wangwei ~]# bash
[root@localhost ~]# hostname
localhost
[root@localhost ~]# hostnamectl
   Static hostname: localhost
         Icon name: computer-vm
           Chassis: vm
        Machine ID: 7750da3b0567423a9038e9ceb71cb049
           Boot ID: 901e0df582484eab8a6bb18f470bfda6
    Virtualization: vmware
  Operating System: Red Hat Enterprise Linux Server 7.4 (Maipo)
       CPE OS Name: cpe:/o:redhat:enterprise_linux:7.4:GA:server
            Kernel: Linux 3.10.0-693.el7.x86_64
      Architecture: x86-64

  • clear:清屏

ctrl+l 快捷键

  • whoami:显示当前登录用户
  • w:显示当前在线用户并显示其正在运行的命令
  • who:查看当前在线用户
[root@localhost ~]# whoami
root
[root@localhost ~]# who am i
root     pts/0        2019-09-11 13:55 (192.168.120.1)
[root@localhost ~]# who
root     tty1         2019-09-07 11:30
root     pts/0        2019-09-11 13:55 (192.168.120.1)
root     pts/1        2019-09-11 15:17 (192.168.120.1)
[root@localhost ~]# w
 15:51:26 up  9:04,  3 users,  load average: 0.00, 0.01, 0.05
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
root     tty1                      六11   22:16m  0.05s  0.05s -bash
root     pts/0    192.168.120.1    13:55    6.00s  0.82s  0.03s w
root     pts/1    192.168.120.1    15:17   31:50   0.03s  0.03s -bash

  • which:显示指定命令的绝对路径
  • cal:打印日历
[root@localhost ~]# which ls        //ls的绝对路径
alias ls='ls --color=auto'
	/usr/bin/ls
[root@localhost ~]# cal
      九月 2019     
日 一 二 三 四 五 六
 1  2  3  4  5  6  7
 8  9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30

[root@localhost ~]# cal 1937        //查看1937年的日历

  • ldd:查看指定程序有哪些依赖库文件
[root@localhost ~]# ldd /usr/bin/ls
	linux-vdso.so.1 =>  (0x00007ffe039f5000)
	libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f112bc91000)
	libcap.so.2 => /lib64/libcap.so.2 (0x00007f112ba8c000)
	libacl.so.1 => /lib64/libacl.so.1 (0x00007f112b882000)
	libc.so.6 => /lib64/libc.so.6 (0x00007f112b4bf000)
	libpcre.so.1 => /lib64/libpcre.so.1 (0x00007f112b25d000)
	libdl.so.2 => /lib64/libdl.so.2 (0x00007f112b058000)
	/lib64/ld-linux-x86-64.so.2 (0x000055c6e0dc8000)
	libattr.so.1 => /lib64/libattr.so.1 (0x00007f112ae53000)
	libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f112ac37000)

常用基础命令(五)

  • date:显示或设置日期与时间
  • -s:以字符串方式设置时间
  • 格式化输出时间:+
    %Y:年
    %m:月
    %d:日
    %H:时
    %M:分
    %S:秒
[root@localhost ~]# date
2019年 09月 11日 星期三 15:57:57 CST
[root@localhost ~]# date -s '2020'
2019年 09月 11日 星期三 20:20:00 CST
[root@localhost ~]# date
2019年 09月 11日 星期三 20:20:06 CST
[root@localhost ~]# date -s '2019-9-11 16:00:50'
2019年 09月 11日 星期三 16:00:50 CST
[root@localhost ~]# date
2019年 09月 11日 星期三 16:00:53 CST


[root@localhost ~]# mkdir $(date '+%y%m%d%H')       //引用当前时间做目录名字
[root@localhost ~]# ls
1  19091116  2  a  anaconda-ks.cfg

掌握查看命令帮助的方法

  • 内部命令:help COMMAND
[root@localhost ~]# type cd     //先用type是内部命令还是外部命令
cd 是 shell 内嵌
[root@localhost ~]# help cd
cd: cd [-L|[-P [-e]]] [dir]

  • 外部命令:COMMAND –help
[root@localhost ~]# type ls         //同上
ls 是 `ls --color=auto' 的别名
[root@localhost ~]# ls --help
用法:ls [选项]... [文件]...

  • -man手册:man COMMAND
[root@localhost ~]# man ls
[root@localhost ~]# man 1 ls        //查看关于ls第一章节man手册



LS(1)                                       User Commands                                      LS(1)

NAME
       ls - list directory contents

SYNOPSIS
       ls [OPTION]... [FILE]...

man手册注意事项

  • []:可选
  • <>:必选
  • …:可出现多次
  • |:多选一
  • {}:分组
  • NAME:命令名称及功能简要说明
  • SYNOPSIS:用法说明,包括可用的选项
  • DESCRIPTION:命令功能的详尽说明,可能包括每一个选项的意义
  • OPTIONS:说明每一个选项的意义
  • FILES:此命令相关的配置文件
  • BUGS:报告bug
  • EXAMPLES:命令示例
  • SEE ALSO:另外参照
  • 翻屏:空格(向后翻一屏),b键(向前翻一屏)
  • 查找:
  • /KEYWORD:从前往后查找KEYWORD
  • ?KEYWORD:从后往前查找KEYWORD
  • n:下一个匹配的行
  • N:前一个匹配的行
  • q:退出
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值