Linux 基础命令总结(1)
简单命令
- who
查看当前所有正在使用系统的用户。
选项有:
-m:功能同 who am i 命令,显示运行该程序的用户名。
-q:只显示用户的登录账号和登录用户的数量。
-i 或 -u:在登录时间后面显示该用户最后一次对系统进行操作至今的时间,也就是常说的”发呆”时间。
-H:会显示一行列标题。
[root@localhost ~]# who am i
root pts/1 2018-01-19 14:50 (192.168.1.18)
[root@localhost ~]# who -m
root pts/1 2018-01-19 14:50 (192.168.1.18)
[root@localhost ~]# who -q
root root root
# 用户数=3
[root@localhost ~]# who -i
who:无效选项 -- i
Try 'who --help' for more information.
[root@localhost ~]# who -u
root :0 2018-01-19 10:19 ? 2879 (:0)
root pts/0 2018-01-19 10:20 01:53 3665 (192.168.1.18)
root pts/1 2018-01-19 14:50 . 6728 (192.168.1.18)
[root@localhost ~]# who -H
名称 线路 时间 备注
root :0 2018-01-19 10:19 (:0)
root pts/0 2018-01-19 10:20 (192.168.1.18)
root pts/1 2018-01-19 14:50 (192.168.1.18)
[root@localhost ~]#
- date
用来显示或设置系统的日期和时间
显示当前日期与时间
[root@localhost ~]# date
2018年 01月 19日 星期五 15:01:46 CST
设置当前时间为15点04分。
[root@localhost ~]# date -s 15:04
2018年 01月 19日 星期五 15:04:00 CST
设置当前时间为2011年3月2日,时间会自动变更为设置日期的0点0时0分。
[root@localhost ~]# date -s 20110302
- cal
可以用来显示1~9999年中任意年份或任意月份的日历
显示当前月份的日历
[root@localhost ~]# cal
一月 2018
日 一 二 三 四 五 六
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
[root@localhost ~]#
显示2009年日历的命令如下:
[root@localhost ~]# cal 2009
显示2017年 3月份 日历的命令如下:
[root@localhost ~]# cal 3 2017
- echo
将命令行中输入的字符串输出到标准输出(一般为显示器)上
常用的选项:
-n:不要在输出后自动换行
[root@localhost ~]# echo How do you do
How do you do
- su
能够让用户在一个登录的shell中不退出即可改变成另一个用户。
如果不使用任何参数,则su 命令缺省要求输入超级用户的密码,使成为超级用户。(只有超级用户登录执行的时候不用输入密码,其他操作都需要输入超级用户的密码)
[root@localhost ~]# su rl
[rl@localhost root]$
- passwd
用来改变用户口令
注意输入的密码是不会回显在屏幕上的。超级用户还可以使用”passwd 用户名”来更改其他用户的口令。
- clear
清屏命令
- man
用来查看命令的帮助文档
[root@localhost test]# man who
特殊符号
- & 后台命令
命令后面加&,就可以使该命令在后台进行工作,不会受到终端用户键盘的干扰。用户也可以继续输入命令进行其他的工作。经常将一些运行时间长的命令或程序放在后台执行。
[root@localhost ~]# find / -name group&
- >< 重定向
“>”是输出重定向,”<”是输入重定向。”>>”表示追加到指定文件的末尾。
将who命令的输出结果保存到指定文件中,而不是显示在屏幕上
[root@localhost test]# who > whoout
[root@localhost test]# cat whoout
root :0 2018-01-19 10:19 (:0)
root pts/0 2018-01-19 10:20 (192.168.1.18)
root pts/1 2018-01-19 14:50 (192.168.1.18)
[root@localhost test]#
创建文本文件
[root@localhost test]# cat > c.txt
[root@localhost test]# ls
a.log readtest sysinfo testcase testfunc testif testset testsig
c.txt
[root@localhost test]#
- | 管道
管道线,能够将一个命令的输出用做另一个命令的输入
将who命令的输出作为 wc -l 命令的输入。
[root@localhost test]# who | wc -l
3
[root@localhost test]#
- *?匹配
通配符,用于模式匹配,如文件名匹配、字符串查找等。“*”用于匹配任意字符的0次或多次出现。
[root@localhost test]# find /usr/test/ -name *.c
[root@localhost test]# find /usr/test -name f?.c
关机过程
- shutdown
是只有超级用户才能使用的一个关机命令。可以用来关机,也可以用来重新启动等。
语法形式:
shutdown [-krhfnc] [-t secs] time [warning message]
选项参数:
-k:并不真正关机,只是发出警告信息给所有用户
-r:关机后立即重新启动
-h:关机后不重新启动
-f:快速关机,重新启动时不执行fsck(fsck时Linux下的一个检查和修复文件系统的程序)。
-n:快速关机,不经过init程序。
-c:取消一个已经运行的shutdown。
-t secs:设定在几秒之后执行关机程序
time:设定关机的时间
message:传送给所有使用者的警告信息
立即关机
命令:
[root@localhost test]# shutdown -h now
- 使用 init 关闭
用来改变系统当前正在运行的功能级别。共有6个级别,其中包括关机和重启系统。
语法形式:
init n
重新启动系统:
[root@localhost test]# init 6
关闭系统:
[root@localhost test]# init 0
缺省的运行级别:
#0 停机模式(千万不要把initdefault设置为0)
#1 单用户模式,类似于windows下的保护模式
#2 多用户,没有NFS支持
#3 完全多用户模式(标准的运行级)
#4 一般用不到
#5 X11(X Windows,一般缺省为该模式)
#6 重新启动(千万不要把initdefault设置为6)
Red Hat Linux 中的启动配置文件/etc/inittab 中有一行:
id:5:initdefault:
可以在这里通过更改其中的数字来改变缺省启动运行级别。
转载请标明出处:http://blog.youkuaiyun.com/renli2549/article/details/79108028