linux的bash命令 linux中bash的用法-古蔺大橙子建站
RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
linux的bash命令 linux中bash的用法

linux的bash命令,sed-i怎么写入变量

在Linux的Bash命令中使用sed-i写入变量可以使用以下语法:sed -i "s/替换字符串/${你的变量名}/g" 文件名 例如,要将变量CONTENT写入文件file.txt: sed -i "s/Content/${CONTENT}/g" file.txt

让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:主机域名、网络空间、营销软件、网站建设、积石山保安族东乡族网站维护、网站推广。

在Linux的Bash命令中使用sed-i写入变量可以使用以下语法:sed -i "s/替换字符串/${你的变量名}/g" 文件名 例如,要将变量CONTENT写入文件file.txt: sed -i "s/Content/${CONTENT}/g" file.txt

Linux里面bash是什么?

Bash,Unix

shell的一种,在1987年由布莱恩·福克斯为了GNU计划而编写。1989年发布第一个正式版本,原先是计划用在GNU操作系统上,但能运行于大多数类Unix系统的操作系统之上,包括Linux与Mac

OS X v10.4都将它作为默认shell。

Bash是一个命令处理器,通常运行于文本窗口中,并能执行用户直接输入的命令。Bash还能从文件中读取命令,这样的文件称为脚本。和其他Unix

shell

一样,它支持文件名替换(通配符匹配)、管道、here文档、命令替换、变量,以及条件判断和循环遍历的结构控制语句。包括关键字、语法在内的基本特性全部是从sh借鉴过来的。其他特性,例如历史命令,是从csh和ksh借鉴而来。总的来说,Bash虽然是一个满足POSIX规范的shell,但有很多扩展。

Linux系统入门-Bash

Shell 是一种命令行解释器, 其读取用户输入的字符串命令, 解释并且执行命令;它是一种特殊的应用程序, 介于系统调用/库与应用程序之间, 其提供了运行其他程序的的接口;它可以是交互式的, 即读取用户输入的字符串;也可以是非交互式的, 即读取脚本文件并解释执行, 直至文件结束. 无论是在类 UNIX, Linux 系统, 还是 Windows, 有很多不同种类的 Shell: 如类 UNIX, Linux 系统上的 Bash, Zsh 等; Windows 系统上的 cmd, PowerShell 等.

Bash 是 Bourne Again SHell 的缩写, 是 GNU 计划中的 Shell, 也是一些类 UNIX 系统与多数 Linux 发行版的默认 Shell

使用Shell可以实现对Linux系统实现绝大部分的管理,例如:

#获取当前时间

[root@CentOS7 ~]# date

Mon Mar 15 22:59:47 CST 2021

#创建文件

[root@CentOS7 opt]# touch xcz

[root@CentOS7 opt]# ll

-rw-r--r--. 1 root root 0 Mar 15 23:01 xcz

#创建一百个文件,我们一般就会使用shell script进行创建

[root@CentOS7 opt]# cat touch.sh

#!/bin/bash

for n in `seq 100`;do

touch xcz$n

echo "文件xcz$n创建成功哦!"

done

[root@CentOS7 opt]# sh touch.sh

命令行输入方式:效率较低,适用于工作量不大的工作;

shell script 脚本方式:效率高,适用于工作量大且复杂的工作。

[root@CentOS7 opt]# bash --version

GNU bash, version 4.2.46(2)-release (x86_64-redhat-linux-gnu)

Copyright (C) 2011 Free Software Foundation, Inc.

License GPLv3+: GNU GPL version 3 or later

This is free software; you are free to change and redistribute it.

There is NO WARRANTY, to the extent permitted by law.

'#39; = 普通用户

'#' = root用户(超级管理员)

#查看当前用户

[root@CentOS7 ~]# whoami

root

#查看当前命令提示符

[root@CentOS7 ~]# echo $PS1

[u@h W]$

root:当前系统的用户

CentOS7:当前系统的主机名

~:当前所在的位置

#:超级管理员身份(root用户)

$:普通用户

提示符参数及含义

d :代表日期;

H :完整的主机名称

h :仅取主机名中的第一个名字

:显示时间为24小时格式,如:HH:MM:SS

T :显示时间为12小时格式

A :显示时间为24小时格式:HH:MM

u :当前用户的账号名称

v :BASH的版本信息

w :完整的工作目录名称

W :利用basename取得工作目录名称,只显示最后一个目录名

# :下达的第几个命令

$ :提示字符,如果是root用户,提示符为 "#" ,普通用户则为 "#34;

#颜色

30 40 黑色

31 41 红色

32 42 绿色

33 43 黄色

34 44 蓝色

35 45 紫红色

36 46 青蓝色

37 47 白色

PS1='[e[32;40m] [[u@h w ]$ [e[0m]'

PS1="[e[37;40m][[e[32;40m]u[e[37;40m]@h [e[36;40m]w[e[0m]]$ "

PS1="[e[37;40m][[e[32;40m]u[e[37;40m]@[e[35;40m]h[e[0m] [e[36;40m]w[e[0m]]$ "

#提示符的应用

[root@CentOS7 ~]# vi .bashrc

#最后一行下面添加

PS1="[e[37;40m][[e[32;40m]u[e[37;40m]@[e[35;40m]h[e[0m] [e[36;40m]w[e[0m]]$ "

#使用source生效

[root@CentOS7 ~]# source .bashrc

#命令 选项 参数

command [-options] [arguments]

[root@CentOS7 ~]# ls -l /opt/

#命令:整条shell命令的主体

#选项:用于调节命令的具体功能

#以'-'引导段个事选项(单个字符),例如”-l“

#以'--'引导长格式选项(多个字符),例如”--list“

#多个短格式选项可以卸载一起,只用一个”-“引导,例如”-la“

#参数:命令操作与偶的对象,如文件、目录名等

#命令必须开头,选项和参数位置可以发生变化

我们在使用Linux系统进行查找一个多层级的文件时,我们可以使用键盘上的Tab键进行快速补全

补全的形式有:

#如果我们忘记网络配置文件具体路径,那么我们就可以使用补全的形式进行配置

[root@CentOS7 ~]# vi /etc/sysconfig/

anaconda cpupower grub irqbalance modules/ rdisc selinux

authconfig crond init kdump netconsole readonly-root sshd

cbq/ ebtables-config ip6tables-config kernel network rsyslog wpa_supplicant

console/ firewalld iptables-config man-db network-scripts/ run-parts

[root@CentOS7 ~]# vi /etc/sysconfig/network

network network-scripts/

[root@CentOS7 ~]# vi /etc/sysconfig/network-scripts/if

ifcfg-ens33 ifdown-eth ifdown-post ifdown-Team ifup-aliases ifup-ipv6 ifup-post ifup-Team

ifcfg-lo ifdown-ippp ifdown-ppp ifdown-TeamPort ifup-bnep ifup-isdn ifup-ppp ifup-TeamPort

ifdown ifdown-ipv6 ifdown-routes ifdown-tunnel ifup-eth ifup-plip ifup-routes ifup-tunnel

ifdown-bnep ifdown-isdn ifdown-sit ifup ifup-ippp ifup-plusb ifup-sit ifup-wireless

[root@CentOS7 ~]# vi /etc/sysconfig/network-scripts/ifcfg-

ifcfg-ens33 ifcfg-lo

[root@CentOS7 ~]# vi /etc/sysconfig/network-scripts/ifcfg-ens33

#如果你的Linux系统无法进行补全,那么咱们可以安装一个扩展包即可

[root@CentOS7 ~]# yum install -y bash-completion

clear #或者用快捷键 ctrl + l

ctrl+c #有些程序也可以用q键退出

ctrl+z # 进程会挂起到后台

bg jobid # 让进程在后台继续执行

fg jobid # 让进程回到前台

Ctrl键+a #将当前光标移动到命令行的行首

Ctrl键+e #将当前光标移动到命令行的行尾

Ctrl键+u #将当前光标之前的所有字符剪切

Ctrl键+k #将当前光标之后的所有字符剪切

Ctrl键+w #将当前光标之前的字符剪切,以空格为结尾

Ctrl键+d #退出当前会话窗口

Ctrl键+z #将当前前台运行的程序,放到后台运行

Ctrl键+r #搜索 历史 命令

Ctrl键+y #粘贴剪切板上的内容

Ctrl键+左右方向键 #向指定的方向键移动一组字符,以空格为分隔符

ESC键+. #使用上一条命令的最后的参数或者路径,以空格为分隔符,空格之后的内容,delete键 从前往后删除一个字符

!命令 #执行最近的一次以该命令为开头的命令

!! #执行上一条命令

#使用格式:

[命令] + [--help] 或者[man] + [命令] 即可

#例如touch命令帮助

[root@CentOS7 ~]# touch --help

Usage: touch [OPTION]... FILE...

Update the access and modification times of each FILE to the current time.

A FILE argument that does not exist is created empty, unless -c or -h

is supplied.

A FILE argument string of - is handled specially and causes touch to

change the times of the file associated with standard output.

Mandatory arguments to long options are mandatory for short options too.

-a change only the access time

-c, --no-create do not create any files

-d, --date=STRING parse STRING and use it instead of current time

-f (ignored)

-h, --no-dereference affect each symbolic link instead of any referenced

file (useful only on systems that can change the

timestamps of a symlink)

-m change only the modification time

-r, --reference=FILE use this file's times instead of current time

-t STAMP use [[CC]YY]MMDDhhmm[.ss] instead of current time

--time=WORD change the specified time:

WORD is access, atime, or use: equivalent to -a

WORD is modify or mtime: equivalent to -m

--help display this help and exit

--version output version information and exit

Note that the -d and -t options accept different time-date formats.

GNU coreutils online help:

For complete documentation, run: info coreutils 'touch invocation'


分享标题:linux的bash命令 linux中bash的用法
文章链接:http://scgulin.cn/article/ddgeejc.html