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这一个插件,所以在这里需要重新学习 ...
随机推荐
- UIButton 加载网络图片
以后就可以 用这个分类 UIButton轻松加载网络图片了, UIButton+WebCache.h #import <UIKit/UIKit.h> @interface UIButt ...
- 2018.5.19 Oracle数据操作和管理表的综合练习
--作业一.使用自己的用户登录,完成如下操作,并且创建5条测试数据 -- 创建学生表(stu),字段如下: -- 学号(stuID) -- 姓名(stuName) -- 性别(stuSex) -- 入 ...
- PAT (Advanced Level) Practise - 1095. Cars on Campus (30)
http://www.patest.cn/contests/pat-a-practise/1095 Zhejiang University has 6 campuses and a lot of ga ...
- AngularJS 数字
AngularJS数字就像JavaScript数字 AngularJS实例: <!DOCTYPE html><html><head><meta http-eq ...
- 牛客NOIP提高组R1 C保护(主席树)
题意 题目链接 Sol Orz lyq 我们可以把一支军队(u, v)拆分为两个(u, lca)和(v, lca) 考虑一个点x,什么时候军队对它有贡献,肯定是u或v在他的子树内,且lca在他的子树外 ...
- ABAP读取长文本的方法
SAP中所有的项目文本都存在以下两张数据表中: 1. STXH 抬头项目文本 透明表 2. STXL 明细项目文本 透明表 长文本读取方法 首先在STXH和STXL中根据OBJECT NAME ...
- 二十二、MySQL 正则表达式
MySQL 正则表达式 在前面的章节我们已经了解到MySQL可以通过 LIKE ...% 来进行模糊匹配. MySQL 同样也支持其他正则表达式的匹配, MySQL中使用 REGEXP 操作符来进行正 ...
- eclipse中使用git上传项目
eclipse中使用git上传项目 先需要上传到本地仓库 先找到此选项打钩 再如下 再添加的属性则可以自动填充邮箱和密码 之后 右键选择import 点击找到git 选中 下一步 如果没有找到git ...
- (转)iOS 对矢量图片的支持如何?
简单说,iOS 支持矢量图片,不过支持的一般.在系统层面上,iOS 对矢量绘图支持得很好.iOS 的 Core Graphics 框架带有很多矢量绘图命令,简单一些的直线.矩形.椭圆,复杂一些的贝赛尔 ...
- Flask初学者:g对象,hook钩子函数
Flask的g对象 作用:g可以可以看作是单词global的缩写,使用“from flask import g”导入,g对象的作用是保存一些在一次请求中多个地方的都需要用到的数据,这些数据可能在用到的 ...