linux基础-简单命令

目录

  1. echo

  2. history

  3. 关机和重启相关
    3.1. reboot
    3.2. shutdown
    3.3. halt
    3.4. poweroff

  4. 登录用户信息
    4.1. whoami
    4.2. who
    4.3. w

  5. screen


echo命令

回显(打印)字符串至标准输出,输出的字符串以空白符隔开,默认换行

选项
  • -n:不自动换行
  • -e: 启用\字符解释功能
启用-e后\字符说明
\a发出警告声
\b退格键
\c最后不加上换行符号
\n换行且光标移至行首
\r回车,即光标移至行首,但不换行
\t插入tab
\\插入\字符
\0nnn插入nnn(八进制)所代表的ASCII字符
\xHH插入HH(十六进制)所代表的ASCII字
echo -e '\033[43;31;5mmagedu\033[0m'

history命令

  • 登录shell时,会读取命令历史文件中记录下的命令~/.bash_history
  • 登录进shell后新执行的命令只会记录在缓存中;这些命令会用户退出时“加”至命令历史文件中,不是实时更新
history选项
  • -c clear the history list by deleting all of the entries
  • -a 把历史缓存更新到.bash_history中
  • -r 把文件中的历史命令同步更新到内存中
完全删除history记录
  1. rm .bash_history #删除文件中的history记录
  2. history -c #删除内存中的history记录
history相关变量
历史变量说明
$HISTFILE指定的历史文件
$HISTSZIE最大历史记录条数
$HISTFILESIZE历史文件中的最大记录数
$HISTTIMEFORMAT自定义格式
$HISTIGNORE不记录某些带特殊字符的命令
[root@centos7 data]$echo $HISTFILE
/root/.bash_history
[root@centos7 data]$
[root@centos7 data]$
[root@centos7 data]$echo $HISTFILESIZE
1000
$HISTTIMEFORMAT="%F %T    "

[root@centos7 data]$HISTTIMEFORMAT="%F %T    "
[root@centos7 data]$history 
    1  2018-07-23 09:59:09    history 
    2  2018-07-23 09:59:16    cat .bash_history 
    3  2018-07-23 10:02:08    id
    4  2018-07-23 10:02:13    id -u
    5  2018-07-23 10:02:15    id -u zhu
    6  2018-07-23 10:02:18    id
    7  2018-07-23 10:03:56    history 
    8  2018-07-23 10:04:02    id -u zhu
[root@centos7 data]$HISTIGNORE="history*"

不记录history相关的字符命令

关机或重启有关命令

启动有关命令说明
halt关机
poweroff关机
reboot重启
shutdown关机或重启
shutdown

关机或重启
shutdown [OPTION]… TIME [MESSAGE]

  • -r: reboot
  • -h: halt
  • -c:cancel
  • TIME:无指定,默认相当于 +1
  1. now: 立刻,相当于+0
  2. +m: 相对时间表示法,几分钟之后;例如 +3
  3. hh:mm: 绝对时间表示,指明具体时间

用户登录信息有关命

用户登录信息有关命令说明
whoani显示当前登录用户
who显示当前所有的登录会话
w系统当前所有的登录会话以及操作
[root@centos7 ~]#whoami
root
[root@centos7 ~]#su zhu
[zhu@centos7 root]#whoami
zhu
[zhu@centos7 root]#exit
exit
[root@centos7 ~]#who
root     :0           2018-08-10 11:08 (:0)
root     pts/1        2018-08-10 11:24 (:0)
root     pts/2        2018-08-13 08:13 (192.168.32.1)
root     pts/0        2018-08-11 00:10 (:0)
[root@centos7 ~]#w
 11:31:00 up 1 day, 17:31,  4 users,  load average: 0.00, 0.01, 0.06
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
root     :0       :0               Fri11   ?xdm?   4:29m  1.06s /usr/libexec/gnome-session-binary --session gno
root     pts/1    :0               Fri11    3days  0.05s  0.05s bash
root     pts/2    192.168.32.1     08:13     ?     0.37s  0.01s w
root     pts/0    :0               Sat00    2days  0.12s  0.12s bash
[root@centos7 ~]#

screen命令

该命令可以使连入会话的终端显示内容同步,这样可以让双法都看到对方的操作,方便协作。另外,还可以新创建一个screen会话,作为长操作的会话,这样可以挂起会话进行其他操作而不影响原有操作。

创建会话
  • screen -S screen_name
[root@centos6 ~]$screen -S help
查看会话
  • screen -ls
[root@centos6 ~]$screen -ls
There is a screen on:
	58465.help	(Attached)
1 Socket in /var/run/screen/S-root.

[root@centos6 ~]$screen -x hel
连接会话
  • screen -x screen_name
挂起会话
  • ctrl +A +D
恢复会话
  • screen -r
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值