1.命令提示标识的含义
[root@guowei ~]#
[当前用户名@主机名 位置(当前位置为root家目录)] #表示root用户
[root@guowei ~]# su lisi
[lisi@guowei root]$ cd /home/lisi
当前用户为lisi@主机名为guowei 所在目录为root $表示普通用户
[lisi@guowei ~]$
2.常用快捷键
Ctrl+ALT 鼠标回到真机
Ctrl shift + 字体变大 Ctrl - 变小
Ctrl+c 结束正在运行的命令
Ctrl + l 清空整个屏幕
Ctrl + a 在命令行光标移动到行首
Ctrl + u 清空至行首
Ctrl + w 往回删除一个单词(以空格界定)
ALT + . 或 Esc + . 粘贴上一个命令的参数
3.常用命令
ifconfig 列出已激活网卡信息 后面可以指定网卡名,列出想要的网卡信息
[root@guowei ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.137.136 netmask 255.255.255.0 broadcast 192.168.137.255
....
[root@guowei ~]# ifconfig virbr0
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
....
uname -r/a 列出内核版本信息
[root@guowei ~]# uname -r
3.10.0-693.el7.x86_64
[root@guowei ~]# uname -a
Linux guowei 3.10.0-693.el7.x86_64 #1 SMP Thu Jul 6 19:56:57 EDT 2017 x86_64 x86_64 x86_64 GNU/Linux
lscpu 列出cpu处理器信息
[root@guowei ~]# lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 1
On-line CPU(s) list: 0
Thread(s) per core: 1
Core(s) per socket: 1
座: 1
NUMA 节点: 1
厂商 ID: GenuineIntel
CPU 系列: 6
型号: 142
型号名称: Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz
hostname 查看主机名
[root@guowei ~]# hostname
guowei
[root@guowei ~]# hostname wei #临时修改主机名
[root@guowei ~]# hostname
wei
[root@guowei ~]# cat /etc/hostname
guowei
[root@guowei ~]# hostnamectl set-hostname wei #永久修改主机名
[root@guowei ~]# hostname
wei
[root@guowei ~]# cat /etc/hostname
wei
[root@guowei ~]# vim /etc/hostname #或者修改配置文件永久修改主机名
pwd print working directory 查看当前位置
[root@guowei ~]# pwd
/root
cd change directory 切换目录
[root@guowei /]# cd /home
[root@guowei home]# cd /root
[root@guowei ~]# cd - # 返回上一次目录
/home
[root@guowei home]# cd .. #返回上一层目录
[root@guowei /]# cd . #当前目录
[root@guowei /]#
ls list 显示当前目录 格式:ls [选项]...[目录或文件名]...
-l 以长格式显示,显示目录内容的详细属性
-a 包括名称以 . 开头的隐藏文档
-d 显示目录本身(而不是内容)的属性
-h 提供易读的容量单位(K、M等)
-R 递归
[root@guowei /]# ls -l /
总用量 36
lrwxrwxrwx. 1 root root 7 4月 11 00:32 bin -> usr/bin
...
[root@guowei /]# ls -hl /
总用量 36K
lrwxrwxrwx. 1 root root 7 4月 11 00:32 bin -> usr/bin
dr-xr-xr-x. 4 root root 4.0K 4月 11 00:47 boot
...
[root@guowei /]# ls -a /
. bin dev etc lib media opt root sbin sys usr
.. boot dvd home lib64 mnt proc run srv tmp var
[root@guowei /]# ls -dl /home/
drwxr-xr-x. 4 root root 32 4月 19 09:44 /home/
...
[root@guowei /]# ls -R /home/
/home/:
guowei lisi
/home/guowei:
公共 模板 视频 图片 文档 下载 音乐 桌面
/home/guowei/公共:
...
cat 查看文本文件内容
cat -n [目标文件夹位置] 显示
cat --help 查看命令常见帮助信息行数
[root@guowei ~]# cat -n love.sh
1 #!/bin/bash
2 #------------------------------------------echo
3
[root@guowei ~]# cat /etc/redhat-release #查看系统版本
Red Hat Enterprise Linux Server release 7.4 (Maipo)
[root@guowei ~]# cat /proc/meminfo #检查内存大小,空闲情况
MemTotal: 1867024 kB
MemFree: 353716 kB
mkdir 创建目录 格式: mkdir [-p](创建多层级目录) [/路径/]目录
[root@guowei ~]# mkdir test/a/b
mkdir: 无法创建目录"test/a/b": 没有那个文件或目录
[root@guowei ~]# mkdir -p test/a/b
[root@guowei ~]# ls -R test/
test/:
a
test/a:
b
test/a/b:
touch [路径名]文件名 创建文件
[root@guowei ~]# touch test/a/b/1.txt
[root@guowei ~]# ls test/a/b/
1.txt
重定向 >覆盖重定向 , >> 追加重定向
[root@guowei ~]# echo 123 > test/a/b/1.txt
[root@guowei ~]# cat test/a/b/1.txt
123
[root@guowei ~]# echo 234 >> test/a/b/1.txt
[root@guowei ~]# cat test/a/b/1.txt
123
234
[root@guowei ~]# echo 345 > test/a/b/1.txt
[root@guowei ~]# cat test/a/b/1.txt
345
head,tail 命令 输出前后指定行数
head/tail -n 数字 文件名
[root@guowei ~]# cat test/a/b/1.txt
hello
Nice to meet you !
Long time no see!
In my opinion,you are a smart girl!
I have a dream!
[root@guowei ~]# head -3 test/a/b/1.txt
hello
Nice to meet you !
Long time no see!
管道符 | 将前面命令输出的结果,作为后面命令的参数,由后面命令再处理一次
[root@guowei ~]# cat test/a/b/1.txt | tail -2
In my opinion,you are a smart girl!
I have a dream!
more,less 对文件或者其他输出分屏显示的工具
more [选项] 文件名
[root@guowei ~]# more +2 test/a/b/1.txt # 从第二行开始显示
Nice to meet you !
Long time no see!
In my opinion,you are a smart girl!
I have a dream!
[root@guowei ~]# more -2 test/a/b/1.txt #定义每屏显示两行
hello
Nice to meet you !
--More--(26%)
#按 enter 键进行翻页(默认为一行) , 空格键 向下显示一屏 , = 输出当前的行号
:f 输出文件名和当前的行号 , v 调用vi编辑器 , q 退出
[root@guowei ~]# more +/opinion test/a/b/1.txt
#每个档案显示前搜寻该字串(pattern)这里为opinion,然后从该字串前两行之后开始显示
...跳过
Nice to meet you !
Long time no see!
In my opinion,you are a smart girl!
I have a dream!
less [参数] 文件 可以上搜也可以下搜
[root@guowei ~]# ps -ef | less -N # ps查看进程信息并用less分屏显示行号
1 UID PID PPID C STIME TTY TIME CMD
2 root 1 0 0 02:28 ? 00:00:06 /usr/lib/systemd/systemd --s 2 witched-root --system --deserialize 21
3 root 2 0 0 02:28 ? 00:00:00 [kthreadd]
4 root 3 2 0 02:28 ? 00:00:00 [ksoftirqd/0]
5 root 5 2 0 02:28 ? 00:00:00 [kworker/0:0H]
6 root 7 2 0 02:28 ? 00:00:00 [migration/0]
7 root 8 2 0 02:28 ? 00:00:00 [rcu_bh]
8 root 9 2 0 02:28 ? 00:00:03 [rcu_sched]
9 root 10 2 0 02:28 ? 00:00:00 [watchdog/0]
10 root 12 2 0 02:28 ? 00:00:00 [kdevtmpfs]
11 root 13 2 0 02:28 ? 00:00:00 [netns]
12 root 14 2 0 02:28 ? 00:00:00 [khungtaskd]
13 root 15 2 0 02:28 ? 00:00:00 [writeback]
14 root 16 2 0 02:28 ? 00:00:00 [kintegrityd]
:
# pageup 向上翻页,pagedown 向下翻页,b 向前翻页 ,d 向后翻页,空格键 显示下一页 enter键显示下一行,q 退出命令
[root@guowei ~]# less test/a/b/1.txt test/a/b/2.txt #可以多个文件同时打开
hello
Nice to meet you !
Long time no see!
In my opinion,you are a smart girl!
I have a dream!
...
~
~
(END) - Next: test/a/b/2.txt
# :n 显示文件2.txt :p 显示文件1.txt