centos7的目录结构,文件系统常用的命令,vim编辑器

centos7的目录结构(linux所有的都是文件)

bin  ---- 命令,二进制文件的存放目录
boot ----- 系统引导程序+系统的内核 
dev   ---- 设备 硬盘,光驱
etc   ---- 存储系统或者服务的配置文件
home  ---- 普通用的家目录
lib  ----- 库文件存放目录
lib64 ---- 库文件的存放目录(64位系统)
media ---- linux识别的设备,比如u盘等,挂这个目录
mnt  ----- 临时的挂载点目录
opt  ----- 第三方的软件安装在整理
proc ----- 虚拟目录,显示内存中的信息(进场,内核的信息)
root -----  root的家目录 
run  -----  放的启动的东西
sbin  ---  超级命令,只用root用户才能用的命令
srv   ----- service的缩写,存放的是一些启动后需要的数据
sys  ------ 虚拟目录,内存信息
tmp  ----- 临时文件的存放位置
usr ---- 存放用户的程序
var ----- 存放经常变化的文件,比如日志等

文件系统常用的命令

1.pwd 显示当前所在的路径
解释: pwd= print working directory 显示当前所在的目录
[root@localhost ~]# pwd
/root

2.cd切换目录结构
cd = change directory 改变目录信息
/目录	表示绝对路径	目录/	表示相当路径

#绝对路径的方式
[root@localhost ~]# cd /etc
[root@localhost etc]# pwd
/etc
[root@localhost etc]# cd /home
[root@localhost home]# pwd
/home
[root@localhost home]# 

# 相对路径的方式
[root@localhost home]# cd /etc
[root@localhost etc]# cd sysconfig/
[root@localhost sysconfig]# 

# 快速回到自己的家目录
三种方式:
cd ~
cd /root
cd

# 快速回到自己进过的目录
cd -

# 返回当前路径的上一级目录
../	返回一级
../../	返回两级
../../../../../../ 很多个是返回到根路径 /

3.mkdir创建目录信息
mkdir	= 	make directory

[root@localhost /]# cd /oldboy
-bash: cd: /oldboy: No such file or directory
[root@localhost /]# mkdir /oldboy
[root@localhost /]# cd /oldboy/
[root@localhost oldboy]# pwd
/oldboy

#用-p参数创建多级目录
[root@localhost oldboy]# mkdir /oldboy/olddog/jason
mkdir: cannot create directory ‘/oldboy/olddog/jason’: No such file or directory
[root@localhost oldboy]# mkdir /oldboy/olddog
[root@localhost oldboy]# mkdir /oldboy/olddog/jason
[root@localhost oldboy]# cd /oldboy/olddog/jason/
[root@localhost jason]# pwd
/oldboy/olddog/jason
[root@localhost jason]# cd /
[root@localhost /]# mkdir -p /oldboy/oldgirl/god
[root@localhost /]# cd /oldboy/oldgirl/god/
[root@localhost god]# pwd
/oldboy/oldgirl/god

#我们在创建目录的时候最好是用绝对路径
4.touch创建文件
#在linux里面不会通过后缀名来区分文件的类型,什么样的文件,就用什么后缀名,免得搞不清楚
[root@localhost tank]# cd /oldboy/
[root@localhost oldboy]# pwd
/oldboy
[root@localhost oldboy]# touch oldboy.txt
[root@localhost oldboy]# ls
oldboy.txt  olddog  oldgirl
[root@localhost oldboy]# touch /oldboy/olddog/jj
[root@localhost oldboy]# ls /oldboy/olddog/
jason  jj
5.ls检查文件或者文件目录是否存在,并且列出目录下面的文件
ls = list
ls检查文件或者文件目录是否存在
[root@localhost /]# cd godsee
[root@localhost godsee]# ls
god2.txt  god3.txt  godlover  god.txt
[root@localhost godsee]# ls god.txt
god.txt
[root@localhost godsee]#

[root@localhost godsee]# ls -l
total 12
-rw-r--r--. 1 root root 136 Mar 25 14:38 god2.txt
-rw-r--r--. 1 root root 143 Mar 25 14:39 god3.txt
drwxr-xr-x. 3 root root  18 Mar 25 14:18 godlover
-rw-r--r--. 1 root root   6 Mar 25 14:47 god.txt
[root@localhost godsee]# 

[root@localhost godsee]# ls -ltr
total 12
drwxr-xr-x. 3 root root  18 Mar 25 14:18 godlover
-rw-r--r--. 1 root root 136 Mar 25 14:38 god2.txt
-rw-r--r--. 1 root root 143 Mar 25 14:39 god3.txt
-rw-r--r--. 1 root root   6 Mar 25 14:47 god.txt
[root@localhost godsee]# 

[root@localhost godsee]# ls -lt
total 12
-rw-r--r--. 1 root root   6 Mar 25 14:47 god.txt
-rw-r--r--. 1 root root 143 Mar 25 14:39 god3.txt
-rw-r--r--. 1 root root 136 Mar 25 14:38 god2.txt
drwxr-xr-x. 3 root root  18 Mar 25 14:18 godlover
[root@localhost godsee]# 


# ls -l 默认是创建时间最新到最老排序(不确定,是按时间还是按照文件名排序)
# ls -lt 创建时间最新到最老排序
# ls -ltr 创建时间最老到最新排序

[root@localhost godsee]# ls -a
.  ..  god2.txt  god3.txt  godlover  god.txt
ls -a 表示查看当前文件夹底下的所有文件,包括隐藏文件
6 cat查看文件信息的命令
# cat 是查看文件信息
[root@localhost godsee]# cat god.txt
hello
[root@localhost godsee]# 
#查看多个文件的文件信息
[root@localhost godsee]# cat god2.txt god3.txt
456456456456456456456456456456456456456456456456456456456456456456456456456456456456456456456456456456456456456456456456456456456456456
123
456456456456456456456456456456456456456456456456456456456456456456456456456456456456456456456456456456456456456456456456456456456456456
[root@localhost godsee]# 

# 将文件中的内容读取出来,放入到另一个文件中

[root@localhost godsee]# cat god.txt > god5.txt
[root@localhost godsee]# cat god5.txt
hello
[root@localhost godsee]# 

7 echo 将信息进行输出
# 直接输出信息
[root@localhost oldboy]# echo "hello world"
hello world

# 将echo的内容写入到文件 ,> 是覆盖写入,>> 是追加写入
[root@localhost oldboy]# echo "hello world" > lxx.txt
[root@localhost oldboy]# ls
jason.txt  lxx.txt  oldboy.txt  olddog  oldgirl  oldgirl.txt
[root@localhost oldboy]# cat lxx.txt 
hello world
[root@localhost oldboy]# echo "hello world" > lxx.txt
[root@localhost oldboy]# cat lxx.txt 
hello world
[root@localhost oldboy]# echo "hello world" >>  lxx.txt
[root@localhost oldboy]# cat lxx.txt 
hello world
8 cp复制
cp = cope
语法格式: cp 参数(可选) 要复制的信息	复制到什么位置

[root@localhost godsee]# cp /etc/hosts godlover/
[root@localhost godsee]# ls
god2.txt  god3.txt  god4.txt  god5.txt  godlover  god.txt
[root@localhost godsee]# cd godlover
[root@localhost godlover]# ls
hosts  rain
[root@localhost godlover]# cat hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
[root@localhost godlover]# cp /etc/hosts godlover/
cp: cannot create regular file ‘godlover/: Not a directory
[root@localhost godlover]# cp /etc/hosts /godsee/godlover/
cp: overwrite ‘/godsee/godlover/hosts’? y
[root@localhost godlover]# 


# 复制文件夹
[root@localhost sysconfig]# cp /etc/sysconfig/ /oldboy/oldgirl
cp: omitting directory ‘/etc/sysconfig/[root@localhost sysconfig]# cp -r  /etc/sysconfig/ /oldboy/oldgirl
[root@localhost sysconfig]# cd /oldboy/oldgirl
[root@localhost oldgirl]# ls
sysconfig  tank
[root@localhost oldgirl]# cd /oldboy/oldgirl/sysconfig/
[root@localhost sysconfig]# pwd
/oldboy/oldgirl/sysconfig

cp的参数:
	-r 进行递归复制
    -p	拷贝是时候属性保存不变
    -d	和链接相关的文件
    -a	== -drp
    
# 利用cp做备份
[root@localhost oldboy]# cat jason.txt 
123
456
[root@localhost oldboy]# cp jason.txt  jason.txt.bak
[root@localhost oldboy]# ls
hosts  jason.txt  jason.txt.bak  lxx.txt  oldboy.txt  olddog  oldgirl  oldgirl.txt
[root@localhost oldboy]# rm -rf jason.txt
[root@localhost oldboy]# ls
hosts  jason.txt.bak  lxx.txt  oldboy.txt  olddog  oldgirl  oldgirl.txt
[root@localhost oldboy]# cp jason.txt.bak  jason.txt
[root@localhost oldboy]# ls
hosts  jason.txt  jason.txt.bak  lxx.txt  oldboy.txt  olddog  oldgirl  oldgirl.txt
[root@localhost oldboy]# cat jason.txt
123
456

# 如果cp的时候,多个文件,会出现多次确定,如何避免
[root@localhost oldboy]# cp -r /etc/sysconfig/ /oldboy/oldgirl
cp: overwrite ‘/oldboy/oldgirl/sysconfig/ip6tables-config’? y
cp: overwrite ‘/oldboy/oldgirl/sysconfig/iptables-config’? y
cp: overwrite ‘/oldboy/oldgirl/sysconfig/cbq/avpkt’? ^C

#解决办法
[root@localhost oldboy]# \cp -r /etc/sysconfig/ /oldboy/oldgirl

9 mv 剪切命名
mv --move
对文件或者文件夹进行剪切(移动)
语法格式:mv 要移动的文件或者文件夹	移动到什么位置
#在根目录创建test文件夹,然后创建heihei.txt
[root@localhost oldboy]# mkdir /test
[root@localhost oldboy]# cd /test
[root@localhost test]# touch heihei.txt

# 将 /test/heihei.txt文件 剪切(移动)到/oldboy/shanghai/的文件夹,
#创建/oldboy/shanghai文件夹
[root@localhost test]# mkdir /oldboy/shanghai
[root@localhost test]# mv /test/heihei.txt  /oldboy/shanghai/
[root@localhost test]# cd /oldboy/shanghai
[root@localhost shanghai]# ls
heihei.txt
#原来的/test/heihei.txt文件消失
[root@localhost shanghai]# cd /test
[root@localhost test]# ls


# 在linux系统没有重名名这个东西,我们可以同mv 命令实现
[root@localhost oldboy]# ls
hosts  jason.txt  jason.txt.bak  lxx.txt  oldboy.txt  olddog  oldgirl  oldgirl.txt  shanghai
[root@localhost oldboy]# mv lxx.txt lxxsb.txt
[root@localhost oldboy]# ls
hosts  jason.txt  jason.txt.bak  lxxsb.txt  oldboy.txt  olddog  oldgirl  oldgirl.txt  shanghai
10.rm命令(删除)
rm = remove
语法: rm 参数 要删除的数据信息

# 删除文件 rm
[root@localhost ~]# cd /oldboy/
[root@localhost oldboy]# ls
hosts  jason.txt  jason.txt.bak  lxxsb.txt  oldboy.txt  olddog  oldgirl  oldgirl.txt  shanghai
[root@localhost oldboy]# rm jason.txt.bak 
rm: remove regular file ‘jason.txt.bak’? y
[root@localhost oldboy]# ls
hosts  jason.txt  lxxsb.txt  oldboy.txt  olddog  oldgirl  oldgirl.txt  shanghai
# 删除文件夹 rm -r
[root@localhost oldboy]# rm shanghai
rm: cannot remove ‘shanghai’: Is a directory
[root@localhost oldboy]# rm -r shanghai
rm: descend into directory ‘shanghai’? y
rm: remove regular empty file ‘shanghai/heihei.txt’? y
rm: remove directory ‘shanghai’? y
    
#强行删除
[root@localhost oldboy]# ls
hosts  jason.txt  lxxsb.txt  oldboy.txt  olddog  oldgirl  oldgirl.txt
[root@localhost oldboy]# rm -f oldboy.txt 
[root@localhost oldboy]# rm -rf olddog
[root@localhost oldboy]# ls
hosts  jason.txt  lxxsb.txt  oldgirl  oldgirl.txt

#centos7这个命令会保护
rm -rf /
#rm -rf /* 不受保护

11.vim编辑器
#安装之前先切换镜像源
https://developer.aliyun.com/mirror/centos?spm=a2c6h.13651102.0.0.3e221b11yCmuQx
# 要用vim要安装
#命令:yum -y install vim 或者 yum install vim -y

# vim 是编辑器,他有三种状态
1 正常模式
	vim 文件 进入后就vim的正常模式,从正常如何进入编辑模式,输入 i,o,a,I,O,A,R,都可以,但是
	我们只要记住一个i,因为方便记忆。
	
	正常模式底下的命令:
	拷贝: yy 粘贴:p
	
	拷贝当前行向下2行,并粘贴
	拷贝2行:2yy
	粘贴:p
	
	删当前行:
	删除:dd
	删除当前行与下一行:
	删除:2dd
	
	光标移动到最后一行:G
	光标移到首行:gg
	光标移到第二行:2gg
	
	撤回:u
	
2 插入模式
	进入编辑模式,就可以直接输入内容。
3 命令模式 shift +1 查找内容:
	:/关键字
	2 取消高亮:
	:nohl
	3 显示行号:
	:set nu
	4 取消行号
	:set nonu
	5 没有修改情况下退出
	:q
	6 如果修改了,但我们不想保存,
	:q!
	7 如果修改,并且想保存,
	:wq
	
# 如果发现vim 不能编辑这个文件
# 我在这个文件所在目录执行: ls -a
# 你会发现有一个 .文件名.swp的隐藏文件
#我们执行删除命令将其删除:rm -rf .文件名.swp

![在这里插入图片描述](https://img-blog.csdnimg.cn/20200327112413631.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQxNTA2MTMx,size_16,color_FFFFFF,t_70)
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值