Linux基础 (redhat 8.0)

Linux基础

bash常用操作

ctrl+a //跳到命令行首
ctrl+e //跳到命令行尾
ctrl+u //删除光标至命令行首的内容
ctrl+k //删除光标至命令行尾的内容
ctrl+l //清屏

history命令用法

-c //清空命令历史命令
-d OFFSET //删除指定位置的命令历史
-w //保存命令历史至历史文件~/.bash_history中
history使用技巧
!n //执行命令历史中第N条命令
! -n //执行命令历史中倒数第N条命令
!string //执行命令历史中最近一个以指定字符串开头的命令
!! //执行上一条命令
!$ //引用前一个命令的最后一个参数

设置别名
alias CMDALIAS=‘conmand [option] [arguments]’

[root@localhost ~]# alias vimens160='vim /etc/sysconfig/network-scripts/ifcfg-ens160'
[root@localhost ~]# vimens160

TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
NAME=ens160
UUID=cf3ccd2f-000d-41a5-b7d0-2507290de20d
DEVICE=ens160
ONBOOT=yes
IPADDR=192.168.72.5
NETMASK=255.255.255.0
GATEWAY=192.168.72.254
DNS1=114.114.114.114
PREFIX=24
IPV6INIT=no
~                                                        
~                                                        
~                                                        
~                                                        
~                                                        
~                                                        
~                                                        
~                                                        
~                                                        
~                                                        
<pts/ifcfg-ens160" 16L, 285C           11,19        全部

基础命令

ls

  • 输出目录内容
    文件类型
    • d //目录文件
    • b //块设备文件(block)
    • c //字符设备文件
    • l //符号链接文件
    • p //命令管道符
    • s //套接字文件

option选项
-h //做单位转换
-a //显示所有文件(包括隐藏文件)
-d //显示目录自身属性
-i //显示文件inode(index node)
-r //逆序显示
-R //递归显示

mkdir

  • 创建目录
    -p 递归创建目录
[root@localhost ~]# mkdir -p /root/wcl/wei
[root@localhost ~]# tree /root
/root
├── anaconda-ks.cfg
└── wcl
    └── wei

-v 显示创建目录的过程

[root@localhost ~]# mkdir -v /root/wcl
mkdir: 已创建目录 '/root/wcl'

tree

#查看目录数
-d //只显示目录

[root@localhost ~]# tree -d /etc/sysconfig
/etc/sysconfig
├── console
├── modules
├── network-scripts
└── rhn
    ├── allowed-actions
    │   ├── configfiles
    │   └── script
    └── clientCaps.d

-L //指定显示的层级数目

[root@localhost ~]# tree -L 2 /boot
/boot
├── config-4.18.0-147.el8.x86_64
├── efi
│   └── EFI
├── grub2
│   ├── device.map
│   ├── fonts
│   ├── grub.cfg
│   ├── grubenv
│   └── i386-pc
├── initramfs-0-rescue-02053c5f5846466a8ff0dbd13b0d9ac7.img
├── initramfs-4.18.0-147.el8.x86_64.img
├── initramfs-4.18.0-147.el8.x86_64kdump.img
├── loader
│   └── entries
├── System.map-4.18.0-147.el8.x86_64
├── vmlinuz-0-rescue-02053c5f5846466a8ff0dbd13b0d9ac7
└── vmlinuz-4.18.0-147.el8.x86_64

7 directories, 10 files

-P //只显示又指定pattern匹配到的路径

[root@localhost ~]# tree -P redhat /boot
/boot
├── efi
│   └── EFI
│       └── redhat
├── grub2
│   ├── fonts
│   └── i386-pc
└── loader
    └── entries

stat

#显示文件或文件系统的状态
-L //链接
-f //只显示文件系统不显示文件

[root@wcluser etc]# stat /etc/passwd
  文件:/etc/passwd
  大小:1715      	块:8          IO 块:4096   普通文件
设备:fd00h/64768d	Inode:16787404    硬链接:1
权限:(0644/-rw-r--r--)  Uid:( 1001/     fyj)   Gid:( 1001/     fyj)
环境:system_u:object_r:passwd_file_t:s0
最近访问:2020-08-04 03:01:01.743227962 -0400
最近更改:2020-08-04 03:00:13.176553067 -0400
最近改动:2020-08-04 03:00:13.230552703 -0400
创建时间:-
[root@wcluser etc]# stat -f /etc/passwd
  文件:"/etc/passwd"
    ID:fd0000000000 文件名长度:255     类型:xfs
块大小:4096       基本块大小:4096
    块:总计:4452864    空闲:3909199    可用:3909199
Inodes: 总计:8910848    空闲:8853540
[root@wcluser etc]# stat -L /etc/passwd
  文件:/etc/passwd
  大小:1715      	块:8          IO 块:4096   普通文件
设备:fd00h/64768d	Inode:16787404    硬链接:1
权限:(0644/-rw-r--r--)  Uid:( 1001/     fyj)   Gid:( 1001/     fyj)
环境:system_u:object_r:passwd_file_t:s0
最近访问:2020-08-04 03:01:01.743227962 -0400
最近更改:2020-08-04 03:00:13.176553067 -0400
最近改动:2020-08-04 03:00:13.230552703 -0400
创建时间:-

cp

  • 复制文件
    -a 归档复制,常用于备份
[root@localhost ~]# cp -a /etc/sysconfig/network-scripts/ifcfg-ens160 /root
[root@localhost ~]# ll
总用量 8
-rw-------. 1 root root 1308 7月  27 12:30 anaconda-ks.cfg
-rw-r--r--. 1 root root  285 7月  27 05:41 ifcfg-ens160
drwxr-xr-x. 3 root root   17 8月  23 03:26 wcl

-r 递归拷贝,拷贝目录时需添加次选项

[root@localhost ~]# cp -r /root/wcl/wei/* ./111/
[root@localhost ~]# tree /root/
/root/
├── 111
│   ├── abc
│   └── wei
├── anaconda-ks.cfg
└── wcl
    └── wei
        └── abc

4 directories, 3 files

-p 拷贝时保留原来的权限

install

  • 复制文件并设置属性
    -m MODE
[root@wcluser ~]# install -m 755 /root/passwd /root/share/
[root@wcluser ~]# cd share/
[root@wcluser share]# ll
-rwxr-xr-x  1 root root 1837 8月   7 21:20 passwd

-o owner

[root@wcluser ~]# ll
-rw-r--r--  1 1001 1001 1837 8月   7 21:05 passwd
[root@wcluser ~]# install -o fyj /root/passwd /root/share/
[root@wcluser ~]# ll /root/share/
-rwxr-xr-x  1 fyj root 1837 8月   7 21:22 passwd

-g GROUP

[root@wcluser ~]# tail -2 /etc/group
wcl:x:205:
nginx:x:204:
[root@wcluser ~]# install -g wcl /root/passwd /root/share/
[root@wcluser ~]# ll /root/share/
-rwxr-xr-x  1 root wcl  1837 8月   7 21:26 passwd

通配符

?:表示单个字符
例:

[root@localhost ~]# ls w??
wcl

*: 表示任意长度的任意字符
例:

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

\ :转义字符;只显示目标本身,去除特殊意义

[[:space:]] :单个空格
[[:upper:]] :单个大写字母
[[:lower:]] :单个小写字母
[[:digit:]] :个位数数字文件名;0-9
[[:alnum:]] : 单个大写字母或数字
[[:alpha:]] :单个大写字母、小写字母或数字
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值