LINUX 常用指令学习
目录
0 查找find
1 别名alias
2 变量的设置
3 常用的系统变量
4 通配符及组合按键
5 指令之间的分隔符(;&||)
6 输出重定向(>,>>,1>,2>)
7 管道
通过本问还能了解到
env,set,export
unset,unalias
$?,$RANDOM
last
cut,wc,uniq,sort
0 查找
通过这个格式,可以查找到文件内容为{}里面的数据
find ~ -type f -exec grep -n abs '{}' ';' -print
1 别名(alias)
一、设置方法
alias是一个比较好用的指令,用于对指令进行重新命名,方便记忆和使用
例如:我们要打开系统的网络配置文件就需要输入较长的指令(虽然vi指令不长,但是文件路径有点深并不适合不好记忆)
[root@xiaoftest ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0
我们给这串指令起一个别名’eth0',是不是很方便呢?
[root@xiaoftest ~]# alias eth0='vi /etc/sysconfig/network-scripts/ifcfg-eth0 '
这样下一次访问只需要输入eth0即可达到一样的效果
二、查看
直接输入alias即可查看用户目前已经配置可以用的别名
[root@xiaoftest ~]# alias
alias cp='cp -i'
alias eth0='vi /etc/sysconfig/network-scripts/ifcfg-eth0 ' //这是我们刚才定义的别名
alias l.='ls -d .* --color=tty'
alias ll='ls -l --color=tty'
alias ls='ls --color=tty'
alias mv='mv -i'
alias rm='rm -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
[root@xiaoftest ~]#
三、取消设置别名
unalias
2 变量与变量的设置
一、变量的使用
个人认为变量其实是与别名相似,变量常常用来保存比较深的路径,其实也可以用来保存指令的
变量名='需要定义的值'
[root@xiaoftest /]# test='ls -al'
[root@xiaoftest /]# $test
total
drwxr-xr-x root root Jan : .
drwxr-xr-x root root Jan : ..
-rw-r--r-- root root Jan : .autofsck
另外变量还可以向后追加
[root@xiaoftest /]# name='sunfan'
[root@xiaoftest /]# echo $name
sunfan
[root@xiaoftest /]# name="$name"test //先引用$name后再追加test
[root@xiaoftest /]# echo $name
sunfantest //追加test成功
[root@xiaoftest /]#
先定义变量name的值是sunfan ,然后通过对变量的引用($name)再附加test赋值给name
name的值就变成了sunfantest. (注意 1变量的赋值一定在等号前后不能有空格 2引用变量的时候一定要用双引号)
在引用变量后面添加值后再赋值给这个变量的方法常常用于对环境变量的配置,
如果我要在环境变量里写入JAVA_HOME="XXXXXX", 这样就会很方便--->PATH="$PATH":XXXXXX
二、查看系统变量
env 显示目前系统中主要的变量
set 显示系统中全部的变量内容
export 如果不接变量的话,则打印所有的变量同set
如果接变量的话,则将用户变量添加至环境变量中去
[root@xiaoftest ~]# name='test' //不使用export
[root@xiaoftest ~]# env |grep name //环境变量中去查询不到name
[root@xiaoftest ~]# echo $name
test
[root@xiaoftest ~]# export name="testtest" //使用export赋值
[root@xiaoftest ~]# echo $name
testtest
[root@xiaoftest ~]# env |grep name //环境变量中能够查询到name
name=testtest //结果
三、取消设置变量
unset
3 常用的系统变量
? 变量(常用)
echo $? 用于输出上一个指令执行是否错误,说明没有错误则显示0,如果是错误的话,就显示错误码
[root@xiaoftest /]# ls
bin dev home lib media mnt proc sbin sfcd sys usr
boot etc initrd lost+found misc opt root selinux srv tmp var
[root@xiaoftest /]# echo $?
0 //上一句指令执行成功
[root@xiaoftest /]# lls
-bash: lls: command not found
[root@xiaoftest /]# echo $?
127 //上一句指令执行失败,错误码127
[root@xiaoftest /]#
RANDOM
[root@xiaoftest ~]# echo $RANDOM
4 通配符及组合按键

5 指令之间的分隔符
command1;command2
指令1和指令2都会执行
[root@xiaoftest sfcd]# ls;ls
d
d
command1&&command2
指令1成功的情况下指令2才会执行
[root@xiaoftest sfcd]# ls&&ls
d
d
command1||command2
指令1失败的情况下指令2才会执行
[root@xiaoftest sfcd]# lll||ls
-bash: lll: command not found
d
6 输出重定向
>,>> 都是屏幕输出到文件 ,>与>>的区别在于 >>是追加在原有文本内容的后面,而>则是覆盖
1> 成功的信息输入
2> 报错的信息输入
下面给三个例子
成功的信息输入到a 失败的信息输入到b
[root@xiaoftest sfcd]# lll >>a >>b
[root@xiaoftest sfcd]# lll >>a >>b
[root@xiaoftest sfcd]# lll >>a >>b
[root@xiaoftest sfcd]# cat a b
-bash: lll: command not found
-bash: lll: command not found
-bash: lll: command not found
[root@xiaoftest sfcd]#
成功和失败的信息都输入到c(注意同文件的失败信息输出是>&1)
[root@xiaoftest sfcd]# lll 1>>c 2>&1 //报错
[root@xiaoftest sfcd]# lll 1>>c 2>&1 //报错
[root@xiaoftest sfcd]# lll 1>>c 2>&1 //报错
[root@xiaoftest sfcd]# ll 1>>c 2>&1 //成功
[root@xiaoftest sfcd]# cat c
-bash: lll: command not found
-bash: lll: command not found
-bash: lll: command not found
total 12
-rw-r--r-- 1 root root 0 Jan 1 20:09 a
-rw-r--r-- 1 root root 90 Jan 1 20:09 b
-rw-r--r-- 1 root root 90 Jan 1 20:11 c
-rwxrwxrwx 1 root root 3 Jan 1 14:57 d
[root@xiaoftest sfcd]#
成功的信息输入到a 失败的丢到垃圾桶
[root@xiaoftest sfcd]# ll 1>>e 2>>/dev/null
[root@xiaoftest sfcd]# lll 1>>e 2>>/dev/null
[root@xiaoftest sfcd]# cat e
total 12
-rw-r--r-- 1 root root 0 Jan 1 20:09 a
-rw-r--r-- 1 root root 90 Jan 1 20:09 b
-rw-r--r-- 1 root root 267 Jan 1 20:11 c
-rwxrwxrwx 1 root root 3 Jan 1 14:57 d
-rw-r--r-- 1 root root 0 Jan 1 20:13 e
7 管道
对命令的结果进行一步一步的过滤及筛选
例如command1|command2|command3...
command1的结果传递给command2,command1进行过滤后传递给command3...最后输出

...悲剧 ,我本想是看grep reboot的结果命令少打了
[root@xiaoftest sfcd]# last |reboot //这第二个命令直接重启了,悲剧。
重新来!
[root@xiaoftest ~]# last|grep reboot
reboot system boot 2.6.-.EL Wed Jan : (:)
reboot system boot 2.6.-.EL Wed Jan : (:)
reboot system boot 2.6.-.EL Wed Jan : (:)
reboot system boot 2.6.-.EL Wed Jan : (:) 在第一个命令结束后再根据第一个命令获得了reboot的记录
[root@xiaoftest ~]# last|grep reboot|wc -l
4
在第二个命令结束后再根据第二个命令获得了reboot的具体次数统计
管道的常用指令
cut 用于筛选文档
[root @test /root ]# cut -d "分隔字符" [-cf] fields
参数说明:
-d :后面接的是用来分隔的字符,默认是『空格符』
-c :后面接的是『第几个字符』
-f :后面接的是第几个区块?
范例:
[root @test /root]# cat /etc/passwd | cut -d ":" -f
将 passwd 这个档案里面,每一行里头的 : 用来作为竖线,
而列出第一个区块!也就是姓名所在啦!
[root @test /root]# last | cut -d " " -f1
以空格符为分隔,并列出第一个区间!
[root @test /root]# last | cut -c1-
将 last 之后的数据,每一行的 - 个字符取出来!
-c 的使用
[root@xiaoftest ~]# last|cut -c1-15 //输出1-15个字符
root pts/
reboot system
root pts/
reboot system
-d -f的使用 -d是采用分隔符 -f用来读取第N个区间的(注意:这里是整体的划分,如本用例就是左右的整体划分)
[root@xiaoftest sfcd]# cat user
Mary/password
Peter/password
kittey/password xiaoLi/password
xiaoming/password test/password
test2/password
[root@xiaoftest sfcd]# cat user |cut -d "/" -f1 //第一区间
Mary
Peter
kittey xiaoLi
xiaoming test
test2
[root@xiaoftest sfcd]# cat user |cut -d "/" -f2 //第二区间
password
password
password password
password password
password
wc 用于统计
[root @test /root ]# wc [-lmw]
参数说明:
-l :多少行
-m :多少字符
-w :多少字?
范例:
[root @test /root]# cat /etc/passwd | wc -l
这个档案里头有多少行?
[root @test /root]# cat /etc/passwd | wc -w
这个档案里头有多少字!?
uniq 用于去重
[root@xiaoftest sfcd]# last |cut -d " " -f 1 |uniq //使用了去重
root
reboot
root
reboot
[root@xiaoftest sfcd]# last |cut -d " " -f 1 //没有使用去重
root
root
root
reboot
root
reboot
sort 排序(更加有利于去重与uniq配合使用较好)
[root@xiaoftest sfcd]# last |cut -d " " -f |sort |uniq //先排序后去重 reboot
root
wtmp
[root@xiaoftest sfcd]#
LINUX 常用指令学习的更多相关文章
- linux常用指令学习记录
前言 本文主要为学习贴,用来记录一些 linux上的常用指令 以供参考. 文件内容查看 cat 从上往下阅读文件内容 cat [-AbEnTv] ${FILE_NAME) cat -n /etc/is ...
- Linux | Linux常用指令学习笔记
@ 目录 前言 1. Linux目录结构: 2. 运行级别: init.systemctl 3. vim相关快捷键: 4. 开关机相关命令: shutdowm.halt.reboot.sync.log ...
- ROS零门槛学渣教程系列(二)——Linux常用指令:mkdir、tar、 unzip、cp、scp、mv、rm、find、apt、ssh
Linux常用指令通过上一教程,我们获得了ubuntu系统.Linux是一个很大的领域.但不要紧张,我们一步步来就是了,跟着教程,需要能用到新知识,会提前介绍给大家.下面学习几个常用的Linux指令. ...
- Linux常用指令(三)
进入京东运维组实习,收到了很多同事的热心指导,自己也努力学习,按照他们给出的学习计划,真的很充实,学到了很多不只是开发方面的知识. 以下简单记录下自己的笔记,方便以后查阅. 1.文件系统 Linux系 ...
- linux常用指令
整理下来的linux常用指令 mount [-t 文件系统] 设备文件名 挂载点挂载命令,一般用于在挂载ISO,或者其他比如U盘等设备时使用,[-t iso9660]为固定格式,可写可不写,非必写项. ...
- Linux常用指令【转载】
[收藏]Linux常用指令[转载] $ 命令行提示符 粗体表示命令 斜体表示参数 filename, file1, file2 都是文件名.有时文件名有后缀,比如file.zip command 命令 ...
- 【ZZ】Linux常用指令
linux常用指令 - 个人文章 - SegmentFault 思否 https://segmentfault.com/a/1190000011068772 查看目录下有什么文件信息 ls //lis ...
- 【Linux】指令学习
Linux学习记录 生命不息,写作不止 一个有梦有戏的人 @怒放吧德德 分享学习心得,欢迎指正,大家一起学习成长! 1.虚拟机网卡配置 服务器重启完成之后,我们可以通过linux的指令 ip addr ...
- Linux常用命令学习6---(vim的使用)
先说说我,我使用了这么久的vim,但是完全没有将vim的功能完全利用到,无非就是使用了编辑(i).保存(:w).退出(:q).等简单的编辑,命令,以及NerdTree这一个插件,所以在这里需要重新学习 ...
随机推荐
- windows xp professional 序列号(密钥)及百度网盘下载地址
HH7VV-6P3G9-82TWK-QKJJ3-MXR96 https://pan.baidu.com/share/link?uk=4247247642&shareid=500360
- window下部署yapi
YApi 是一个可本地部署的.打通前后端及QA的.可视化的接口管理平台. 环境要求 nodejs(尽量最新版本) mongodb(尽量最新版本) 1.安装node https://www.runoob ...
- 谷歌SwitchySharp && SwitchyOmega插件
http://pan.baidu.com/s/1jOwgu 谷歌SwitchySharp插件 http://pan.baidu.com/s/1mgl7e2k SwitchySharp的升级版Switc ...
- 运维自动化之Cobbler系统安装详解
原文链接 参考文档 参考文档SA们现在都知道运维自动化的重要性,尤其是对于在服务器数量按几百台.几千台增加的公司而言,单单是装系统,如果不通过自动化来完成,根本是不可想象的. 运维自动化安装方面,早期 ...
- Webpack--模块打包器
首先介绍一个安装webpack的百度经验:https://jingyan.baidu.com/article/a3a3f811230ee58da3eb8a6e.html 推荐一个详细介绍webpack ...
- 解决: Intelij IDEA 创建WEB项目时没有Servlet的jar包
今天创建SpringMVC项目时 用到HttpServletRequest时, 发现项目中根本没有Servlet这个包, 在网上搜了一下,这个问题是因为web项目没有添加服务器导致的. 配置tomec ...
- 散列表的ASL计算
题目: 已知关键字序列为{30,25,72,38,8,17,59},设散列表表长为15.散列函数是H(key)=key MOD 13,处理冲突的方法为二次探测法Hi= ( H(key) + di )m ...
- 爬虫学习(九)——登录获取cookie爬取
import urllib.requestimport urllib.parseimport http.cookiejar # http.cookiejar 该包是专门对网页的cookie只进行获取的 ...
- hibernate系列之一
通过自己不断的学习框架以及相关知识的学习,自己学会总结了学习路上遇到的一些问题以及疑惑,自己现在跟着相关的学习资料又进行了一些总结和实践,希望通过自己走过的学习之路能够帮助小伙伴们解决一些学习上问题或 ...
- Zabbix监控告警Lack of free swap space on Zabbix server解决办法
报错详情如下: 是因为Zabbix监控没有考虑虚拟主机的交换空间情况 解决办法修改配置 修改表达式内容:{Template OS Linux:system.swap.size[,pfree].last ...