|
基础命令
Linux系统的命令通常都是如下所示的格式:
-
命令名称 [命名参数] [命令对象]
获取登录信息
获取登录信息 - 「w」 / 「who」 / 「last」/ 「lastb」。
-
maoli@ubuntu:~$ w
-
08:07:38 up 2 min, 1 user, load average: 0.83, 0.64, 0.27
-
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
-
maoli tty7 :0 08:06 2:38 2.29s 0.31s /sbin/upstart -
-
maoli@ubuntu:~$ who
-
maoli tty7 2020-05-28 08:06 (:0)
-
maoli@ubuntu:~$ last
-
maoli tty7 :0 Thu May 28 08:06 gone - no logout
-
reboot system boot 4.15.0-99-generi Thu May 28 08:04 still running
-
maoli tty7 :0 Fri May 1 15:20 - down (01:26)
-
reboot system boot 4.15.0-99-generi Fri May 1 15:20 - 16:47 (01:26)
-
maoli tty7 :0 Fri May 1 10:12 - crash (05:08)
-
wtmp begins Fri May 1 10:12:22 2020
-
maoli@ubuntu:~$ sudo lastb
-
[sudo] maoli 的密码:
-
-
btmp begins Fri May 1 15:20:29 2020
查看自己使用的Shell
查看自己使用的Shell - 「ps」。
Shell也被称为“壳”或“壳程序”,它是用户与操作系统内核交流的翻译官,简单的说就是人与计算机交互的界面和接口。目前很多Linux系统默认的Shell都是bash(Bourne Again SHell),因为它可以使用tab键进行命令和路径补全、可以保存历史命令、可以方便的配置环境变量以及执行批处理操作。
-
maoli@ubuntu:~$ ps
-
PID TTY TIME CMD
-
3621 pts/1 00:00:00 bash
-
5082 pts/1 00:00:00 ps
查看命令的说明和位置
查看命令的说明和位置 - 「whatis」 / 「which」 / 「whereis」。
-
maoli@ubuntu:~$ whatis ps
-
ps (1) - report a snapshot of the current processes.
-
maoli@ubuntu:~$ whatis python
-
python (1) - an interpreted, interactive, object-oriented programmi...
-
maoli@ubuntu:~$ whereis ps
-
ps: /bin/ps /usr/share/man/man1/ps.1.gz
-
maoli@ubuntu:~$ whereis python
-
python: /usr/bin/python3.5m-config /usr/bin/python /usr/bin/python3.5 /usr/bin/python3.5m /usr/bin/python2.7 /usr/bin/python3.5-config /usr/lib/python3.5 /usr/lib/python2.7 /etc/python /etc/python3.5 /etc/python2.7 /usr/local/lib/python3.5 /usr/local/lib/python2.7 /usr/include/python3.5 /usr/include/python3.5m /usr/share/python /usr/share/man/man1/python.1.gz
-
maoli@ubuntu:~$ which ps
-
/bin/ps
-
maoli@ubuntu:~$ which python
-
/usr/bin/python
清除屏幕上显示的内容
清除屏幕上显示的内容 - 「clear」。
查看帮助文档查看帮助文档 - 「man」 / 「info」 / 「help」 / 「apropos」。
-
maoli@ubuntu:~$ ps
-
-
Usage:
-
ps [options]
-
-
Try 'ps --help <simple|list|output|threads|misc|all>'
-
or 'ps --help <s|l|o|t|m|a>'
-
for additional help text.
-
-
For more details see ps(1).
-
maoli@ubuntu:~$ man ps
-
-
PS(1) User Commands PS(1)
-
NAME
-
ps - report a snapshot of the current processes.
-
SYNOPSIS
-
ps [options]
-
DESCRIPTION
-
...
查看系统和主机名
查看系统和主机名 - 「uname」 / 「hostname」。
-
maoli@ubuntu:~$ uname
-
Linux
-
maoli@ubuntu:~$ hostname
-
ubuntu
时间和日期
时间和日期 - 「date」 / 「cal」。
-
maoli@ubuntu:~$ date
-
2020年 05月 28日 星期四 08:13:25 CST
-
maoli@ubuntu:~$ cal
-
五月 2020
-
日 一 二 三 四 五 六
-
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
-
31
-
maoli@ubuntu:~$ cal 5 2020
-
五月 2020
-
日 一 二 三 四 五 六
-
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
-
31
重启和关机
重启和关机 - 「reboot」 / 「shutdown」。
-
maoli@ubuntu:~$ shutdown -h +5 #五分钟关机
-
Shutdown scheduled for 四 2020-05-28 08:19:24 CST, use 'shutdown -c' to cancel. [root ~]#
-
maoli@ubuntu:~$ shutdown -c
-
maoli@ubuntu:~$ shutdown -r 12:00
-
Shutdown scheduled for 四 2020-05-28 12:00:00 CST, use 'shutdown -c' to cancel
-
maoli@ubuntu:~$ shutdown -c
说明:在执行shutdown命令时会向登录系统的用户发出警告,可以在命令后面跟上警告消息来替换默认的警告消息,也可以在-h参数后通过now来表示立刻关机。
退出登录
退出登录 - 「exit」 / 「logout」。
查看历史命令
查看历史命令 - 「history」。
-
maoli@ubuntu:~$ history
-
...
-
625 date
-
626 cal
-
627 cal 5 2020
-
628 shutdown -c
-
629 shutdown -r 12:00
-
630 shutdown -c
-
631 history
-
-
maoli@ubuntu:~$ !631
说明:查看到历史命令之后,可以用!历史命令编号来重新执行该命令;通过history -c可以清除历史命令。
实用程序
文件和文件夹操作
创建/删除空目录
创建/删除空目录 - 「mkdir」 / 「rmdir」。
-
[root ~]# mkdir runsen
-
[root ~]# mkdir -p abc/runsen
-
[root ~]# rmdir runsen
创建/删除文件
创建/删除文件 - 「touch」 / 「rm」。
-
maoli@ubuntu:~$ touch readme.txt
-
maoli@ubuntu:~$ rm readme.txt
-
rm: remove regular empty file ‘readme.txt ’? y
-
[root ~]# rm -rf ;xyz&amp;nbsp;
touch命令用于创建空白文件或修改文件时间。在Linux系统中一个文件有三种时间:
-
更改内容的时间 - mtime。
-
更改权限的时间 - ctime。
-
最后访问时间 - atime。
rm的几个重要参数:
-
-i:交互式删除,每个删除项都会进行询问。
-
-r:删除目录并递归的删除目录中的文件和目录。
-
-f:强制删除,忽略不存在的文件,没有任何提示。
切换和查看当前工作目录
切换和查看当前工作目录 - 「cd」 / 「pwd」。
说明:cd命令后面可以跟相对路径(以当前路径作为参照)或绝对路径(以/开头)来切换到指定的目录,也可以用cd ..来返回上一级目录。返回到上上一级目录应该给cd ../../命令。
查看目录内容
查看目录内容 - 「ls」。
-
-l:以长格式查看文件和目录。
-
-a:显示以点开头的文件和目录(隐藏文件)。
-
-R:遇到目录要进行递归展开(继续列出目录下面的文件和目录)。
-
-d:只列出目录,不列出其他内容。
-
-S / -t:按大小/时间排序。
-

(编辑:衡阳站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|