Joinc

导航

linux Bash 常用

linux 帮助文档

man + [命令] eg: man ls
[命令] + --help eg:ls --help
help +[命令] eg:help ce
info + [命令] eg:info ls


echo -e 输出转义后的文字

shell 
文件头一定写
#!/bin/bash
执行shell脚本
1. bash hello.sh
2. chmod 755 hello.sh >>然后相对路径 ./hello.sh 或者绝对路径 /tmp/hello.sh 调用执行

文件重命名 mv hello.sh hellonew.sh


Bash的基本功能


alias 查看系统所有命令别名

alias 别名='原命令' #设定命令别名
unalias 别名 #删除别名

vi ~/.bashrc #写入环境变量文件

Bash 常用快捷键

ctrl+c 强制终止当前命令
ctrl+l 清屏
Ctrl+a 光标移动到命令行首
ctrl+e 光标移动到命令行尾
Ctrl+u 从光标所在位置删除到行首
Ctrl+z 把命令放到后台
ctrl+r 在历史命令中搜索

/etc/profile 常用环境变量配置文件

输出从定向

单大于号覆盖(正确信息)
eg: ifconfig > test.log 定时任务
双大于号是追加(正确信息)
eg: ifconfig >> test.log 定时任务

单大于号覆盖(错误信息)
eg: ifconfig 2> test.log 定时任务
双大于号是追加(错误信息)
eg: ifconfig 2>> test.log 定时任务

命令>>文件 2>&1 同 命令&>>文件 追加的方式把正确和错误的输出都保存在同一个文件中
eg:ifconfig >> test3.log 2>&1
eg:ls woxihuan &>>test4.log

文件保存黑洞
ls &>/dev/null #执行结果直接消失

命令>>文件1 2>>文件2 把正确的输出追加到文件1中,把错误的输出追加到文件2中
eg: cat beautify >> access.log 2>> error.log

posted on 2017-12-20 11:40  Joinc  阅读(188)  评论(0编辑  收藏  举报