首页 > 系统相关 >玩转Redhat Linux 8.0系列 | 使用BASH SHELL执行命令

玩转Redhat Linux 8.0系列 | 使用BASH SHELL执行命令

时间:2023-09-28 18:01:11浏览次数:27  
标签:8.0 sbin SHELL Redhat -- etc host passwd user

今天继续分享一些Redhat Linux 8.0的知识,记得关注,会一直更新~

基本命令语法

GNU Bourne-Again Shell (bash)这一程序可以解读用户键入的命令。

当您准备好执行命令时,请按Enter键。在单独的行上键入每个命令。系统会显示命令输出,然后显示下一shell提示符。

[user@host]$ whoami 
user
[user@host]$

以下示例演示了如何在命令行中组合两个命令(command1和command2)。

[user@host]$ command1;command2

简单命令示例

date 命令可显示当前的日期和时间。超级用户也可以用它来设置系统时钟。以加号(+)开头的参数可指定日期命令的格式字符串。

[user@host -]$ date
Sat Jan 26 08:13:50 IST 2019
[user@host -]$ date +%R
08:13
[user@host -]$ date +%x
01/26/2019

超级用户可以使用passwd 命令更改其他用户的密码。

[user@host -]$ passwd
Changing password for user user, current password: old_password New password: new_password
Retype new password: new_password
passwd: all authentication tokens updated successfully.

Linux不需要文件扩展名来根据类型分类文件。file命令可以扫描文件内容的开头,显示该文件的类型,要分类得文件作为参数传递至该命令

[user@host -]$ file /etc/passwd
/etc/passwd: ASCII text
[user@host -]$ file /bin/passwd
/bin/passwd: setuid ELF 64-bit LSB shared object, x86-64, version 1
(SYsv), dynamically linked, interpreter /lib64/1d-linux-x86-64.s0.2,
for GNU/Linux 3.2.0, BuildiD[sha1]=a3637110e27e9a48dced9f38b4ae43388d32d8e4, 
stripped
[user@host -]$ file /home
/home: directory

查看文件的内容

Linux中一个最简单且最常用的命令是cat。

以下示例演示了如何查看/etc/passwd文件的内容。

[user@host -]$ cat /etc/passwd 
root:x:0:0:root:/root:/bin/bash 
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin
...output omitted...

使用以下命令来显示多个文件的内容。

[user@host -]$ cat file1 file2 
Hello World!!
Introduction to Linux commands.

head和tail命令分别显示文件的开头和结尾部分。

[userghost -]$ head /etc/passwd 
root:x:0:8:root:/root:/
bin/bash bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin 
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:1p:/var/spool/1pd:/sbin/nologin 
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown 
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin 
operator:x:11:0:operator:/root:/sbin/nologin
[user@host -]$ tail -n 3 /etc/passwd 
gdm:x:42:42::/var/lib/gdm:/sbin/nologin
gnome-initial-setup:x:977:977::/run/gnome-initial-setup/:/sbin/nologin 
avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin

wc命令可计算文件中行、字和字符的数量。

[user@host -]$ wc /etc/passwd
45102 2480/etc/passwd
[user@host -]$ wc -1 /etc/passwd ; wc -1 /etc/group
45 /etc/passwd
70 /etc/group
[user@host -]$ wc -c /etc/group /etc/hosts
966 /etc/group
516 /etc/hosts
1482 total

TAB补全

Tab补全允许用户在提示符下键入足够的内容以使其唯一后快速补全命令或文件名。

[user@host -]$ pasOTab+Tab
passwd  paste  pasuspender  
[user@host -]$ passTab
[user@host ~]$ passwd
Changing password for user user. 
current password:

①按Tab键两次。

②按Tab键一次。

Tab补全可以用于在键入文件名作为命令的参数时将它们补全。

[user@host -]$ ls /etc/pasOTab
[user@host -]$ 1s /etc/passwdOTab
passwd  passwd-

①②按Tab键一次。

useradd 命令供超级用户root在系统上创建其他用户。

[root@host -]# useradd -.OTab+Tab
--base-dir  --groups  --no-log-init  --shell  
--comment  --help  --non-unique  --skel  
--create-home  --home-dir  --no-user-group  --system  
--defaults  --inactive  --password  --uid  
--expiredate  --key  --root  --user-group  
--gid  --no-create-home --selinux-user  
[root@host ~]# useradd --

①按Tab键两次。

命令历史记录

history命令显示之前执行的命令的列表,带有命令编号作为前缀。

感叹号字符(!) 是元字符,用于扩展之前的命令而不必重新键入它们。!number命令扩展至与指定编号匹配的命令。!string命令扩展至最近一个以指定字符串开头的命令。

[user@host -]$ history
...output omitted...
23 clear
24 who
25 pwd
26 ls /etc
27 uptime
28 ls -1
29 date
30 history[user@host -]$ !ls 
ls -1 
total 0
drwxr-xr-x. 2 user user 6 Mar 29 21:16 Desktop
...output omitted...
[user@host -]$ !26
1s /etc
abrt    hosts  pulse
adjtime  hosts,allow  purple  
aliases  hosts,deny  qemu-ga  
...output omitted...

编辑命令行

以交互方式使用时,bash具有命令行编辑功能。下表介绍了更为强大的编辑命令。

命令行编辑实用快捷键

快捷键

描述

ctr1+A

跳到命令行的开头。

ctr1+E

跳到命令行的末尾。

ctr1+U

将光标处到命令行开头的内容清除。

ctr1+K

将光标处到命令行末尾的内容清除。

ctrl+向左箭头

跳到命令行中前一字的开头。

ctrl+向右箭头

跳到命令行中下一字的末尾。

ctr1+R

在历史记录列表中搜索某一模式的命令。

还有其他几个命令行编辑命令可用,但这些是对新用户最有用的命令。

带你玩转Redhat Linux 8.0

想了解 新技术 9.0

想获取完整的电子档

可留言获取

想了解更多网工知识,获取《网工大礼包》,可关注公众号:IT运维大本营

标签:8.0,sbin,SHELL,Redhat,--,etc,host,passwd,user
From: https://blog.51cto.com/atomguo/7641435

相关文章

  • [Linux] shell文本处理记录 - 查找、增删特定行及附近行
    转:https://blog.csdn.net/wy_hhxx/article/details/127416595查找username所在行并删除此行,输出到新文件sed'/username/,+d'04filename.log>04filename_new.log 目录1.grep查找关键字所在行号、查找关键字前后行2.sed删除指定行及其前后若干行3.sed在匹配行前或后添......
  • k8s 版本升级1.18.0>>>1.18.20
    1.1升级步骤注意kubectl命令主节点执行,yum命令需要升级的服务器执行;查看当前系统支持的所有k8s版本和当前版本yumlist--showduplicateskubeadm--disableexcludes=kubernetes2.1.1升级控制节点1、查看当前版本和升级计划(即可以从目前版本升级到哪个版本)kubectlversion#匹配......
  • Powershell 获取AD Certificate 详细信息
    get-aduser-SearchBase$ou-Filter*-Propertiesdisplayname,usercertificate|ForEach-Object{$displayname=$_.displayname$_|select-ExpandPropertyusercertificate|ForEach-Object{$cert=[System.Security.Cryptography.X509Certifi......
  • shell遍历比较文件夹下文件md5值
    #!/bin/bashCURRENT_DIR=$(cd$(dirname$0);pwd)SOURCE_DIR="$CURRENT_DIR/python_data"TARGET_DIR="$CURRENT_DIR/out_bin"cd$SOURCE_DIR>python.md5forfilein$(ls$SOURCE_DIR|grep"data")dosource_file=${SOURCE_......
  • 掌握Shell用户管理,让你的系统运行更顺畅!
    用户帐号帐号操作主要是增、删、改、禁。Linux系统提供了底层的 useradd, userdel 和 usermod 来完成相关操作,也提供了进一步的简化封装:adduser, deluser。为了避免混淆,咱们这里只介绍最底层的指令,这些指令设计上已经够简洁明了方便。由于只有系统管理员才能创建新用户,请确......
  • How to add a string that contains whitespace to array in shell script All In One
    HowtoaddastringthatcontainswhitespacetoarrayinshellscriptAllInOneIhavetriedsomewaystoaddastringwhichcontainwhitespacetoarrayinshellscript,butfailed.stringvariablesconcatenate#!/usr/bin/envbashstr1="hello&qu......
  • linux-Shell将命令行终端输出结果写入保存到文件中
    (一)将输出与错误写到同一个文件(1)方法1#!bin/bashjava-jarhbase-example.jar2>&1|teehbase_log.txt说明:0,1,2:在linux分别表示标准输入、标准输出和标准错误信息输出。tee默认为写入覆盖,-a参数表示追加内容。#!bin/bashjava-jarhbase-example.jar2>&1|tee-ahbase_......
  • Linux shell编程学习笔记1:关于shell的前世今生
    一、什么是Shell?Shell英文单词的原意是“外壳”,在计算机领域专指在操作系统(OperatingSystem)外层,提供用户界面(UserInterface)的程序,主要负责将用户的命令(Command)转化为操作系统可识别的指令(Instruction)。二、UnixshellUnix诞生于1969年,是最早提供shell,从而将操作系统和用户界面......
  • 乌班图18.04安装.net 6.0
    乌班图18.04安装.net6.0wgethttps://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb-Opackages-microsoft-prod.debsudodpkg-ipackages-microsoft-prod.debsudoapt-getinstallapt-transport-httpssudoapt-getupdatesudoapt-getin......
  • Linux系统之安装MySQL8.0版本
    一、MySQL介绍1.1MySQL简介MySQL8.0是最新版本的MySQL数据库管理系统,是一种关系型数据库管理系统,由Oracle公司开发和维护。MySQL8.0带来了一系列新特性,包括多个性能提升,更好的安全性和扩展性,以及新的管理功能。1.2MySQL特点更好的性能:MySQL8.0提供了对于大型查......