Linux学习笔记-基础命令(一)

  1. 显示日期与时钟
[root@centos6 ~]# date                       #查看日期
Mon Jul 17 19:38:37 CST 2017
[root@centos6 ~]# clock                      #查看硬件时间
Mon 17 Jul 2017 07:39:04 PM CST  -0.097558 seconds
[root@centos6 ~]#
[root@centos6 ~]# hwclock                    #查看硬件时间
Mon 17 Jul 2017 07:39:09 PM CST  -0.595049 seconds
[root@centos6 ~]# date
Mon Jul 17 19:39:20 CST 2017
  1. 校准时间
[root@centos6 ~]# clock -w                #以系统时间为准修改硬件时间
[root@centos6 ~]# clock -s                #以硬件时间为准修改系统时间
  1. 显示Linux的日历
[root@centos6 ~]# cal                     #显示当前月份的日历
[root@centos6 ~]# cal 1995                #显示指定的日历
  1. 关机命令
  • 关机
[root@centos6 ~]# halt                    #关机
[root@centos6 ~]# poweroff                #关机并切断电源
[root@centos6 ~]# shutdown -r             # -r重启    -h关机
[root@centos6 ~]#          -h
[root@centos6 ~]# shutdown -r +1          # +1表示在一分钟之后执行重启
Broadcast message from [email protected]
        (/dev/pts/1) at 20:10 ...
The system is going down for reboot in 1 minute!
^C                                        #当前用户按Ctrl+c取消重启计划
shutdown: Shutdown cancelled
  • 指定具体的关机或者重启时间
[root@centos6 ~]# shutdown -h 22:00
[root@centos6 ~]# shutdown -r 0718 22:00      #7月18号22:00重启
[root@centos6 ~]# shutdown -r 180718 22:00    #18年7月18号重启
  • 2分钟后关机,并发送消息"will halt"给所有用户
[root@centos6 ~]# shutdown -h +2 "will halt"
  • 取消shutdown计划
[root@centos6 ~]# shutdown -c        

CentOS6与CentOS7的区别

#
[root@centos6 ~]# shutdown -r +1 "will halt"      #CentOS6需要指定时间
#
[root@centos6 ~]# shutdown -r  "will halt"        #CentOS7默认一分钟
  1. 用户登录信息的查看
[root@centos6 ~]# who                   #查看用户登录信息
[root@centos6 ~]# w                     #查看详细的登录信息以及执行的命令
[root@centos6 ~]# whoami                #查看当前的用户名
[root@centos6 ~]# who am i              #查看当前登录信息
#
#
[root@centos6 ~]# who
root     tty1         2017-07-17 19:37 (:0)
root     pts/0        2017-07-17 19:38 (:0.0)
root     pts/1        2017-07-17 19:38 (192.168.0.1)
[root@centos6 ~]# whoami
root
[root@centos6 ~]# who am i
root     pts/1        2017-07-17 19:38 (192.168.0.1)
[root@centos6 ~]# w
 20:42:31 up  1:13,  3 users,  load average: 1.12, 0.83, 0.39
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
root     pts/0    :0.0             19:38    1:04m  0.05s  0.05s /bin/bash
root     pts/1    192.168.0.1      19:38    1.00s  0.90s  0.53s w
  1. screen会话
  • screen会话是独立运行的,只要没有终止都是可以恢复的。即使在远程时网络连接中断screen会话依然继续运行。
  • 适用于长时间的远程操作,这样不用担心中途网络问题而造成工作中断。

  • 安装screen

[root@centos6 Packages]# rpm -ivh screen-4.0.3-19.el6.x86_64.rpm 
  • 创建一个screen
[root@centos6 ~]# screen -S aubin        # -S为大写
  • 加入一个screen会话
[root@centos6 ~]# screen -x aubin
  • 列出所有会话
[root@centos6 ~]# screen -ls
  • 退出并关闭会话,关闭后强制已连接用户退出会话
[root@centos6 ~]# exit
  • 剥离会话-----剥离会话不是退出,进程将继续运行
Ctrl+a,                                   #先按Ctrl+a,再按B
  • 恢复会话
    -------当会话没有用户时screen -x aubin恢复会话
    -------当会话中有用户时使用screen -x加入会话
[root@centos6 ~]# screen -x aubin
  1. 更新Linux时间
[root@centos6 ~]# netdate 223.6.6.6
  1. 命令替换之反单引号的使用
    反单引号的作用与$()的作用相同
  2. echo命令
    echo默认"为双引号
    " 双引号识别变量,不识别命令
    ' 单引号不识别变量,不识别命令
    ` 反单引号识别变量,识别命令
[root@centos6 ~]# echo echo $UID 
echo 0
[root@centos6 ~]# echo "echo $UID"
echo 0
[root@centos6 ~]# echo 'echo $UID'
echo $UID
[root@centos6 ~]# echo `echo $UID`
0

echo [-neE] [字符串]

-e 启用 \ 字符的解释功(启用转义字符)
-E (默认)不支持 \ 解释功能
-n 不自动换行
↓字符串
\a 发出警告声
\b 退格键
\c 最后不加上换行符号
\n 换行且光标移至行首
\r 回车,即光标移至行首,但不换行
\t 插入tab
\\ 插入\字符
\0nnn 插入nnn(八进制)所代表的ASCII字符
echo -e '\033[43;31;5mmagedu\033[0m'
\xHH插入HH(十六进制)所代表的ASCII字
  1. bc计算器
    计算器默认输入、输出都为10进制
[root@centos6 ~]# bc                                #打开计算器
bc 1.06.95
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'. 
obase=16                                            #设置输出为16进制
ibase=2                                             #设置输入为2进制
11111111100001111                                   #输入一个2进制数
1FF0F                                               #计算器返回16进制数
  1. 命令行的扩展
  • 创建1-10的log文件
[root@centos6 test]# touch {1..10}.log
[root@centos6 test]# ls
10.log  1.log  2.log  3.log  4.log  5.log  6.log  7.log  8.log  9.log
  • 输出a-z
[root@centos6 test]# echo {a..z}
a b c d e f g h i j k l m n o p q r s t u v w x y z
  • 输出从000到100的等差以.log结尾
[root@centos6 test]# echo {000..100..3}.log
000.log 003.log 006.log 009.log 012.log 015.log 018.log 021.log 024.log 
027.log 030.log 033.log 036.log 039.log 042.log 045.log 048.log 051.log 
054.log 057.log 060.log 063.log 066.log 069.log 072.log 075.log 078.log 
081.log 084.log 087.log 090.log 093.log 096.log 099.log
  • 创建一批1-5的log、txt文件
[root@centos6 /]# mkdir {1..5}.{log,txt}
[root@centos6 /]# rm -r  {1..5}.{log,txt}

[root@centos6 /]# getent passwd


反单引号额练习

你可能感兴趣的:(Linux学习笔记-基础命令(一))