1. Linux中严格的区分大写和小写,tab键可以把命令补齐,上下键可以查看历史使用命令,并且还可以执行。“;”可以分隔命令,“\”可以断开命令。
2. pwd 查看当前目录
[root@localhost ~]# pwd
/root
3. (1) cd 切换到当前用户的家目录下
[root@localhost /]# cd
[root@localhost ~]#
(2)cd 目录 例如:cd /etc
[root@localhost ~]# cd /etc
[root@localhost etc]#
(3)cd - 切换到上次所在的目录中
[root@localhost ~]# cd /
[root@localhost /]# cd -
/root
[root@localhost ~]#
(4)cd .. 切换到上级目录
[root@localhost ~]# cd ..
[root@localhost /]#
(5)cd ~ 切换到当前用户的家目录下
[root@localhost /]# cd ~
[root@localhost ~]#
(6)cd ../.. 切换到上两级目录
[root@localhost /]# cd /etc
[root@localhost etc]# cd lvm
[root@localhost lvm]# cd cache
[root@localhost cache]# cd ../..
[root@localhost etc]#
4.(1)ls 列出当前目录下的文件或目录信息
比如说:查看“/”目录下的目录信息
[root@localhost ~]# ls /
bin dev home lib64 mnt proc run srv tmp var
boot etc lib media opt root sbin sys usr
(2)ls -l 显示文件或者目录的详细信息 “ls -l”=“ll”
[root@localhost ~]# ls -l
总用量 2084
-rw-------. 1 root root 1659 3月 4 23:48 anaconda-ks.cfg
-rw-r--r--. 1 root root 1707 3月 4 23:49 initial-setup-ks.cfg
-rw-r--r--. 1 root root 2124092 1月 31 2017 nginx-debuginfo-1.10.3-1.el7.ngx.x86_64.rpm
[root@localhost ~]#
“ll“
[root@localhost ~]# ll
总用量 2084
-rw-------. 1 root root 1659 3月 4 23:48 anaconda-ks.cfg
-rw-r--r--. 1 root root 1707 3月 4 23:49 initial-setup-ks.cfg
-rw-r--r--. 1 root root 2124092 1月 31 2017 nginx-debuginfo-1.10.3-1.el7.ngx.x86_64.rpm
[root@localhost ~]#
(3)“ls -a” 显示所有文件,包括以“.”开头的隐藏文件
[root@localhost ~]# ls -a
. .bash_profile .dbus .xauthAbALxg
.. .bashrc initial-setup-ks.cfg .xauthevNW3Y
anaconda-ks.cfg .cache nginx-debuginfo-1.10.3-1.el7.ngx.x86_64.rpm .Xauthority
.bash_history .config .tcshrc
.bash_logout .cshrc .viminfo
[root@localhost ~]#
(4)“ls -ld” 如果参数是目录,以得到目录的详细信息
[root@localhost ~]# ls -a
. .bash_profile .dbus .xauthAbALxg
.. .bashrc initial-setup-ks.cfg .xauthevNW3Y
anaconda-ks.cfg .cache nginx-debuginfo-1.10.3-1.el7.ngx.x86_64.rpm .Xauthority
.bash_history .config .tcshrc
.bash_logout .cshrc .viminfo
[root@localhost ~]# ls -ld
dr-xr-x---. 5 root root 4096 3月 22 15:53 .
[root@localhost ~]#
5.
(1)相对路径:从根开始的路径
例如:cd /etc/sysconfig/network-scripts/
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]#
(2)相对路径:从当前目录开始的路径
例如:cd/etc/sysconfig/network-scripts/
[root@localhost /]# cd etc/sysconfig/network-scripts/
[root@localhost network-scripts]#
6.
(1)cat 查看文件内容
[root@localhost ~]# cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
[root@localhost ~]#
cat -n 显示文件的行号
[root@localhost ~]# cat -n /etc/passwd
1 root:x:0:0:root:/root:/bin/bash
2 bin:x:1:1:bin:/bin:/sbin/nologin
3 daemon:x:2:2:daemon:/sbin:/sbin/nologin
4 adm:x:3:4:adm:/var/adm:/sbin/nologin
5 lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
6 sync:x:5:0:sync:/sbin:/bin/sync
[root@localhost ~]#
(2)more 分屏显示文件内容 “more 文件名”
[root@localhost ~]# more /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
[root@localhost ~]#
进入文件内容后:“enter键往下翻一行” “空格键往下翻一页” “q退出正在查看的文件内容”
moer -n 往下翻页的时候,每次翻几行
more +n 打开文件时从第几行开始显示文件内容
(3)less 分屏显示文件内容 “less 文件名”
“enter键往下翻一行” “空格键往下翻一页” “b 往上翻一页” “ / 搜索”
(4)head 查看文件前十行内容 “head 文件名”
[root@localhost ~]# head /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
[root@localhost ~]#
head -n 显示文件前几行
(5)tail 查看文件后十行内容
[root@localhost ~]# tail /etc/passwd
setroubleshoot:x:993:990::/var/lib/setroubleshoot:/sbin/nologin
pulse:x:171:171:PulseAudio System Daemon:/var/run/pulse:/sbin/nologin
gdm:x:42:42::/var/lib/gdm:/sbin/nologin
gnome-initial-setup:x:992:987::/run/gnome-initial-setup/:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
ntp:x:38:38::/etc/ntp:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
user:x:1000:1000:user:/home/user:/bin/bash
[root@localhost ~]#
tail -n 显示文件后几行
(6)cp 复制
cp 源文件 目标文件
例如:把etc/passwd复制到tmp下
[root@localhost ~]# cp /etc/passwd /tmp/passwd
[root@localhost ~]# ls /tmp
passwd
ssh-9Rl4jcg9CGZ8
[root@localhost ~]#
cp -r 复制目录
例如:把tmp下的passwd复制到etc下,并改名为2
[root@localhost ~]# cp -r /tmp/passwd /etc/2
[root@localhost ~]# ls /etc
2 hosts protocols
[root@localhost ~]#
cp -a 带权限的复制
例如:
(7)管道符 “|” 把前面命令的结果传递给后面的命令
例如:head -6 2 | tail -1 只显示2文件的第六行
[root@localhost ~]#cd /etc
[root@localhost etc]# head -5 2 |tail -1
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
[root@localhost etc]#
(8)wc -l 文件名 统计文件的行数
例如:统计etc下的passwd文件的行数
[root@localhost ~]# wc -l /etc/passwd
40 /etc/passwd
[root@localhost ~]#
(9)touch 文件名 创建文件
例如:在家目录下创建一个名为xuan的文件
[root@localhost ~]# touch xuan
[root@localhost ~]# ls
xuan
[root@localhost ~]#
(10)mkdir 创建目录
例如:在“/”下创建一个名为xuan123的文件
[root@localhost ~]# cd /
[root@localhost /]# mkdir xuan123
[root@localhost /]# ls
bin dev home lib64 mnt proc run srv tmp var
boot etc lib media opt root sbin sys usr xuan123
[root@localhost /]#
(11)vim 字处理器,编辑器
末行模式 在编辑模式下按:进入
:q 正常退出
:q!强制退出 不保存退出
:wq 保存退出
:wq! 强制保存退出
: set nu 显示行号
: set nonu 取消行号
插入模式
I 在光标之前插入
a在光标之后插入
O 在当前光标之上另起一行插入
o 在当前光标之下另起一行插入
在插入模式下按ESC键返回编辑模式
编辑模式 打开vim编辑器就是编辑模式
gg 跳到文本开头
G 跳到文本末尾
M 跳到屏幕中键
yy 复制 前面可以加数字
dd 删除 前面可以加数组
p 在光标下一行粘贴
P 在光标上一行粘贴
u 撤销
7.
rm删除文件
[root@localhost ~]# rm /qwe/dfg
rm:是否删除普通空文件 "/qwe/dfg"?y
[root@localhost ~]# ls /qwe
yui zxc
[root@localhost ~]#
rm -rf 删除目录
[root@localhost ~]# rm -rf qwe
[root@localhost ~]# ls
anaconda-ks.cfg initial-setup-ks.cfg nginx-debuginfo-1.10.3-1.el7.ngx.x86_64.rpm xuan
[root@localhost ~]#
rm -r 递归删除文件
[root@localhost ~]# cd poi
[root@localhost poi]# touch 1
[root@localhost poi]# touch 2
[root@localhost poi]# touch 3
[root@localhost poi]# cd
[root@localhost ~]# rm -r poi
rm:是否进入目录"poi"? y
rm:是否删除普通空文件 "poi/1"?y
rm:是否删除普通空文件 "poi/2"?y
rm:是否删除普通空文件 "poi/3"?y
rm:是否删除目录 "poi"?y
[root@localhost ~]#
rm -f 强制删除文件
[root@localhost ~]# cd q1
[root@localhost q1]# touch 1w
[root@localhost ~]# cd q1
[root@localhost q1]# rm -f 1w
[root@localhost q1]# ls
re w
[root@localhost q1]#
8.
clear 清屏
ctrl +l 清屏
9.
uname 查看系统信息
例如:查看“/”系统信息
[root@localhost /]# uname
Linux
[root@localhost /]#
uname -a 查看系统详细信息
例如:查看“/”的系统详细信息
[root@localhost /]# uname -a
Linux localhost.localdomain 3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
[root@localhost /]#
uname -r查看内核版本
例如:查看“/”的内核版本
[root@localhost /]# uname -r
3.10.0-693.el7.x86_64
[root@localhost /]#
10.
shutdown 关机
shutdown [参数] 时间 [警示信息]
shutdown -r 重启
shutdown -h 关机
shutdown -h now 立即关机 等价于 poweroff
shutdown -h hh:mm 指定时间关机
shutdown -h +m 在多少分钟之后关机
shutdown -r now 立即重启 等价于 reboot