您的位置:首页 > 运维架构 > Linux

Basic Linux Commands :date, clock, hwclock, cal, ls, pwd, whereis, which, who, w, whoami

2015-09-04 11:48 766 查看
作业:自行学习如下命令
date, clock, hwclock, cal,ls, cd, pwd, tty, whereis, which,stat, echo, shutdown, halt, reboot, poweroff,who, w, whoami

date: 显示系统时间, 【时间日期】

date 查看系统当前时间 参数-u显示utc时间

格式化显示年月日 用+号连起来如:date +%Y-%m-%d(如果我们用date +%Y - %m - %d 会发现出错,因为系统看见空格后的- 会以为是一个参数。

这时候我们要用""连起来date +%Y" - "%m" - "%d )

常用参数注解
-d,--date
显示指定字符串所描述的时间,而非当前时间

-f,--file=日期文件
类似--date,从日期文件中按行读入时间描述
-r, --reference=文件
显示文件指定文件的最后修改时间

-s, --set=字符串
设置指定字符串来分开时间

-u, --utc, --universal
输出或者设置协调的通用时间

日期格式化字符串列表:
%H : 小时(00..23)
%I : 小时(01..12)
%k : 小时(0..23)
%l : 小时(1..12)
%M : 分钟(00..59)
%p : 显示本地 AM 或 PM
%r : 直接显示时间 (12 小时制,格式为 hh:mm:ss [AP]M)
%s : 从 1970 年 1 月 1 日 00:00:00 UTC 到目前为止的秒数
%S : 秒(00..61)
%T : 直接显示时间 (24 小时制)
%X : 相当于 %H:%M:%S
%Z : 显示时区 %a : 星期几 (Sun..Sat)
%A : 星期几 (Sunday..Saturday)
%b : 月份 (Jan..Dec)
%B : 月份 (January..December)
%c : 直接显示日期与时间
%d : 日 (01..31)
%D : 直接显示日期 (mm/dd/yy)
%h : 同 %b
%j : 一年中的第几天 (001..366)
%m : 月份 (01..12)
%U : 一年中的第几周 (00..53) (以 Sunday 为一周的第一天的情形)
%w : 一周中的第几天 (0..6)
%W : 一年中的第几周 (00..53) (以 Monday 为一周的第一天的情形)
%x : 直接显示日期 (mm/dd/yy)
%y : 年份的最后两位数字 (00.99)
%Y : 完整年份 (0000..9999)

如果我们想使用跟多格式化时间可以用date --help来看到更多的参数显示日期,不需要root权限

简单实例:

Just type the date command:$ date
Sample outputs:
Wed Apr 23 10:32:59 CDT 2014 Linux Display The Hardware Clock (RTC)

格式化输出:

date +"%Y-%m-%d"
2015-08-21

输出昨天日期:
date -d "1 day ago" +"%Y-%m-%d"
2015-08-20

2秒后输出: date -d "2 second" +"%Y-%m-%d %H:%M.%S"
2015-08-21 10:05.49

传说中的 1234567890 秒:
date -d "1980-01-01 1234567890 seconds" +"%Y-%m-%d %H:%m:%S"
2019-02-13 23:02:30

普通转格式:

date -d "2015-08-08" +"%Y/%m/%d %H:%M.%S"
2015/08/08 00:00.00

加减操作:
date +%Y%m%d //显示当前年月日
20150821

date -d "+1 day" +%Y%m%d //显示后一天的日期
20150822

date -d "-1 day" +%Y%m%d //显示前一天的日期
20150820

date -d "-1 month" +%Y%m%d //显示上一月的日期
20150721

date -d "+1 month" +%Y%m%d //显示下一月的日期
20150921

date -d "-1 year" +%Y%m%d //显示前一年的日期
20140821

date -d "+1 year" +%Y%m%d //显示下一年的日期
20160821
【设置时间】

date -s "20131213" 设置日期

date -s "18:38:00" 设置时间

date -s //设置当前时间,只有root权限才能设置,其他只能查看
date -s 20160823 //设置成20120523,这样会把具体时间设置成空00:00:00
date -s 01:01:01 //设置具体时间,不会对日期做更改
date -s "01:01:01 2016-08-23" //这样可以设置全部时间
date -s "01:01:01 20150823" //这样可以设置全部时间
date -s "2015-08-21 01:01:01" //这样可以设置全部时间
date -s "20150821 01:01:01" //这样可以设置全部时间

Use the following syntax to set new data and time:

# date --set="STRING"
For example, set new data to 2 Oct 2006 18:00:00, type the following command as root user:
# date -s "2 OCT 2006 18:00:00"
OR
# date --set="2 OCT 2006 18:00:00"

You can also simplify format using following syntax:
# date +%Y%m%d -s "20081128"

Linux Set Time Examples
To set time use the following syntax:
# date +%T -s "10:13:13"

Where,

10: Hour (hh)
13: Minute (mm)
13: Second (ss)
Use %p locale's equivalent of either AM or PM, enter:
# date +%T%p -s "6:10:30AM"
# date +%T%p -s "12:10:30PM"

clock与hwclock命令
clock命令,与hwclock命令是同一个命令,主要用来查询和设置硬件时钟(query and set the hardware clock (RTC))。RTC=Real Time Clock,也就是硬件时钟。
在Linux中有硬件时钟与系统时钟等两种时钟。
硬件时钟是指主机板上的时钟设备,也就是通常可在BIOS画面设定的时钟。
系统时钟则是指kernel中的时钟。

clock:显示硬件时间,

hwclock : hwclock -w 把系统时间同步到硬件/ hwclock -s 把硬件时间同步到系统时间,

显示时钟时间

# hwclock -r
OR
# hwclock --show

OR show it in Coordinated Universal time (UTC):
# hwclock --show --utc
Sample outputs:
Wed 23 Apr 2014 10:36:23 AM CDT -0.157239 seconds

简单查看clock帮助信息
[root@localhost ~]#clock help
hwclock - query and set the hardware clock (RTC) //第一行就说明了与hwclock是同一个命令
用法: hwclock [function] [options...]
常用的参数有以下:
-r, --show 读取并打印硬件时钟(read hardware clock and print result )
-s, --hctosys 将硬件时钟同步到系统时钟(set the system time from the hardware clock )
-w, --systohc 将系统时钟同步到硬件时钟(set the hardware clock to the current system time )
示例: 显示硬件时钟
[root@localhost ~]# hwclock
2015年08月21日 星期五 18时42分07秒 -0.986791 seconds
[root@localhost ~]# hwclock -r
2015年08月21日 星期五 18时42分29秒 -0.425118 seconds
[root@localhost ~]# hwclock --show
2015年08月21日 星期五 18时42分50秒 -0.376585 seconds

设置当前时间为系统时间
How do I set the Hardware Clock to the current System Time?
Use the following syntax:
# hwclock --systohc
OR
# hwclock -w

注:系统时间准确,最好还是使用ntp服务进行同步
示例:使用ntpdate命令从网络同步时间,再同步到硬件时钟
ntpdate命令是使用NTP协议来从网络同步时间的命令
NTP=Network Time Protocol 网络时间协议
[root@localhost ~]# ntpdate -u 202.112.10.36
21 Aug 11:01:14 ntpdate[2533]: step time server 202.112.10.36 offset -6690347.700246 sec
[root@localhost ~]# date /注:上面已经做了修改
2015年 08月 21日 星期五 11:01:18 CST
[root@localhost ~]# hwclock -w /系统时间同步到硬件时间

cal:显示日历

cal 查看日历,命令行方式输出

查看cal命令简单帮助信息 [root@localhost ~]# man cal
用法:cal [参数][月份][年份]
常用参数:
-1 显示一个月的月历
-3 显示系统前一个月,当前月,下一个月的月历
-s 显示星期天为一个星期的第一天,默认的格式
-m 显示星期一为一个星期的第一天

示例
显示当前月份日历
[root@localhost ~]# cal
八月 2015
日 一 二 三 四 五 六
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 ~]# cal 9 2015
九月 2015
日 一 二 三 四 五 六
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

显示全年日历
[root@localhost ~]# cal 2015
2015
一月 二月 三月
日 一 二 三 四 五 六 日 一 二 三 四 五 六 日 一 二 三 四 五 六
1 2 3 1 2 3 4 5 6 7 1 2 3 4 5 6 7
4 5 6 7 8 9 10 8 9 10 11 12 13 14 8 9 10 11 12 13 14
11 12 13 14 15 16 17 15 16 17 18 19 20 21 15 16 17 18 19 20 21
18 19 20 21 22 23 24 22 23 24 25 26 27 28 22 23 24 25 26 27 28
25 26 27 28 29 30 31 29 30 31
四月 五月 六月
日 一 二 三 四 五 六 日 一 二 三 四 五 六 日 一 二 三 四 五 六
1 2 3 4 1 2 1 2 3 4 5 6
5 6 7 8 9 10 11 3 4 5 6 7 8 9 7 8 9 10 11 12 13
12 13 14 15 16 17 18 10 11 12 13 14 15 16 14 15 16 17 18 19 20
19 20 21 22 23 24 25 17 18 19 20 21 22 23 21 22 23 24 25 26 27
26 27 28 29 30 24 25 26 27 28 29 30 28 29 30
31
七月 八月 九月
日 一 二 三 四 五 六 日 一 二 三 四 五 六 日 一 二 三 四 五 六
1 2 3 4 1 1 2 3 4 5
5 6 7 8 9 10 11 2 3 4 5 6 7 8 6 7 8 9 10 11 12
12 13 14 15 16 17 18 9 10 11 12 13 14 15 13 14 15 16 17 18 19
19 20 21 22 23 24 25 16 17 18 19 20 21 22 20 21 22 23 24 25 26
26 27 28 29 30 31 23 24 25 26 27 28 29 27 28 29 30
30 31
十月 十一月 十二月
日 一 二 三 四 五 六 日 一 二 三 四 五 六 日 一 二 三 四 五 六
1 2 3 1 2 3 4 5 6 7 1 2 3 4 5
4 5 6 7 8 9 10 8 9 10 11 12 13 14 6 7 8 9 10 11 12
11 12 13 14 15 16 17 15 16 17 18 19 20 21 13 14 15 16 17 18 19
18 19 20 21 22 23 24 22 23 24 25 26 27 28 20 21 22 23 24 25 26
25 26 27 28 29 30 31 29 30 27 28 29 30 31

uptime 查看系统启动可多久,和系统的负载

ls: 文件属性:
-:普通文件
d:目录文件
b:块设备
c:字符设备文件
l:符号连接文件
p:命令管道
s:套接字文件

文件权限:
9位数字,每3位一组
文件硬链接次数
文件所属主(owner)
文件的属组(group)
文件大小(size),单位默认是字节

常用选项:
-l:显示文件属性,ls -l=ll //除了文件名之外,还将文件的权限、所有者、文件大小等信息详细列出来。
-h:做相应的单位转换显示
-a:–all //列出目录下的所有文件,包括以 . 开头的隐含文件显示所有文件
-A:显示.和..以为的所有文件
-d:–directory 显示目录自身属性 //将目录象文件一样显示,而不是显示其下的文件。
-i:显示文件的缩影接点号码(index node ,inode)
-r:–reverse 逆序显示文件列//依相反次序排列
-R:递归显示文件,

[root@localhost ~]# man ls
ls - list directory contents /列出目标目录中所有的子目录和文件
用法:[选项] [目录名]
常用参数比较多,有如下:

-c //配合 -lt:根据 ctime 排序及显示 ctime (文件状态最后更改的时间)配合 -l:显示 ctime 但根据名称排序否则:根据 ctime 排序
-C //每栏由上至下列出项目
–color[=WHEN] //控制是否使用色彩分辨文件。WHEN 可以是'never'、'always'或'auto'其中之一
-d,
-D, –dired //产生适合 Emacs 的 dired 模式使用的结果
-f //对输出的文件不进行排序,-aU 选项生效,-lst 选项失效
-h, –human-readable //以容易理解的格式列出文件大小 (例如 1K 234M 2G)
-k 即 –block-size=1K //以 k 字节的形式表示文件的大小。
-L, –dereference //当显示符号链接的文件信息时,显示符号链接所指示的对象而并非符号链接本身的信息
-m //所有项目以逗号分隔,并填满整行行宽
-R, –recursive //同时列出所有子目录层
-s, –size //以块大小为单位列出所有文件的大小
-S //根据文件大小排序
-t //以文件修改时间排序
-u //配合 -lt:显示访问时间而且依访问时间排序;配合 -l:显示访问时间但根据名称排序;否则:根据访问时间排序
-U //不进行排序;依文件系统原有的次序列出项目
-v //根据版本进行排序
-w, –width=COLS //指定屏幕宽度而不使用目前的数值
-x //逐行列出项目而不是逐栏列出
-X //根据扩展名排序
-1 //每行只列出一个文件

示例:
列出/var/log文件夹下的所有文件和目录的详细资料
[root@localhost /]# ls -l -R /var/log
/var/log:
总用量 1860
-rw-------. 1 root root 2368 8月 20 22:03 anaconda.ifcfg.log
-rw-------. 1 root root 34407 8月 20 22:03 anaconda.log
-rw-------. 1 root root 42974 8月 20 22:03 anaconda.program.log
-rw-------. 1 root root 190963 8月 20 22:03 anaconda.storage.log
-rw-------. 1 root root 139257 8月 20 22:03 anaconda.syslog
-rw-------. 1 root root 33233 8月 20 22:03 anaconda.xlog
-rw-------. 1 root root 119307 8月 20 22:03 anaconda.yum.log
drwxr-x---. 2 root root 4096 8月 20 22:04 audit
-rw-r--r--. 2 root root 2603 8月 21 14:32 boot.log
-rw-------. 1 root utmp 0 8月 20 21:52 btmp
drwxr-xr-x. 2 root root 4096 8月 20 22:05 ConsoleKit
-rw-------. 1 root root 14254 8月 21 15:40 cron
drwxr-xr-x. 2 lp sys 4096 7月 24 19:09 cups
-rw-r--r--. 1 root root 86435 8月 21 14:32 dmesg
-rw-r--r--. 1 root root 86435 8月 21 13:32 dmesg.old
-rw-r--r--. 1 root root 227554 8月 20 22:02 dracut.log
drwxrwx--T. 2 root gdm 4096 8月 21 14:32 gdm
drwx------. 2 root root 4096 7月 24 19:53 httpd
-rw-r--r--. 1 root root 145708 8月 21 14:33 lastlog
-rw-------. 1 root root 1669 8月 21 14:32 maillog
-rw-------. 1 root root 643394 8月 21 14:32 messages
drwxr-xr-x. 2 ntp ntp 4096 7月 24 18:56 ntpstats
-rw-r--r--. 1 root root 89 8月 21 14:32 pm-powersave.log
drwx------. 2 root root 4096 3月 16 16:51 ppp
drwxr-xr-x. 2 root root 4096 8月 20 15:33 prelink
drwxr-xr-x. 2 root root 4096 11月 6 2015 sa
drwx------. 3 root root 4096 8月 20 21:53 samba
-rw-------. 1 root root 10342 8月 21 14:33 secure
-rw-------. 1 root root 0 8月 20 22:04 spice-vdagent.log
-rw-------. 1 root root 0 8月 20 21:55 spooler
drwxr-x---. 2 root root 4096 7月 24 19:45 sssd
-rw-------. 1 root root 0 8月 20 21:50 tallylog
-rw-r--r--. 1 root root 0 8月 20 22:04 wpa_supplicant.log
-rw-rw-r--. 1 root utmp 36864 8月 21 14:33 wtmp
-rw-r--r--. 1 root root 35687 8月 21 14:33 Xorg.0.log
-rw-r--r--. 1 root root 37708 8月 21 14:23 Xorg.0.log.old
-rw-r--r--. 1 root root 31347 8月 20 22:05 Xorg.9.log
-rw-------. 1 root root 0 8月 20 14:21 yum.log
/var/log/audit:
总用量 232
-rw-------. 1 root root 233257 8月 21 15:40 audit.log
/var/log/ConsoleKit:
总用量 8
-rw-r--r--. 1 root root 6387 8月 21 14:32 history
/var/log/cups:
总用量 0
/var/log/gdm:
总用量 200
-rw-r--r--. 1 gdm gdm 504 8月 21 14:32 :0-greeter.log
-rw-r--r--. 1 gdm gdm 998 8月 21 14:23 :0-greeter.log.1
-rw-r--r--. 1 gdm gdm 836 8月 21 11:53 :0-greeter.log.2
-rw-r--r--. 1 gdm gdm 836 8月 21 11:52 :0-greeter.log.3
-rw-r--r--. 1 gdm gdm 836 8月 20 14:16 :0-greeter.log.4
-rw-r--r--. 1 root root 27242 8月 21 14:33 :0.log
-rw-r--r--. 1 root root 28752 8月 21 14:23 :0.log.1
-rw-r--r--. 1 root root 38869 8月 21 13:32 :0.log.2
-rw-r--r--. 1 root root 28752 8月 21 11:52 :0.log.3
-rw-r--r--. 1 root root 36898 8月 20 16:32 :0.log.4
-rw-r--r--. 1 root root 0 8月 21 14:32 :0-slave.log
-rw-r--r--. 1 root root 0 8月 21 13:33 :0-slave.log.1
-rw-r--r--. 1 root root 31 8月 21 11:53 :0-slave.log.2
-rw-r--r--. 1 root root 0 8月 21 10:01 :0-slave.log.3
-rw-r--r--. 1 root root 31 8月 20 14:16 :0-slave.log.4
/var/log/httpd:
总用量 0
/var/log/ntpstats:
总用量 0
/var/log/ppp:
总用量 0
/var/log/prelink:
总用量 56
-rw-r--r--. 1 root root 56381 8月 21 12:35 prelink.log
/var/log/sa:
总用量 168
-rw-r--r--. 1 root root 2460 11月 6 2015 sa06
-rw-r--r--. 1 root root 92904 8月 20 22:00 sa20
-rw-r--r--. 1 root root 62772 8月 21 15:40 sa21
/var/log/samba:
总用量 4
drwx------. 2 root root 4096 7月 24 11:16 old
/var/log/samba/old:
总用量 0
/var/log/sssd:
总用量 0
示例:列出当前/目录中所有以“t”开头的目录的详细内容
[root@localhost /]# ls -l t*
总用量 32
drwx------. 2 root root 4096 8月 20 22:05 keyring-8nQEth
drwx------. 2 root root 4096 8月 20 14:16 keyring-SDqtwB
drwx------. 2 gdm gdm 4096 8月 21 14:32 orbit-gdm
drwx------. 2 gdm gdm 4096 8月 21 14:32 pulse-8WdjQ60VOcZx
drwx------. 2 root root 4096 8月 21 11:53 pulse-hI8dPZuR8vK7
drwx------. 2 root root 4096 8月 20 14:16 virtual-root.ErfcRn
drwx------. 2 root root 4096 8月 21 11:53 virtual-root.Kt3kb3
drwx------. 2 root root 4096 8月 20 22:06 virtual-root.qpXn8K
-rw-------. 1 root root 0 8月 20 21:48 yum.log
示例:列出目前/var/log所有名称是s 开头的档案,愈新的排愈后面
[root@localhost log]# ls -ltr s*
-rw-------. 1 root root 0 8月 20 21:55 spooler
-rw-------. 1 root root 0 8月 20 22:04 spice-vdagent.log
-rw-------. 1 root root 10342 8月 21 14:33 secure
sssd:
总用量 0
samba:
总用量 4
drwx------. 2 root root 4096 7月 24 11:16 old
sa:
总用量 168
-rw-r--r--. 1 root root 92904 8月 20 22:00 sa20
-rw-r--r--. 1 root root 64776 8月 21 15:50 sa21
-rw-r--r--. 1 root root 2460 11月 6 2015 sa06
示例:显示当前目录下隐藏文件
[root@localhost ~]# ls -a
. anaconda-ks.cfg .bash_logout .bashrc install.log .mysql_history satools .tcshrc .vimrc .. .bash_history .bash_profile .cshrc install.log.syslog .rnd .ssh .viminfo
示例:水平输出文件列表
[root@localhost /]# ls -m
bin, boot, data, dev, etc, home, lib, lost+found, media, misc, mnt, opt, proc, root, sbin, selinux, srv, sys, tmp, usr, var
示例:显示文件夹信息
[root@localhost /]# ls -ld /etc/
drwxr-xr-x. 116 root root 12288 8月 21 14:32 /etc/

cd:change directory
cd:回到用户的家目录
cd ~username:进入指定用户的家目录
cd - :在当前目录和前一次所在的目录来回切换
cd ..:切换至其父目录,

[root@localhost ~]# man cd
用户:cd [目录名] //切换目录
常用参数选项
-p 如果要切换到的目标目录是一个符号连接,直接切换到符号连接指向的目标目录
-L 如果要切换的目标目录是一个符号的连接,直接切换到字符连接名代表的目录,而非符号连接所指向的目标目录
cd命令有一些比较灵活的使用技巧,常用的如下:
cd 进入用户主目录
cd ~ 进入用户主目录
cd - 返回进入此目录之前所在的目录
cd .. 返回上级目录(若当前目录为“/“,则执行完后还在“/";".."为上级目录的意思)
cd ../.. 返回上两级目录
cd !$ 把上个命令的参数作为cd参数使用

pwd:--print name of current/working directory //显示用户当前工作目录

pwd命令 // printenv 显示当前环境变量
简单查看pwd命令帮助文档
[root@localhost ~]# man cd
pwd--print name of current/working directory //显示用户当前工作目录
用法:pwd [目录名]
示例:显示当前用户工作路径
[root@localhost ~]# pwd
/root

tty:tty - print the file name of the terminal connected to standard input //显示终端机连接标准输入设备的文件名称
用法:tty [OPTION]...
常用选项参数
-s或--silent或--quiet //不显示任何信息,只回传状态代码
示例:显示终端输入的设备名称
[root@localhost ~]# tty
/dev/pts/0

whereis:

简单查看whereis命令帮助信息
[root@localhost ~]# man whereis
whereis - locate the binary, source, and manual page files for a command //搜索、查找二进制、源文件
用法:whereis [选项][参数]文件
常用选项参数:
-b:只查找二进制文件
-B<目录>:只在设置的目录下查找二进制文件
-f:不显示文件名前的路径名称
-m:只查找说明文件
-M<目录>:只在设置的目录下查找说明文件
-s:只查找原始代码文件
-S<目录>只在设置的目录下查找原始代码文件
-u:查找不包含指定类型的文件
示例:查找passwd相关文件
[root@localhost ~]# whereis passwd
passwd: /usr/bin/passwd /etc/passwd /usr/share/man/man5/passwd.5.gz /usr/share/man/man1/passwd.1.gz
以二进制文件查找/etc/passwd
[root@localhost ~]# whereis -b /etc/passwd
passwd: /usr/bin/passwd /etc/passwd
[root@localhost ~]# whereis -m /etc/passwd
passwd: /usr/share/man/man5/passwd.5.gz /usr/share/man/man1/passwd.1.gz
[root@localhost ~]# whereis -s /etc/passwd
passwd:

which:

简单查看which命令帮助信息
[root@localhost ~]# man which
which - shows the full path of (shell) commands //查找并显示给定命令的绝对路径
用法:which [选项] [参数] 文件
常用参数:
-n<文件名长度>:制定文件名长度,指定的长度必须大于或等于所有文件中最长的文件名
-p<文件名长度>:与-n参数相同,但此处的<文件名长度>包含了文件的路径
示例:查找文件、显示命令路径
[root@localhost ~]# which pwd
/bin/pwd
[root@localhost ~]# which passwd
/usr/bin/passwd

stat:
查看stat命令帮助文档信息
[root@localhost ~]# man stat
stat - display file or file system status
用法:stat[选项][参数]
常用的选项参数
-L:支持符号连接
-f:显示文件系统状态而非文件状态
-t:以简洁方式输出信息
示例:
显示var文件系统

[root@localhost /]# stat -f var

File: "var"
ID: 24776601f298d4cb Namelen: 255 Type: ext2/ext3
Block size: 4096 Fundamental block size: 4096
Blocks: Total: 7021609 Free: 6883938 Available: 6525590
Inodes: Total: 1794048 Free: 1783601

以简洁方式输出信息var文件
[root@localhost /]# stat -t var
var 4096 8 41ed 0 0 fd00 1179649 22 0 0 1440075283 1440079190 1440079190 4096

echo: 输出信息
echo "abc"
echo "字符串" | passwd --stdin USERNAME:利用管道修改用户密码
Linux命令之echo
- 显示文本、打印信息
简单查看echo命令帮助信息
[root@localhost ~]# man echo
echo - display a line of text //打印信息
常用参数
-n 打印信息之后不换行。
-e 对字符串转义。
示例:
打印当前PATH设置信息
[root@localhost ~]# echo $PATH
/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
输出信息字符进行转义
[root@localhost ~]# echo -e 'hello\n51CTO'
hello
51CTO

shutdown: [-akrhHPfnc] [-t secs] time [warning message]
shutdown:关机的命令
-r now:立即重启
-t sec:几秒之后
-h now:立即关机,

简单查看shutdown帮助信息
[root@localhost ~]# man shutdown
shutdown - bring the system down //关闭系统
用法:shutdown [-dfinw]
常用参数:
-k: 不真正关机,只是向系统中的登录用户发出警告信息
-f:重启系统时不执行文件系统检查指令(fsck)
-F:重启系统时执行fsck
-h:关机后不重启,halt、poweroff
-r: 重新启动系统
-n: 不调用init程序,有shutdown完成所有的关机操作。(不推荐)
-t: 关机操作延迟的秒数
-c:用户取消正在执行的shutdown操作,如设置延迟1000秒关机

注意:shutdown在系统关机或重启前,可以向所有的登录用户发送通知,新的登录指令会被禁止,还可以指定关机时间。
shutdown –h HH:MM 警告信息
shutdown指令通过向init程序发送SIGTERM(终止软件、进程)信号,然后发送kill信号,init改变系统的运行级别来完成相关操作。
示例:
立即关机
[root@localhost ~]# shutdown -n
设置1分钟以后关闭计算机,并提示“1 minute after shutdown”
[root@localhost ~]# shutdown -h +1 "1 minute after shutdown"
Broadcast message from root@localhost.localdomain
(/dev/pts/4) at 14:22 ...
The system is going down for halt in 1 minute!
1 minute after shutdown
取消关机
[root@localhost ~]# shutdown -c

halt, poweroff命令
简单查看halt、poweroff命令帮助信息
[root@localhost ~]# man halt

[root@localhost ~]# man poweroff
reboot or stop the system //重启或者关机
用法:halt [选项]...
或 poweroff [选项]...
常见参数都有以下:
-w:不关闭OS,仅在wtmp(登录和退出纪录)中添加相应记录。
-f:强制关闭系统。
-p:关闭OS并且切断电源,即调用poweroff。
示例:
强制关机
[root@localhost ~]# halt -f

[root@localhost ~]# poweroff -f

reboot:
简单查看reboot命令帮助信息
[root@localhost ~]# man reboot
reboot or stop the system //重启或者关机
用法:reboot [-dfinw]
常见参数:
-n:重启系统,不执行sync,不写/var/log/wtmp
-w:不重启,仅在/var/log/wtmp中添加相应记录
-d:重启系统,不写/var/log/wtmp
-f:强制重启,不调用shutdown
-i:重启前,关闭所有网络接口,可以保证系统重启过程中不会有网络用户登录系统。
示例
强制关机
[root@localhost ~]# reboot -f

who: 命令
简单显示who帮助信息
[root@localhost ~]# who --help
用法:who [选项]... [ 文件 | 参数1 参数2 ]
显示当前已登录的用户信息。
常见的参数如下:
-b, --boot 上次系统启动时间
-l,--login 显示系统登录进程
--lookup 尝试通过 DNS 查验主机名
-q, --count 列出所有已登录用户的登录名与用户数量
-u, --users 列出已登录的用户
示例:
显示上次系统引导时间
[root@localhost ~]# who -b
系统引导 2015-08-21 18:01
显示系统登录进程
[root@localhost ~]# who -l
登录 tty3 2015-08-21 10:01 2144 id=3
登录 tty2 2015-08-21 10:01 2142 id=2
登录 tty5 2015-08-21 10:01 2148 id=5
登录 tty4 2015-08-21 10:01 2146 id=4
登录 tty6 2015-08-21 10:01 2150 id=6
显示已登录用户以及次数
[root@localhost ~]# who -q
root root root root root
# 用户数=5

w:命令
简单显示who帮助信息
[root@localhost ~]# man w
  w - Show who is logged on and what they are doing. //显示目前登入系统的用户信息。
  用法:w [-fhlsuV][用户名称]
  常见参数:
  -f  开启或关闭显示用户从何处登入系统。
  -h  不显示各栏位的标题信息列。
  -s  使用简洁格式列表,不显示用户登入时间,终端机阶段作业和程序所耗费的CPU时间。
示例:
显示root用户登入系统信息
[root@localhost ~]# w -f root
11:40:45 up 1:39, 5 users, load average: 0.00, 0.00, 0.00
USER TTY LOGIN@ IDLE JCPU PCPU WHAT
root pts/0 10:06 1:32m 0.06s 0.06s -bash
root pts/1 10:08 1:30m 0.07s 0.07s -bash
root pts/2 10:10 1:27m 0.07s 0.07s -bash
root pts/3 10:13 31:39 0.16s 0.01s man cal
root pts/4 11:13 0.00s 0.10s 0.01s w -f root

whoami:命令
简单显示who帮助信息
[root@localhost ~]# man w
whoami - print effective userid:显示用户名称。
  用法:whoami [OPTION]...
该命令比较简单,示例
[root@localhost ~]# whoami
root

本文出自 “IT_working” 博客,请务必保留此出处http://weine100.blog.51cto.com/2152945/1691281
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: