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这一个插件,所以在这里需要重新学习 ...
随机推荐
- VS打包方法(安装和部署简介)——内含大量图片,密症慎入!
友情提示:内含大量文字.图片,密集恐惧症者慎入! 主要记述一下利用微软集成开发环境VS打包的方法和详细步骤. 1.新建打包工程 打开VS,文件->添加项目->新建项目(如图1),在添加新项 ...
- IOS segue(跳转页面处理)
● Storyboard上每一根用来界面跳转的线,都是一个UIStoryboardSegue对象(简称Segue) Segue的属性 ● 每一个Segue对象,都有3个属性 ➢ 唯一标识 @prope ...
- POJ 3126 Prime Path(筛法,双向搜索)
题意:一个4位的素数每次变动一个数位,中间过程也要上素数,问变成另一个的最小步数. 线性筛一遍以后bfs就好.我写的双向,其实没有必要. #include<cstdio> #include ...
- 【BZOJ3994】[SDOI2015] 约数个数和(莫比乌斯反演)
点此看题面 大致题意: 设\(d(x)\)为\(x\)的约数个数,求\(\sum_{i=1}^N\sum_{j=1}^Md(i·j)\). 莫比乌斯反演 这是一道莫比乌斯反演题. 一个重要的性质 首先 ...
- python_52_函数返回值2
def test1(x,y): print(x,y) test1(1,2)#位置参数调用,按顺序来,与形参一一对应 test1(y=1,x=2)#输出为2 1,不是1 2.关键字参数调用按关键字,不按 ...
- 客户端(springmvc)调用netty构建的nio服务端,获得响应后返回页面(同步响应)
后面考虑通过netty做一个真正意义的简约版RPC框架,今天先尝试通过正常调用逻辑调用netty构建的nio服务端并同步获得返回信息.为后面做铺垫 服务端实现 我们先完成服务端的逻辑,逻辑很简单,把客 ...
- bootstrap2文档的学习
就像刚开始的 优雅,直观,强大的前端框架,让web开发更快,更容易,bootstrap给我的感觉就是把常用的布局,组件(导航,列表,按钮,表格),还有规范化颜色等等,同时它的遍历不至于此,他还支持了自 ...
- latex目录标题常用宏包说明与示例
http://blog.sina.com.cn/s/blog_5e16f1770100gyxn.html
- C#分块拷贝大文件
//定义源文件和目标文件,绝对路径 public static string source = @"E:\C#\C#编程语言详解.pdf"; //2014-6-10 Trainin ...
- java基础面试题:如何把一段逗号分割的字符串转换成一个数组? String s = "a" +"b" + "c" + "d";生成几个对象?
package com.swift; public class Douhao_String_Test { public static void main(String[] args) { /* * 如 ...