renhat8文件基础命令笔记

一.访问控制行

Shell:命令的解释器(将用户输入的指令翻译成内核可以理解的命令)

CLI:Command Line Interface (命令行,有shell)

 

Unix/Linux中的shell:bash、sh、ksh、csh、zsh

Windows中的shell:cmd.exe、powershell

 

当前系统支持的shell:

[root@localhost ~]# ll /etc/shells

-rw-r--r--. 1 root root 44 Sep 10  2018 /etc/shells

 

root@localhost ~]# file /etc/shells

/etc/shells: ASCII text

 

[root@localhost ~]# more /etc/shells

/bin/sh

/bin/bash

/usr/bin/sh

/usr/bin/bash

 

查看系统默认的shell:

[root@localhost ~]# echo $SHELL

/bin/bash

 

bash(GNU Bourne-Again Shell)

 

交互式shell:shell等待用户输入      ##shell与用户进行交互

非交互式shell:shell不直接和用户交互

 

Shell提示符:

普通用户执行shell 默认提示服务结尾是$

超级用户执行shell 默认提示服务结尾为#

 

Shell提示符输入的指令包括三个部分:

Command [option] [argument]

command:运行的程序的名称

option:用于调整程序行为的选项,使用-或--开头

argument:作为程序的目标参数

 

登录到本地计算机(方法):

  1. 物理控制台:物理控制台支持多个虚拟的控制台 Ctrl+alt+f1+f6切换
  2. 网络登录:通过IP地址或者主机名来进行登录

(主机名:1.DNS将host解析成IP地址

2本地/etc/hosts文件将主机名解析成IP地址

  1. 保证链路连通性)

 

服务器地址:

ip addr 获取服务器的IP地址

[root@localhost ~]# systemctl is-active sshd.service

Active

 

CRT远程登陆:

setenforce 0

systemctl restart sshd

vim /etc/ssh/sshd——config      

 

 

退出:exit

 

GUI

RHEL7/RHEl8使用Gnome3提供桌面环境

图形用户界面:Grahpical User Interface

Linux GUI shell:window Manger、CDE、KDE、SFCe等

 

使用bash执行命令

基本命令的语法:Command [option] [argument]

 

内部命令:shell内置

[root@localhost ~]# type cd

cd is a shell builtin

外部命令:在文件系统中某个路径下可执行的文件

[root@localhost ~]# type date

date is /usr/bin/date

 

简单命令实例

Date:显示当前日期和时间,root用户设置系统时钟

[root@localhost ~]# date

Tue May 26 01:17:16 PDT 2020

 

[root@localhost ~]# date –help

 

(1)date

使用date显示日期的时间格式为2020-05-26

[root@localhost ~]# date +%Y-%m-%d

2020-05-26

 

练习:使用date显示日期格式为2020-05-26 01:30:56

[root@localhost ~]# date "+%Y-%m-%d %H:%M:%S"

2020-05-26 01:30:56

 

(2)passwd:用来修改自己的密码,root用户可以更改其他用户的密码

 

(3)file 显示文件的类型    linux不需要文件的扩展名分类文件

[root@localhost ~]# file /etc/passwd

/etc/passwd: ASCII text

 

 

[root@localhost ~]# ll  /bin/passwd

-rwsr-xr-x. 1 root root 34512 Aug 12  2018 /bin/passwd

PS

开头是-为普通文件

开头是d是目录

开头是c是字符文件

开头是b是块设备文件

开头是l是符号链接文件

开头是p是管道文件

开头是s是套接字文件

 

查看文本内容:

Cat

[root@localhost ~]# cat anaconda-ks.cfg

##一次性看完文件所有内容(用于比较少的文件)

 

[root@localhost ~]# cat anaconda-ks.cfg original-ks.cfg

##可以几个文件内容一起看

 

More

[root@localhost ~]# more anaconda-ks.cfg

##从头向后查看,回车、空格 分屏显示

PS

空格   向下翻页

回车    向下滚动一行

Q       退出

Less

[root@localhost ~]# less anaconda-ks.cfg

可以从头向后查看,也可以从后往前看  支持查找

PS

空格   向下翻页

回车    向下滚动一行

b       向前翻一页

y       向前滚动一行

查找      /***(向下查找)   或者  ?***(向上查找)

n/N         重复前一个搜索功能/反向搜索

 

head:

显示文件的前十行(默认)

[root@localhost ~]# head -n 5 anaconda-ks.cfg

##显示文件前五行(可选)

 

Tail

[root@localhost ~]# tail – n 5 anaconda-ks.cfg

##显示后五行(默认10行)

 

 

Wc:显示文件行数/字符数量

[root@localhost ~]# wc -cml anaconda-ks.cfg

  95 2640 2640 anaconda-ks.cfg

[root@localhost ~]# wc -c anaconda-ks.cfg

2640 anaconda-ks.cfg

[root@localhost ~]# wc -m anaconda-ks.cfg

2640 anaconda-ks.cfg

[root@localhost ~]# wc -l anaconda-ks.cfg

95 anaconda-ks.cfg

 

 

 

命令补全:

Tab补全在提示符输入足够的唯一的内容快速补全文件名

 

命令补全:在path环境变量中所指定的路径下进行搜索(包括选项)

路径补全:搜索给定起始路径的么每个文件名

 

[root@localhost ~]# head -n\

> 5 anaconda-ks.cfg

 

 

命令历史:

History:显示之前执行的命令的列表

!(number/数字):执行命令历史记录中第n条命令

!string:运行命令历史记录中最近一个以指定string字符串开头的命令

        支持上下方向键 显示在命令历史记录中的命令

 

 

 

命令行快捷键:

支持左右方向键、backspace

Ctrl+a  跳到行首

Ctrl+e  跳到行尾

Ctrl+d  删除光标所在的字符

Ctrl+h  删除光标前的一个字符

Ctrl+u  删除光标至命令行首的内容(不包括光标处)

Ctrl+k  删除光标至命令行尾的内容(包括光标处)

Ctrl+左右方向键

 

 

 

 

使用shell扩展匹配文件名:

模式匹配

文件名通配:globbing

元字符:

*:0或者多个任意字符

?:任意一个字符

[abc…]   匹配括号中的任意一个字符

[!abc…][^abc…]   不匹配括号中的任意一个字符

[[:alpha:]]   匹配任意的字符

[[:lower]]   匹配任意小写字母

[[:upper]]   匹配任意大写字母

[[:digit]]   匹配任意0-9数字

[[:alnum]]   匹配任意的字符和数字

 

例:

[root@localhost var]# ls /var/l?[[:lower:]]

[root@localhost var]# ls -l /etc/[0-9]*[^0-9]

[root@localhost var]# ls -l /etc/[[:digit:]]*[^0-9]

 

~:匹配当前用户家目录

[root@localhost var]# cd ~

[root@localhost ~]#  ls ~/anaconda-ks.cfg

/root/anaconda-ks.cfg

[root@localhost ~]# cd ~student(切换到用户)、

 

 

 

mkdir/ls-l dir[abc]

{aa,bb,cc}

{a..z}

 

 

命令替换:

允许命令的输出替换命令的本身

$(command)或者$’comand’

 

[root@localhost ~]# echo "hello world"

hello world

[root@localhost ~]# echo "today is date"

today is date

 

[root@localhost ~]# echo "today is $(date)"

today is Mon Jun  1 19:11:19 PDT 2020

 

PS:

单引号 强引用

双引号  弱引用

 

[root@localhost ~]# echo this $PWD

this /root

 

[root@localhost ~]# echo 'this $PWD'

this $PWD

 

 

通配

 

 

在红帽中获取帮助:

--help:获取命令的选项

 

man:

[root@localhost ~]# man passwd

PS:1,5,8章节关注

 

 

PASSWD(1)    章节

NAME   名字解释

SYNOPSIS   语法概要

DESCRIPTION   描述

FILES  命令相关的文件在那个地方

OPTIONS   选项解释

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------

                                                                                                                                             记录每一天的学习生活!!!!!

 

 

 

 

 

 

 

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值