Linux 快捷键记录栏

1 图形模式与文字模式的切换方式

Linux预设提供了六个命令窗口终端机让我们来登录。 六个窗口分别为tty1,tty2 … tty6,可以按下Ctrl + Alt + F1 ~ F6 来切换,默认登录的时第一个窗口tty1。如果安装了图形界面,默认时进入图形界面,可以按Ctrl + Alt + F1 ~ F6进入其中一个命令窗口界面,按 Ctrl + Alt + F7返回图形界面。 如果用的vmware 虚拟机,命令窗口切换的快捷键为 Alt + Space + F1~F6. 如果在图形界面下按Alt + Shift + Ctrl + F1~F6 切换至命令窗口。

Ctrl + Alt + F1  命令窗口tty1
Ctrl + Alt + F2  命令窗口tty2
Ctrl + Alt + F3  命令窗口tty3
Ctrl + Alt + F4  命令窗口tty4
Ctrl + Alt + F5  命令窗口tty5
Ctrl + Alt + F6  命令窗口tty6
Ctrl + Alt + F7  返回图形界面

2 关机

正确的关机流程为:sync > shutdown > reboot > halt
关机指令为:shutdown
不管是重启系统还是关闭系统,首先要运行 sync 命令,把内存中的数据写到磁盘中。
关机的命令有 shutdown –h now halt poweroffinit 0, 重启系统的命令有 shutdown –r now reboot init 6

sync 将数据由内存同步到硬盘中
shutdown –h 10 ‘This server will shutdown after 10 mins’ 计算机将在10分钟后关机,并且会显示在登陆用户的当前屏幕中。
shutdown –h now 立马关机
shutdown –h 20:25 系统会在今天20:25关机
shutdown –h +10 十分钟后关机
shutdown –r now 系统立马重启
shutdown –r +10 系统十分钟后重启
shutdown -c 取消预定设置
reboot 重启,等同于 shutdown –r now
halt 关闭系统,等同于shutdown –h now 和 poweroff

3 处理目录的常用命令

3.1 ls 列出目录 命令格式:ls [目录名]

选项和参数

-a :全部的文件,连同隐藏档( 开头为 . 的文件) 一起列出来
-d :仅列出目录本身,而不是列出目录内的文件数据
-l :长数据串列出,包含文件的属性与权限等等数据
root@slave1:/home/xxx# ls -a /root
.   .bash_history  .cache   .gconf  .oracle_jre_usage  .ssh
..  .bashrc        .config  .gnupg  .profile           .wget-hsts
root@slave1:/home/xxx# ls -d /root
/root

3.2 cd 切换目录 命令格式:cd [相对路径或绝对路径]

root@slave1:~# cd /home/xxx/Downloads     使用绝对路径切换到/home目录
root@slave1:/# cd ./home                  使用相对路径切换到/home目录
root@slave1:/home# cd ~                   回到/root目录 注:cd后面有一空格
root@slave1:~#
root@slave1:/home/xxx# cd ..              回到目前的上一级目录
root@slave1:/home#

3.3 pwd 显示目前所在的目录

pwd 是 Print Working Directory(打印工作目录) 的缩写,也就是显示目前所在目录的命令。

root@slave1:/home# pwd
/home
root@slave1:/home# pwd -P               -P :显示出确实的路径,而非使用连结 (link) 路径。
/home

3.4 mkdir (创建新目录) 命令格式:mkdir [-mp] 目录名称

选项与参数:
-m :配置文件的权限,直接配置
-p :将所需要的目录(包含上一级目录)递归创建起来

root@slave1:/home/xxx/Documents# mkdir test
root@slave1:/home/xxx/Documents# mkdir test1/test2/test3
mkdir: cannot create directory ‘test1/test2/test3’: No such file or directory      没办法直接创建此目录
root@slave1:/home/xxx/Documents# mkdir -p test1/test2/test3                        加-p 的选项,可以自行创建多层目录
root@slave1:/home/xxx/Documents/test1/test2/test3#
root@slave1:/home/xxx/Documents# mkdir -m 711 test2                                创建权限为 rwx--x--x 的目录
root@slave1:/home/xxx/Documents# ls -l
drwxr-xr-x 2 root root 4096 9月  17 03:14 test
drwxr-xr-x 3 root root 4096 9月  17 03:15 test1
drwx--x--x 2 root root 4096 9月  17 03:20 test2

3.5 rmdir (删除空的目录) 命令格式:rmdir [-p] 目录名称

选项与参数:
-p :连同上一级『空的』目录也一起删除

root@slave1:/home/xxx/Documents# rmdir test                 空目录可以直接删除 注意: rmdir仅能删除空的目录,可以使用rm命令来删除非空目录
root@slave1:/home/xxx/Documents# rmdir test1                不是空目录不能直接删除
rmdir: failed to remove 'test1': Directory not empty
root@slave1:/home/xxx/Documents# rmdir -p test1/test2/test3 用-p 这个选项,立刻就可以将 test1/test2/test3 一次删除
root@slave1:/home/xxx/Documents# ls -l
drwx--x--x 2 root root 4096 9月  17 03:20 test2

3.6 rm (移除文件或目录) 命令格式:rm [-fir] 文件或目录

选项与参数:
-f :就是 force 的意思,忽略不存在的文件,不会出现警告信息;
-i :互动模式,在删除前会询问使用者是否动作
-r :递归删除
删除cp 实例中创建的bashrc

root@slave1:~# cd /tmp
root@slave1:/tmp# rm -i bashrc
rm: remove regular file 'bashrc'? y

3.7 cp (复制文件或目录)

选项与参数:

-a:相当于 -pdr 的意思,至于 pdr 请参考下列说明;(常用)

-d:若来源档为连结档的属性(link file),则复制连结档属性而非文件本身;

-f:为强制(force)的意思,若目标文件已经存在且无法开启,则移除后再尝试一次;

-i:若目标档(destination)已经存在时,在覆盖时会先询问动作的进行(常用)

-l:进行硬式连结(hard link)的连结档创建,而非复制文件本身;

-p:连同文件的属性一起复制过去,而非使用默认属性(备份常用);

-r:递归持续复制,用於目录的复制行为;(常用)

-s:复制成为符号连结档 (symbolic link),亦即『捷径』文件;

-u:若 destination 比 source 旧才升级 destination !

root@slave1:~# cp ~/.bashrc /tmp/bashrc
root@slave1:~# cp -i ~/.bashrc /tmp/bashrc
cp: overwrite '/tmp/bashrc'? n     <==n不覆盖,y为覆盖

3.8 mv (移动文件与目录,或修改名称)

命令格式:

mv [-fiu] source destination
mv [options] source1 source2 source3 .... directory

选项与参数:
-f:force 强制的意思,如果目标文件已经存在,不会询问而直接覆盖;
-i:若目标文件 (destination) 已经存在时,就会询问是否覆盖!
-u:若目标文件已经存在,且 source 比较新,才会升级 (update)
复制一文件,创建一目录,将文件移动到目录中

root@slave1:/tmp# cp ~/.bashrc bashrc
root@slave1:/tmp# mkdir mvtest
root@slave1:/tmp# mv bashrc mvtest    将bashrc文件移动到mvtest目录
root@slave1:/tmp# mv mvtest mvtest2   将目录名mvtest改为mvtest2

4 文件内容查看

4.1 cat 由第一行开始显示文件内容 命令格式:cat [-AbEnTv]

选项与参数:
-A :相当於 -vET 的整合选项,可列出一些特殊字符而不是空白而已;
-b :列出行号,仅针对非空白行做行号显示,空白行不标行号!
-E :将结尾的断行字节 $ 显示出来;
-n :列印出行号,连同空白行也会有行号,与 -b 的选项不同;
-T :将 [tab] 按键以 ^I 显示出来;
-v :列出一些看不出来的特殊字符
检看/etc/X11/Xwrapper.config这个文件的内容:

root@slave1:/etc/X11# cat /etc/X11/Xwrapper.config
# Xwrapper.config (Debian X Window System server wrapper configuration file)
#
# This file was generated by the post-installation script of the
# xserver-xorg-legacy package using values from the debconf database.
#
# See the Xwrapper.config(5) manual page for more information.
#
# This file is automatically updated on upgrades of the xserver-xorg-legacy
# package *only* if it has not been modified since the last upgrade of that
# package.
#
# If you have edited this file but would like it to be automatically updated
# again, run the following command as root:
#   dpkg-reconfigure xserver-xorg-legacy
allowed_users=console

4.2 tac

taccat命令相反,文件内容从最后一行开始显示


root@slave1:/etc/X11# tac /etc/X11/Xwrapper.config
allowed_users=console
#   dpkg-reconfigure xserver-xorg-legacy
# again, run the following command as root:
# If you have edited this file but would like it to be automatically updated
#
# package.
# package *only* if it has not been modified since the last upgrade of that
# This file is automatically updated on upgrades of the xserver-xorg-legacy
#
# See the Xwrapper.config(5) manual page for more information.
#
# xserver-xorg-legacy package using values from the debconf database.
# This file was generated by the post-installation script of the
#
# Xwrapper.config (Debian X Window System server wrapper configuration file)

4.3 nl 显示行号 命令格式:nl [-bnw] 文件

选项与参数:

-b :指定行号指定的方式,主要有两种:
-b a :表示不论是否为空行,也同样列出行号(类似 cat -n);
-b t :如果有空行,空的那一行不要列出行号(默认值);

-n :列出行号表示的方法,主要有三种:
-n ln :行号在荧幕的最左方显示;
-n rn :行号在自己栏位的最右方显示,且不加 0 ;
-n rz :行号在自己栏位的最右方显示,且加 0 ;
-w :行号栏位的占用的位数。


root@slave1:~# nl /etc/X11/Xwrapper.config
     1    # Xwrapper.config (Debian X Window System server wrapper configuration file)
     2    #
     3    # This file was generated by the post-installation script of the
     4    # xserver-xorg-legacy package using values from the debconf database.
     5    #
     6    # See the Xwrapper.config(5) manual page for more information.
     7    #
     8    # This file is automatically updated on upgrades of the xserver-xorg-legacy
     9    # package *only* if it has not been modified since the last upgrade of that
    10    # package.
    11    #
    12    # If you have edited this file but would like it to be automatically updated
    13    # again, run the following command as root:
    14    #   dpkg-reconfigure xserver-xorg-legacy
    15    allowed_users=console

4.4 more 一页一页翻动

more运行时可以输入的命令有:
空白键 (space):代表向下翻一页;
Enter         :代表向下翻『一行』;
/字串         :代表在这个显示的内容当中,向下搜寻『字串』这个关键字;
:f            :立刻显示出档名以及目前显示的行数;
q             :代表立刻离开 more ,不再显示该文件内容。
b 或 [ctrl]-b :代表往回翻页,不过这动作只对文件有用,对管线无用。

root@slave1:~# more /etc/X11/rgb.txt
! $Xorg: rgb.txt,v 1.3 2000/08/17 19:54:00 cpqbld Exp $
255 250 250        snow
248 248 255        ghost white
248 248 255        GhostWhite
245 245 245        white smoke
245 245 245        WhiteSmoke
220 220 220        gainsboro
255 250 240        floral white
255 250 240        FloralWhite
253 245 230        old lace
253 245 230        OldLace
250 240 230        linen
250 235 215        antique white
250 235 215        AntiqueWhite
255 239 213        papaya whip
255 239 213        PapayaWhip
255 235 205        blanched almond
255 235 205        BlanchedAlmond
255 228 196        bisque
255 218 185        peach puff
255 218 185        PeachPuff
255 222 173        navajo white
255 222 173        NavajoWhite
--More--(3%)                        重点在这一行!光标也会在这里等待输入命令

4.5 less 一页一页翻动

less运行时可以输入的命令有:
空白键    :向下翻动一页;
[pagedown]:向下翻动一页;
[pageup]  :向上翻动一页;
/字串     :向下搜寻『字串』的功能;
?字串     :向上搜寻『字串』的功能;
n         :重复前一个搜寻 (与 / 或 ? 有关!)
N         :反向的重复前一个搜寻 (与 / 或 ? 有关!)
q         :离开 less 这个程序;

以下实例输出/etc/X11/rgb.txt文件的内容:

root@slave1:~# less /etc/X11/rgb.txt
! $Xorg: rgb.txt,v 1.3 2000/08/17 19:54:00 cpqbld Exp $
255 250 250        snow
248 248 255        ghost white
....(中间省略)....
255 250 205             LemonChiffon
255 245 238             seashell
:                                     等待输入命令

4.6 head 取出文件前面几行 命令格式:head [-n number] 文件

选项与参数:
-n :后面接数字,代表显示几行的意思, 默认的情况中,显示前面 10 行。

root@slave1:~# head /etc/X11/rgb.txt
! $Xorg: rgb.txt,v 1.3 2000/08/17 19:54:00 cpqbld Exp $
255 250 250        snow
248 248 255        ghost white
248 248 255        GhostWhite
245 245 245        white smoke
245 245 245        WhiteSmoke
220 220 220        gainsboro
255 250 240        floral white
255 250 240        FloralWhite
253 245 230        old lace

root@slave1:~# head -n 20 /etc/X11/rgb.txt                显示前20行
! $Xorg: rgb.txt,v 1.3 2000/08/17 19:54:00 cpqbld Exp $
255 250 250        snow
248 248 255        ghost white
248 248 255        GhostWhite
245 245 245        white smoke
245 245 245        WhiteSmoke
220 220 220        gainsboro
255 250 240        floral white
255 250 240        FloralWhite
253 245 230        old lace
253 245 230        OldLace
250 240 230        linen
250 235 215        antique white
250 235 215        AntiqueWhite
255 239 213        papaya whip
255 239 213        PapayaWhip
255 235 205        blanched almond
255 235 205        BlanchedAlmond
255 228 196        bisque
255 218 185        peach puff

4.7 tail 取出文件后面几行 命令格式:tail [-n number] 文件

选项与参数:
-n :后面接数字,代表显示几行的意思
-f :表示持续侦测后面所接的档名,要等到按下[ctrl]-c才会结束tail的侦测

root@slave1:~# tail /etc/X11/rgb.txt                默认显示后十行
0     0 139        dark blue
0     0 139        DarkBlue
0   139 139        dark cyan
0   139 139        DarkCyan
139   0 139        dark magenta
139   0 139        DarkMagenta
139   0   0        dark red
139   0   0        DarkRed
144 238 144        light green
144 238 144        LightGreen

root@slave1:~# tail -n 20 /etc/X11/rgb.txt          显示后二十行
250 250 250         gray98
250 250 250         grey98
252 252 252         gray99
252 252 252         grey99
255 255 255         gray100
255 255 255         grey100
169 169 169        dark grey
169 169 169        DarkGrey
169 169 169        dark gray
169 169 169        DarkGray
0     0 139        dark blue
0     0 139        DarkBlue
0   139 139        dark cyan
0   139 139        DarkCyan
139   0 139        dark magenta
139   0 139        DarkMagenta
139   0   0        dark red
139   0   0        DarkRed
144 238 144        light green
144 238 144        LightGreen
原文地址:https://www.cnblogs.com/eugene0/p/11537142.html