码迷,mamicode.com
首页 > 系统相关 > 详细

Linux部分命令解释及使用

时间:2017-04-10 20:32:46      阅读:264      评论:0      收藏:0      [点我收藏+]

标签:表达式   字符集   data   开始   this   查看文件内容   file   word   获取   

 

 
Linux部分命令解释及使用
 
ASCII 信息交换码 
GB2312
big5
 
UTF-8 字符集
 
乱码问题 生产环境中最常见故障  字符集格式设置不一致
 
 
查看系统版本  cat /etc/redhat-release 
 
 
$() ``  
 
echo "This system‘s name is $(hostname)"
This system‘s name is cent7.magedu.com
 
echo "This system‘s name is `hostname`"
This system‘s name is cent7.magedu.com
 
[root@cent7 ~]# name=hostname
[root@cent7 ~]# echo "This system‘s name is `$name`"
This system‘s name is cent7.magedu.com
 
括号扩展 {}
 
[root@cent7 ~]# echo {1..10}
1 2 3 4 5 6 7 8 9 10
[root@cent7 ~]# 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
[root@cent7 ~]# 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
[root@cent7 ~]# 
[root@cent7 ~]# echo {000..20..2}
000 002 004 006 008 010 012 014 016 018 020
cp hello.sh{,bak}
 
tab   命令补全
      判断某个命令是否安装
 
 
[root@cent7 ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
定义命令的全路径,避免每次敲命令要使用全部路径
 
 
 
使用频率  1星 
 
command 2Tab  所有命令行补全
string2Tab  以string开头命令        使用频率超5星
 
/2Tab  显示所有根目录下一级目录,包括隐藏目录
./2Tab  当前目录下子目录,包括隐藏目录         ls -da  ./*
*2Tab  当前目录下子目录,不包括隐藏目录        ls -d  ./*
~2Tab  所有用户列表
$2Tab  所有变量  
@2Tab  /etc/hosts记录   (centos7不支持)
=2Tab  相当于ls –A  (CentOS 7 不支持)
 
 
命令行历史  使用5星
 
!string 重复执行前面已string开头的命令
!?string 重复前一个包含string的命令
^string 删除上一条命令中的string
[root@CentOS68 ~]# ls /tmp/
epel.repo.bak         huan.txt        orbit-gdm   pulse-QRIoXpeAIz6g
functions-2017-03-23  keyring-BPBfln  orbit-root  pulse-rnm429VarZOM
[root@CentOS68 ~]# ^tmp/
 
 
^string1^string2 将上一条命令中的第一个string1替换为string2
[root@CentOS68 ~]# ls /tmp/
epel.repo.bak         huan.txt        orbit-gdm   pulse-QRIoXpeAIz6g
functions-2017-03-23  keyring-BPBfln  orbit-root  pulse-rnm429VarZOM
[root@CentOS68 ~]# ^tmp^etc
 
!!:gs/string1/string2 将上一条命令中所有的string1都替换为 string2
 
[root@CentOS68 ~]# ls /tmp/ /tmp/
/tmp/:
epel.repo.bak         huan.txt        orbit-gdm   pulse-QRIoXpeAIz6g
functions-2017-03-23  keyring-BPBfln  orbit-root  pulse-rnm429VarZOM
 
/tmp/:
epel.repo.bak         huan.txt        orbit-gdm   pulse-QRIoXpeAIz6g
functions-2017-03-23  keyring-BPBfln  orbit-root  pulse-rnm429VarZOM
[root@CentOS68 ~]# !!:gs/tmp/opt
ls /opt/ /opt/
/opt/:
rh
/opt/:
rh
 
 
 
command !^ : 利用上一个命令的第一个参数做cmd的参数
ls /tmp  /opt
ls !^
command !$ : 利用上一个命令的最后一个参数做cmd的参数
ls /tmp /opt/
ls !$
command !* : 利用上一个命令的全部参数做cmd的参数
ls /tmp /opt
ls !*
command !:n : 利用上一个命令的第n个参数做cmd的参数
ls /tmp /opt
ls !:1
 
 
command !n:^ 调用第n条命令的第一个参数
 ls !505:^
command !n:$ 调用第n条命令的最后一个参数
ls !505:$
command !n:m 调用第n条命令的第m个参数
ls !505:2
command !n:* 调用第n条命令的所有参数
ls !505:*
 
command !string:^ 从命令历史中搜索以 string 开头的命令,并获取它的第一个参数
ls !ls:^
command !string:$ 从命令历史中搜索以 string 开头的命令,并获取它的最后一个参数
[root@CentOS68 ~]# ls /tmp/ /opt/
/opt/:
rh
 
/tmp/:
epel.repo.bak         huan.txt        orbit-gdm   pulse-QRIoXpeAIz6g
functions-2017-03-23  keyring-BPBfln  orbit-root  pulse-rnm429VarZOM
[root@CentOS68 ~]# ls !ls:$
ls /opt/
rh
 
command !string:n 从命令历史中搜索以 string 开头的命令,并获取它的第n个参数
[root@CentOS68 ~]# ls /tmp/ /opt/
/opt/:
rh
 
/tmp/:
epel.repo.bak         huan.txt        orbit-gdm   pulse-QRIoXpeAIz6g
functions-2017-03-23  keyring-BPBfln  orbit-root  pulse-rnm429VarZOM
[root@CentOS68 ~]# ls !ls:2
ls /opt/
rh
 
command !string:* 从命令历史中搜索以 string 开头的命令,并获取它的所有参数
 
[root@CentOS68 ~]# ls /tmp/ /opt/
/opt/:
rh
 
/tmp/:
epel.repo.bak         huan.txt        orbit-gdm   pulse-QRIoXpeAIz6g
functions-2017-03-23  keyring-BPBfln  orbit-root  pulse-rnm429VarZOM
[root@CentOS68 ~]# ls !ls:*
ls /tmp/ /opt/
/opt/:
rh
 
/tmp/:
epel.repo.bak         huan.txt        orbit-gdm   pulse-QRIoXpeAIz6g
functions-2017-03-23  keyring-BPBf
 
正则表达式  ^$ 位置锚定 开始和结束 
            *  *前面的字符出现任意次
文件通配符  *  匹配所有格式的文件
 
history 默认最多只能记录1000命令
命令历史一般记录在.bash_history文件中
当前shell中的历史记录会被记录在内存中,只有退出之后才会保存在.bash_history中
-a
Append
 
$HISTSIZE 修改history存储条数
$HISTFILE 指定历史文件的存放位置
$HISTFILESIZE 指定历史文件的命令的存储条数
HISTTIMEFORMAT=“%F %T “ 显示每条命令的具体执行时间
HISTIGNORE=  把某些命令敏感的字符串给屏蔽掉不予显示
 
 
环境变量:HISTCONTROL
    ignoredups  默认,忽略重复的命令,连续且相同为“重复”
    ignorespace 忽略所有以空白开头的命令
    ignoreboth  相当于ignoredups, ignorespace的组合
    erasedups   删除重复命令
 
 
export magedu=123 顶一个环境变量
 
 
使用频率超五星
Ctrl + l    清屏,相当于clear命令
Ctrl + c    终止命令
Ctrl + xx    光标在命令行首和光标之间移动
 
Ctrl + a    光标移到命令行首,相当于Home
Ctrl + e    光标移到命令行尾,相当于End
 
 
使用频率 :2星
Ctrl + u    从光标处删除至命令行首
Ctrl + k    从光标处删除至命令行尾
 
 
 
 
date cat ls  cp mv  cal w rm 
more less
who whoami
nano
pwd
useradd
help
history
bash
enable
alias
shutdown
which
type
init 
runlevel
poweroff
echo
passwd
touch
cd
 
whatis
 
lscpu
cat /proc/cpuinfo  查看cpu的信息
显示当前时间
技术分享
 技术分享
 
如果内部命令获取帮助 可以使用help CMD
 
 
less 命令 查看文件内容
类似于cat 或者more
字体颜色改变
技术分享
 技术分享
man –f keyword 查看某个命令使用帮助在哪个章节里面
 
man
space 向文件尾部翻屏
b   向文件首部翻屏
enter  向下一行一行翻 
y  向上一行一行翻
1G 回到文件首部
G  回到文件尾部
 
/keywork  向下搜索 n 向下 N 向上
 
?向上搜索
 
LVS 负载均衡 国防大学 章文嵩  淘宝正明 滴滴打车  开源领域的最大贡献
 
做运维 自己写代码 shell Python JAVA
一定要有帮助文档readme  
 
 
 
 
 
 
 
 
 
 
 

Linux部分命令解释及使用

标签:表达式   字符集   data   开始   this   查看文件内容   file   word   获取   

原文地址:http://www.cnblogs.com/linux53wangtang/p/6690538.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!