目录

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 常用指令学习的更多相关文章

  1. linux常用指令学习记录

    前言 本文主要为学习贴,用来记录一些 linux上的常用指令 以供参考. 文件内容查看 cat 从上往下阅读文件内容 cat [-AbEnTv] ${FILE_NAME) cat -n /etc/is ...

  2. Linux | Linux常用指令学习笔记

    @ 目录 前言 1. Linux目录结构: 2. 运行级别: init.systemctl 3. vim相关快捷键: 4. 开关机相关命令: shutdowm.halt.reboot.sync.log ...

  3. ROS零门槛学渣教程系列(二)——Linux常用指令:mkdir、tar、 unzip、cp、scp、mv、rm、find、apt、ssh

    Linux常用指令通过上一教程,我们获得了ubuntu系统.Linux是一个很大的领域.但不要紧张,我们一步步来就是了,跟着教程,需要能用到新知识,会提前介绍给大家.下面学习几个常用的Linux指令. ...

  4. Linux常用指令(三)

    进入京东运维组实习,收到了很多同事的热心指导,自己也努力学习,按照他们给出的学习计划,真的很充实,学到了很多不只是开发方面的知识. 以下简单记录下自己的笔记,方便以后查阅. 1.文件系统 Linux系 ...

  5. linux常用指令

    整理下来的linux常用指令 mount [-t 文件系统] 设备文件名 挂载点挂载命令,一般用于在挂载ISO,或者其他比如U盘等设备时使用,[-t iso9660]为固定格式,可写可不写,非必写项. ...

  6. Linux常用指令【转载】

    [收藏]Linux常用指令[转载] $ 命令行提示符 粗体表示命令 斜体表示参数 filename, file1, file2 都是文件名.有时文件名有后缀,比如file.zip command 命令 ...

  7. 【ZZ】Linux常用指令

    linux常用指令 - 个人文章 - SegmentFault 思否 https://segmentfault.com/a/1190000011068772 查看目录下有什么文件信息 ls //lis ...

  8. 【Linux】指令学习

    Linux学习记录 生命不息,写作不止 一个有梦有戏的人 @怒放吧德德 分享学习心得,欢迎指正,大家一起学习成长! 1.虚拟机网卡配置 服务器重启完成之后,我们可以通过linux的指令 ip addr ...

  9. Linux常用命令学习6---(vim的使用)

    先说说我,我使用了这么久的vim,但是完全没有将vim的功能完全利用到,无非就是使用了编辑(i).保存(:w).退出(:q).等简单的编辑,命令,以及NerdTree这一个插件,所以在这里需要重新学习 ...

随机推荐

  1. 使用Window Media Player网页播放器

    近段时间在做一个IETM的项目,项目需要使用WebBrower对包含avi的xml进行显示,可avi的显示总是有问题,网上找到这段在html中播放avi的代码,在Win10上表现不错,明天上班用Win ...

  2. IOS UISwitch控件的基本使用

    * UISwitch继承自UIControl,因此也能像UIButton一样监听一些事件,比如状态改变事件* UISwitch可以通过拖线监听状态改变* UISwitch可以通过addTarget:. ...

  3. 【BZOJ4540】 [HNOI2016] 序列(莫队)

    点此看题面 大致题意: 求出一个序列的一段区间中所有子序列最小值之和. 莫队 这道题其实是一道莫队题. 但是需要大量的预处理. 预处理 先考虑预处理两个数组\(lst_i\)和\(nxt_i\),分别 ...

  4. Hadoop集群批量命令执行

    ./pdsh -R ssh -w node-10-0[0-5] hostname -R:指定传输方式,默认为rsh,本例为ssh,如果希望ssh传输需要另行安装pdsh-rcmd-ssh,如果希望ss ...

  5. 在maven项目中 配置代理对象远程调用crm

    1 在maven项目中配置代理对象远程调用crm 1.1 在项目的pom.xml中引入CXF的依赖 <dependency> <groupId>org.apache.cxf&l ...

  6. struts+hibernate+spring整合过程常见问题收集

    1.java.lang.NoClassDefFoundError: org/objectweb/asm/ClassVisitor缺少asm-3.3.jar2.java.lang.NoClassDefF ...

  7. 七、Linux 文件与目录管理

    Linux 文件与目录管理 我们知道Linux的目录结构为树状结构,最顶级的目录为根目录 /. 其他目录通过挂载可以将它们添加到树中,通过解除挂载可以移除它们. 在开始本教程前我们需要先知道什么是绝对 ...

  8. Green Space【绿色空间】

    Green Space Living in an urban area with green spaces has a long-lasting positive impact on people's ...

  9. C++多态实例

    #include <iostream> #include <string> using namespace std; //class 实现 class Employee { s ...

  10. 对二维数组使用指针进行操作的探索(C语言)

    /* Name: 对二维数组使用指针进行操作的探索 Copyright: Author: lingr7 Date: 01/12/18 11:55 Description: */ #include< ...