草庐IT

Linux基础命令二

tushanbu 2023-03-28 原文

Linux基础二


Linux基本原则

由目的单一的小程序组成,组合小程序完成复杂任务;

  1. 一切皆文件;
  2. 配置文件保存为纯文本格式。

bash特性

支持命令历史、命令补全,支持管道、重定向,支持命令别名,支持命令行编辑,支持命令行展开,支持文件名通配,支持变量,支持编程
shell
shell(外壳),广义的shell可以理解为是用户的工作环境,在windows看来桌面就是一个shell,在linux看来终端就是shell
常见的shell有两种,一种是图形界面,即GUI,一种是命令行终端,即CLI。
常用的GUI:Graphic User Interface,Windows,XWindow,Gnome,KDE,Xface
常用的CLI:Command Line Interface,bash,sh,csh,zsh,ksh,tcsh

基础命令

Tab //路径补全

[root@lnh ~]# cd /etc/sys
sysconfig/ sysctl.d/  systemd/   
[root@lnh ~]# cd /etc/sysconfig/
console/         modules/         network-scripts/ 
[root@lnh ~]# cd /etc/sysconfig/network-scripts/
[root@lnh network-scripts]# 
//Tab一下没有补全,就Tab俩下补全路径

alias +定义名字='运行的命令'//命令别名

[root@lnh ~]# cd /etc/sysconfig/network-scripts/
[root@lnh network-scripts]# cd
[root@lnh ~]# alias dx='cd /etc/sysconfig/network-scripts/'
[root@lnh ~]# dx
[root@lnh network-scripts]# 
//复制上面运行的命令到下面的单引号里面,然后在alias 后面随便定义一个名字等于刚刚复制过来的命令,再去执行自己定义的名字就相当于执行了上面那个复制过来的命令

history //查看命令历史
-c //清空保存下来的历史
-d//指定删除哪一条命令(历史)
-w//保存命令历史到/.bash_history中

[root@lnh ~]# history 
    1  shell ls
    2  echo shell
    3  echo $SHELL
    4  cd /etc/sysconfig/network-scripts/
    5  cd
    6  alias dx='cd /etc/sysconfig/network-scripts/'
    7  dx
    8  cd
    9  history 
[root@lnh ~]# history -c
[root@lnh ~]# history 
    1  history 
[root@lnh ~]# pwd
/root
[root@lnh ~]# history -d 1
[root@lnh ~]# history 
    1  pwd
    2  history -d 1
    3  history 
[root@lnh ~]# history -w
[root@lnh ~]# history 
    1  pwd
    2  history -d 1
    3* 
    4  history -w
    5  history 
[root@lnh ~]# history -c
[root@lnh ~]# history 
    1  history 
//-d删除指定的命令后它后面的命令会前进它的命令顺序上面,后面的命令依次排序

命令历史的使用技巧
!n //执行历史中的第几条命令
!-n//执行历史中的倒数第几条命令
!! // 执行上一条命令
!+历史最近命令//执行次命令
!$//引用前一个命令的最后一个参数
Esc+. //按下esc后按.引用上一条命令

[root@lnh ~]# !1
history 
    1  history 
[root@lnh ~]# !-1
history 
    1  history 
[root@lnh ~]# !!
history 
    1  history 
[root@lnh ~]# !history
history 
    1  history 
[root@lnh ~]# !$
history
    1  history 
    2  history
[root@lnh ~]# history
    1  history 
    2  history

命令替换

[root@lnh ~]# date 
Wed Jun 29 23:50:25 CST 2022
[root@lnh ~]# echo $(date +%Y%m%d)
20220629
[root@lnh ~]# echo `date +%Y%m%d`
20220629
不建议用反引号(`),一般都是用小括号

PATH//命令搜索路径
HISTSIZE //可以查看命令历史的存储空间
RANDOM //保存着0-32768之间的随机数
SHELL //当前正在用的shell

[root@lnh ~]# echo $PATH 
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@lnh ~]# echo $HISTSIZE 
1000
[root@lnh ~]# echo $RANDOM 
22103
[root@lnh ~]# echo $RANDOM 
3357
[root@lnh ~]# echo $RANDOM 
10760
[root@lnh ~]# echo $SHELL
/bin/bash //当前shell
[root@lnh ~]# cat /etc/shells 
/bin/sh
/bin/bash
/usr/bin/sh
/usr/bin/bash
//系统可以使用的shell

*,?,[],^,-的用法

[root@lnh ~]# cd xbz/
[root@lnh xbz]# touch {1..100}
[root@lnh xbz]# ls
1    14  2    24  3   35  40  46  51  57  62  68  73  79  84  9   95  bb
10   15  20   25  30  36  41  47  52  58  63  69  74  8   85  90  96
100  16  21   26  31  37  42  48  53  59  64  7   75  80  86  91  97
11   17  22   27  32  38  43  49  54  6   65  70  76  81  87  92  98
12   18  222  28  33  39  44  5   55  60  66  71  77  82  88  93  99
13   19  23   29  34  4   45  50  56  61  67  72  78  83  89  94  b
[root@lnh xbz]# ls 1*
1  10  100  11  12  13  14  15  16  17  18  19
[root@lnh xbz]# ls 2*
2  20  21  22  23  24  25  26  27  28  29
222:
a
//*表示列出了任意字符的长度(此处表示所有字符)
[root@lnh xbz]# ls ?
1  2  3  4  5  6  7  8  9

b:
[root@lnh xbz]# ls ??
10  15  20  25  30  35  40  45  50  55  60  65  70  75  80  85  90  95
11  16  21  26  31  36  41  46  51  56  61  66  71  76  81  86  91  96
12  17  22  27  32  37  42  47  52  57  62  67  72  77  82  87  92  97
13  18  23  28  33  38  43  48  53  58  63  68  73  78  83  88  93  98
14  19  24  29  34  39  44  49  54  59  64  69  74  79  84  89  94  99

bb:
[root@lnh xbz]# ls ???
100

222:
a
//?表示匹配任意单个字符(此时表示一个?为单个字符,两个?表示两个字符,三个?表示三个字符)
[root@lnh xbz]# ls [23-33]
2  3
[root@lnh xbz]# ls [23-89]
2  3  4  5  6  7  8  9
[root@lnh xbz]# ls [23-33][23-33]
22  23  32  33
[root@lnh xbz]# ls [23-89][23-89]
22  26  32  36  42  46  52  56  62  66  72  76  82  86  92  96
23  27  33  37  43  47  53  57  63  67  73  77  83  87  93  97
24  28  34  38  44  48  54  58  64  68  74  78  84  88  94  98
25  29  35  39  45  49  55  59  65  69  75  79  85  89  95  99
//[]表示范围内的单个字符,例如此处[23-33]里面只有两个字符2,3,[23-89]里面有2,3,4,5,6,7,8,9,[23-89][23-89]表示左边[]里面的字符与右边[]字符进行俩俩组合,用左边的与右边的进行组合
[root@lnh xbz]# ls [^23-89]
1

b:
[root@lnh xbz]# ls [^23-79]
1  8

b:
[root@lnh xbz]# ls [^23-71]
8  9

b:
[root@lnh xbz]# ls [^53-71]
2  8  9

b:
[root@lnh xbz]# ls [^53-49]
1  2  6  7  8

b:
[root@lnh xbz]# ls [^33]
1  2  4  5  6  7  8  9

b:

[root@lnh xbz]# ls [53-49^]
3  4  5  9
[root@lnh xbz]# ls [22-33^]
2  3
//^在前面表示除了括号里面的字符的其他所有字符,在后面的话没有表示什么意义或者说只是表示次括号里面的字符
[root@lnh xbz]# ls [22-33]
2  3
[root@lnh xbz]# ls [53-49]
3  4  5  9
[root@lnh xbz]# ls [2-44]
2  3  4
[root@lnh xbz]# ls [-100]
1
[root@lnh xbz]# ls [-59]
5  9
[root@lnh xbz]# ls [33-]
3
//-在前面表示就两个字符的单个的字符,这中间表示前一个字符到后一个范围内的字符,在后面也是和在前面效果一样

命令类型

type//内部命令(shell内置)外部命令:在文件系统的某个路径下有一个与命令名称相应的可执行文件

[root@lnh ~]# type pwd
pwd is a shell builtin //内部
[root@lnh ~]# type cd 
cd is a shell builtin  //内部
[root@lnh ~]# type ls
ls is aliased to `ls --color=auto' //外部
[root@lnh ~]# type /usr/bin/ls
/usr/bin/ls is /usr/bin/ls         //外部
圣人(内)生而知之,就是一直都存在的
凡人(外)学而知之,通过后来学习来的

有关Linux基础命令二的更多相关文章

  1. ruby - 在 Ruby 中编写命令行实用程序 - 2

    我想用ruby​​编写一个小的命令行实用程序并将其作为gem分发。我知道安装后,Guard、Sass和Thor等某些gem可以从命令行自行运行。为了让gem像二进制文件一样可用,我需要在我的gemspec中指定什么。 最佳答案 Gem::Specification.newdo|s|...s.executable='name_of_executable'...endhttp://docs.rubygems.org/read/chapter/20 关于ruby-在Ruby中编写命令行实用程序

  2. postman接口测试工具-基础使用教程 - 2

    1.postman介绍Postman一款非常流行的API调试工具。其实,开发人员用的更多。因为测试人员做接口测试会有更多选择,例如Jmeter、soapUI等。不过,对于开发过程中去调试接口,Postman确实足够的简单方便,而且功能强大。2.下载安装官网地址:https://www.postman.com/下载完成后双击安装吧,安装过程极其简单,无需任何操作3.使用教程这里以百度为例,工具使用简单,填写URL地址即可发送请求,在下方查看响应结果和响应状态码常用方法都有支持请求方法:getpostputdeleteGet、Post、Put与Delete的作用get:请求方法一般是用于数据查询,

  3. ruby-on-rails - rbenv:从 RVM 移动到 rbenv 后,在 Jenkins 执行 shell 中找不到命令 - 2

    我从Ubuntu服务器上的RVM转移到rbenv。当我使用RVM时,使用bundle没有问题。转移到rbenv后,我在Jenkins的执行shell中收到“找不到命令”错误。我内爆并删除了RVM,并从~/.bashrc'中删除了所有与RVM相关的行。使用后我仍然收到此错误:rvmimploderm~/.rvm-rfrm~/.rvmrcgeminstallbundlerecho'exportPATH="$HOME/.rbenv/bin:$PATH"'>>~/.bashrcecho'eval"$(rbenvinit-)"'>>~/.bashrc.~/.bashrcrbenvversions

  4. 软件测试基础 - 2

    Ⅰ软件测试基础一、软件测试基础理论1、软件测试的必要性所有的产品或者服务上线都需要测试2、测试的发展过程3、什么是软件测试找bug,发现缺陷4、测试的定义使用人工或自动的手段来运行或者测试某个系统的过程。目的在于检测它是否满足规定的需求。弄清预期结果和实际结果的差别。5、测试的目的以最小的人力、物力和时间找出软件中潜在的错误和缺陷6、测试的原则28原则:20%的主要功能要重点测(eg:支付宝的支付功能,其他功能都是次要的)80%的错误存在于20%的代码中7、测试标准8、测试的基本要求功能测试性能测试安全性测试兼容性测试易用性测试外观界面测试可靠性测试二、质量模型衡量一个优秀软件的维度①功能性功

  5. ES基础入门 - 2

    ES一、简介1、ElasticStackES技术栈:ElasticSearch:存数据+搜索;QL;Kibana:Web可视化平台,分析。LogStash:日志收集,Log4j:产生日志;log.info(xxx)。。。。使用场景:metrics:指标监控…2、基本概念Index(索引)动词:保存(插入)名词:类似MySQL数据库,给数据Type(类型)已废弃,以前类似MySQL的表现在用索引对数据分类Document(文档)真正要保存的一个JSON数据{name:"tcx"}二、入门实战{"name":"DESKTOP-1TSVGKG","cluster_name":"elasticsear

  6. ruby - 从 Ruby : capturing the output while displaying the output? 运行 shell 命令 - 2

    我有一个问题。我想从另一个ruby​​脚本运行一个ruby​​脚本并捕获它的输出信息,同时让它也输出到屏幕。亚军#!/usr/bin/envrubyprint"Enteryourpassword:"password=gets.chompputs"Hereisyourpassword:#{password}"我运行的脚本文件:开始.rboutput=`runner`putsoutput.match(/Hereisyour(password:.*)/).captures[0].to_s正如您在此处看到的那样,存在问题。在start.rb的第一行,屏幕是空的。我在运行程序中看不到“输入您的密

  7. ruby - 是否有将图像文件转换为 ASCII 艺术的命令行程序或库? - 2

    有这样的事吗?我想在Ruby程序中使用它。 最佳答案 试试这个http://csl.sublevel3.org/jp2a/此外,Imagemagick可能还有一些东西 关于ruby-是否有将图像文件转换为ASCII艺术的命令行程序或库?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/6510445/

  8. ruby - 在 Ruby 的 if 语句中检查 bash 命令 - 2

    如何在Ruby的if语句中检查bash命令的返回值(true/false)。我想要这样的东西,if("/usr/bin/fswscell>/dev/null2>&1")has_afs="true"elsehas_afs="false"end它会提示以下错误含义,它总是返回true。(irb):5:warning:stringliteralincondition正确的语法是什么?更新:/usr/bin/fswscell寻找afs安装和运行状态。它会抛出这样的字符串,Thisworkstationbelongstocell如果afs没有运行,命令以状态1退出 最

  9. ruby - 可以正常中断的来自 Rake 的长时间运行的 shell 命令? - 2

    在几个项目中,我希望有一个类似rakeserver的rake任务,它将通过任何需要的方式开始为该应用程序提供服务。这是一个示例:task:serverdo%x{bundleexecrackup-p1234}end这行得通,但是当我准备停止它时,按Ctrl+c并没有正常关闭;它中断了Rake任务本身,它说rakeaborted!并给出堆栈跟踪。在某些情况下,我必须执行Ctrl+c两次。我可能可以用Signal.trap写一些东西来更优雅地中断它。有没有更简单的方法? 最佳答案 trap('SIGINT'){puts"Yourmessa

  10. ruby - Capistrano 中的执行、测试和捕获命令有什么区别? - 2

    关于SSHkit-Github它说:Allbackendssupporttheexecute(*args),test(*args)&capture(*args)来自SSHkit-Rubydoc,我明白execute实际上是test的别名?test之间有什么区别?,execute,capture在Capistrano/SSHKit中我应该什么时候使用? 最佳答案 执行只是执行命令。使用非0退出引发错误。测试方法的行为与execute完全相同,但是它返回bool值(true如果命令以0退出,而false否则)。它通常用于控制任务中的流程

随机推荐