系统学习-----Linux文件以及Bash的功能特性

Linux文件系统介绍

系统文件路径:

示例:
Window:C:\Users\Zhaohao\Desktop
Linux: /etc/sysconfig/network-scripts/

绝对路径: 从/位置开始(从根位置开始)
相对路径:从.位置开始 (从当前位置开始)
表示方式:
/sysconfig/network-scripts/ -> 绝对路径
./network-scripts/ -> 相对路径
network-scripts/ -> 相对路径
…/ -> 相对路径 ( …代表从上一个目录作为当前目录)

文件是由 Metadata 和 data 组成的

Metadata:元数据:描述文件属性等信息
data:文件本身的信息

文件名称的命名规则:

  1. 严格区分大小写
  2. 可以使用除 “/” 以外的任意字符,但是要避免使用一些特殊字符( . * ?),有特殊含义。
  3. 不超过255个字符
  4. 以 . 开头的文件为隐藏文件

命令的使用规则

<command> [options] [obj]
	
options: 
	长选项	-- ()
	短选项	-  短选项可以组合使用(-aild)
	
	一般来说: 短选项的使用放在长选项之前 

obj  肯定是文件 

注意: 命令、选项和文件之间要有空格

ls命令

[root@localhost ~]# ls --help

OPTIONS:
-a : 显示所有文件(包括隐藏文件)
-l :显示列表中文件的详细信息
-i : 显示文件的inode号
-d :查看目录文件的信息

pwd命令

显示当前路径

[root@test tmp]# pwd
/tmp

cd命令

切换目录
cd命令默认是切换到各自的家目录下:/root/

[root@test ~]# cd test/
[root@test test]# cd 
[root@test ~]# cd ./test/
[root@test test]# cd

[root@test test2]# pwd
/root/test/test2
[root@test test2]# cd ..	# 返回上层目录
[root@test test]# ls
test2

[root@test test2]# cd - 	# 返回上次所在的目录 

文件类型

  • 普通文件 [-]
  • 目录文件 [d]
  • 块设备文件 [b]
  • 字符设备文件 [c]
  • 套接字文件 [s]
  • 管道文件 [p]
  • 链接文件 [l]

如何去查看文件类型:

  1. ls -l 命令 (ll)
[root@test ~]# ll 
total 4
-rw-------. 1 root root 1260 Feb  5  2020 anaconda-ks.cfg
drwxr-xr-x. 3 root root   19 Feb  5 06:57 test
[root@test ~]# ll /dev/sda
brw-rw----. 1 root disk 8, 0 Feb  5  2020 /dev/sda
[root@test ~]# ll /dev/zero 
crw-rw-rw-. 1 root root 1, 5 Feb  5  2020 /dev/zero
[root@test ~]# ll /var/spool/postfix/public/showq 
srw-rw-rw-. 1 postfix postfix 0 Feb  5  2020 /var/spool/postfix/public/showq
[root@test ~]# ll /run/dmeventd-client 
prw-------. 1 root root 0 Feb  5  2020 /run/dmeventd-client
  1. file命令
[root@test ~]# file test/
test/: directory
[root@test ~]# file anaconda-ks.cfg 
anaconda-ks.cfg: ASCII text
  1. stat命令
[root@test ~]# stat anaconda-ks.cfg 
  File: ‘anaconda-ks.cfg’
  Size: 1260      	Blocks: 8          IO Block: 4096   regular file
	

[root@test ~]# stat test/
  File: ‘test/’
  Size: 19        	Blocks: 0          IO Block: 4096   directory

目录结构

注意:介绍/下的第1级目录

bin: Binary缩写; 存放着经常使用的命令
boot: 启动Linux需要的部分核心文件
dev: Device缩写; Linux外部设备(磁盘等)
etc: 系统管理所需要的配置文件和子目录
home: 用户的家目录
lib: 程序运行时所依赖的库文件(包括内核模块)
lib64: 专用于x86_64系统上的辅助共享库文件存放位置
media: 自动识别的设备存放位置
mnt: 用户临时挂载别的文件系统
opt: 安装额外软件的存放位置
proc: 虚拟目录;访问该目录可以获取系统相关信息
root: 超级管理员家目录
run: 存储系统运行以来的所有信息
sbin: 超级管理员所使用的命令
srv: 服务启动后需要的数据
sys:子文件系统;映射内核信息 (针对内核做调整的话)
tmp: 临时文件目录
usr: 用户的应用程序和相关文件
var: 经常被修改的文件存储位置(日志: /var/log/…)

Bash的基础特性

在这里插入图片描述
用户空间: 命令全部在用户空间交由给Shell翻译后让内核进行执行并返回执行结果

命令相关

Shell程序找到输入命令所对应的执行程序或者代码,并由其分析之后提交给内核分配资源
运行起来之后,将表现为一个或者多个进程

进程:正在运行的程序

Shell中可执行的2类命令
内建命令:Shell自带

[root@test ~]# type cd
cd is a shell builtin

外部命令:某个文件系统路径下有相对应的可执行程序文件

[root@test ~]# type find
find is /usr/bin/find

相关命令:type/whereis/which等命令

[root@test ~]# whereis ls
ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz
[root@test ~]# whereis cd
cd: /usr/bin/cd /usr/share/man/man1/cd.1.gz
			
[root@test ~]# which ls
alias ls='ls --color=auto'
	/usr/bin/ls
[root@test ~]# which cd
/usr/bin/cd

命令格式

	<Command> <Options...> <obj/arguments...>
	
	Options: 长短选项
	arguments: 命令作用的对象/命令提供的数据

命令执行结果

失败(非0)或者成功(0)
echo $? : 判断上一条命令执行的结果

[root@test ~]# echo $?
0
[root@test ~]# cat/etc/sysconfig/network-scripts/ifcfg-ens32 
-bash: cat/etc/sysconfig/network-scripts/ifcfg-ens32: No such file or directory
[root@test ~]# echo $?
127

注意:
多个选项及参数之间使用空格字符分割,短选项可以合写
取消命令的执行: Ctrl + c

命令历史

查看命令历史: history命令
历史命令文件: ~/.bash_history  上一次shell所保留的命令
登录shell时会读取历史命令文件,并将后续的操作命令添加到历史命令文件中

history命令相关参数:
	-a : 追加本地会话执行的命令历史列表到历史文件当中
	-d : 删除历史中指定的命令
		[root@test ~]# history -d 28 (命令历史ID)
	-c :清空历史命令
		[root@test ~]# history -c 

快捷操作:
	!# 调用历史列表中的第#条命令
	!string 调用历史列表中最近一条以string开头的命令
	!! 调用的是上一条命令

路径补全

Tab键进行路径补全操作,所输入的路径必须要唯一
double Tab键 输出所有符合补全条件的选项

[root@test ~]# cd /etc/sysc
sysconfig/   sysctl.conf  sysctl.d/  

别名

查看别名: alias
定义别名: alias [name]=[value]
alias ll=‘ls -l --color=auto’

[root@test ~]# alias pingdu='ping www.baidu.com'
[root@test ~]# pingdu

取消别名: unalias [name]

---- 对当前会话有效

如果想要对当前用户生效: 需要将别名的定义写入~/.bashrc配置文件中,并让其生效
使其生效的方式:
立即生效: source .bashrc

发布了21 篇原创文章 · 获赞 3 · 访问量 973

猜你喜欢

转载自blog.csdn.net/weixin_46097280/article/details/104201033