
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 softwareyou 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[3240m] [[u@h w ]$ [e[0m]'
PS1="[e[3740m][[e[3240m]u[e[3740m]@h [e[3640m]w[e[0m]]$ "
PS1="[e[3740m][[e[3240m]u[e[3740m]@[e[3540m]h[e[0m] [e[3640m]w[e[0m]]$ "
#提示符的应用
[root@CentOS7 ~]# vi .bashrc
#最后一行下面添加
PS1="[e[3740m][[e[3240m]u[e[3740m]@[e[3540m]h[e[0m] [e[3640m]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'
ifcfg-l0 是本地回环接口,相当于 127.0.0.1ifcfg-eth0 本地网卡第一个接口需ROOT的权限配置如下:vim /etc/sysconfig/....按a 或 i 进入编辑IPADDR=192.168.0.1 ( 配置的IP ) NETMASK=255.255.255.0 (掩码)GATEWAY=192.168.0.254 ( 网关)DNS1=192.168.0.254(DNS):wq你是否是用root登陆的呢? 在VMwareWorkstation上,安装RHEL-Server-7.2后,使用ifconfig查看,只有lo网卡,进入/ect/sysconfig/network-scripts/目录发现只有ifcfg-lo;
step1:
关闭虚拟机,进入安装目录找到*.vxm文件,在最后一行添加: ethernet0.virtualDev = "e1000"
保存后,启动虚拟机,ifconfig查看,出现: ens33 网卡;
step2:
进入/ect/sysconfig/network-scripts/目录,还是只有ifcfg-lo,复制一份,修改名称为 ifcfg-ens33(注意,和实际查到的网卡名称一致) ;
修改内容如下:
ONBOOT=yes
USERCTL=no
PEERDNS=yes
TYPE=Ethernet
DEVICE=ens33
IPADDR=192.168.151.237
NETMASK=255.255.255.0
GATEWAY=192.168.151.1
HWADDR=00:0C:29:cd:23:24
其中,HWADDR的值,填写ifconfig查看的网卡的mac地址;
step3:
重启网卡服务 systemctl network.service restart
ifconfig查看,配置生效。
如果有图形界面,可以在设置中配置网卡地址,在 *** 作前是不可以的。
ヾ(◍°∇°◍)ノ゙
---------孙小黑 --------
O(∩_∩)O哈哈~
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)