云计算运维

Windows Server 2003 - Windows Server 2019 系统工具,Linux系统脚本,Mysql、Nginx、PHP、Redis、K8S、Seafile、Weblogic 、Jenkins、DNS、DHCP、FTP、IIS、Zookeeper、Rabbitmq、Oracle、Tomcat、Mavrn等服务搭建维护,请关注我.

Linux文件系统组成和基本操作


Linux文件系统组成和基本操作

文件系统的组成

  • 文件和目录构成单根倒树状结构
  • 文件系统从根目录开始,表示为一个单独的“/”字符
  • 命名区分大小写
  • 路径之间以“/”分隔

重要目录

  • /root:超级用户root的家目录;
  • /home/username:普通用户的家目录;
  • /usr:安装的软件、共享库等目录;
  • /usr/bin:用户命令,存放的路径;
  • /usr/sbin:系统管理员命令;
  • /usr/local:本地自定义软件安装目录;
  • /etc:系统的配置文件;
  • /var:系统服务的数据,例如数据库文件、日志文件和网站内容等;
  • /tmp:系统临时文件目录;
  • /boot:系统启动所需要的文件;
  • /dev:包含一些特殊的设备文件,供系统用于访问硬件;
  • /proc和/sys:反应当前系统运行状态;

文件和目录名

  • 文件及目录的名字不能多于255个字符
  • 所有字符都要求是有效的,不能使用“/”作为文件名
    • 文件或目录名中不要使用特殊字符
    • 如果文件名中含有特殊字符时应该使用单引号引起来
  • 在Linux中命名区分大小写

绝对路径和相对路径

  • 绝对路径
    • 以根开头的路径
    • 文件位置的全路径
    • 在任何位置都可以引用
  • 相对路径
    • 不以斜线开头
    • 当前工作目录的相对位置
    • 在特定的位置才可以引用

基本操作

pwd:显示当前工作目录

[erik@localhost ~]$ pwd
/home/erik
[erik@localhost ~]$

cd:改变到一个绝对或相对目录

  • cd ..:回退到上一层目录
  • cd -:回退到上一次所在的工作目录
  • cd/cd ~:改变的哦啊当前用户的主目录
  • cd ~username:改变到某个用户的主目录
[erik@localhost ~]$ cd /etc
[erik@localhost etc]$ cd ..
[erik@localhost /]$ cd ~
[erik@localhost ~]$ 

ls:列出当前目录或者指定目录下的内容

  • ls -a:包含隐藏文件
  • ls -l:显示扩展信息
  • ls -R:递归所有目录
  • ls -ld:显示目录和符号链接信息
[erik@localhost ~]$ ls
Desktop  Documents  Downloads  Music  Pictures  Public  Templates  Videos
[erik@localhost ~]$ ls -a
.              .bash_profile  Desktop    .ICEauthority  Pictures
..             .bashrc        Documents  .local         Public
.bash_history  .cache         Downloads  .mozilla       Templates
.bash_logout   .config        .esd_auth  Music          Videos
[erik@localhost ~]$ ls -R
.:
Desktop  Documents  Downloads  Music  Pictures  Public  Templates  Videos

./Desktop:

./Documents:

./Downloads:

./Music:

./Pictures:

./Public:

./Templates:

./Videos:
[erik@localhost ~]$ ls -ld
drwx------. 14 erik erik 4096 Mar 26 06:23 .
[erik@localhost ~]$ ll
total 0
drwxr-xr-x. 2 erik erik 6 Mar 23 05:33 Desktop
drwxr-xr-x. 2 erik erik 6 Mar 23 05:33 Documents
drwxr-xr-x. 2 erik erik 6 Mar 23 05:33 Downloads
drwxr-xr-x. 2 erik erik 6 Mar 23 05:33 Music
drwxr-xr-x. 2 erik erik 6 Mar 23 05:33 Pictures
drwxr-xr-x. 2 erik erik 6 Mar 23 05:33 Public
drwxr-xr-x. 2 erik erik 6 Mar 23 05:33 Templates
drwxr-xr-x. 2 erik erik 6 Mar 23 05:33 Videos
[erik@localhost ~]$ 

touch:创建一个空文件或者更新一个文件的时间戳

  • 如果文件不存在,则创建空文件
  • 如果文件已存在,则更新文件的时间戳
    • atime(access time):文件最后一次被访问的时间
    • mtime(modify time):文件最后一次被修改的时间(文件内容发生变化)
    • ctime(change time):文件最后一次被改变的时间(文件属性发生变化,例如文件的权限、大小)
    • Birth:文件被创建的时间(红帽没有开启该时间)

cp:拷贝文件和目录

  • 格式:cp [option] file destination
  • 如果destination是一个目录,可以一次拷贝多个文件到这个目录,cp [option] file1 file2 destination
  • destination说明:
    • 如果目标是一个目录,该拷贝把文件放到该目录下
    • 如果目标是一个文件,该拷贝覆盖目标文件
    • 如果目标不存在,该拷贝被重命名
  • 拷贝目录使用cp -r
[root@localhost erik]# touch test.txt
[root@localhost erik]# ls
Desktop    Downloads  Pictures  Templates  Videos
Documents  Music      Public    test.txt
[root@localhost erik]# pwd
/home/erik
[root@localhost erik]#ls /opt
rh 
[root@localhost erik]# cp test.txt /opt/
[root@localhost erik]# ls /opt
rh  test.txt
[root@localhost erik]# 

mv:移动或者重命名文件和目录 ○ mv的源文件和目标文件在同一个目录就是重命名,不在同一个目录就是移动 ○ 格式:mv [option] file destination ○ 如果目标是一个目录可以同时移动多个文件,mv [option] file1 file2 destination

[root@localhost erik]# touch test1.txt
[root@localhost erik]# ls
Desktop    Downloads  Pictures  Templates  test.txt
Documents  Music      Public    test1.txt  Videos
[root@localhost erik]# mv test1.txt /opt
[root@localhost erik]# ls /opt/
rh  test1.txt  test.txt
[root@localhost erik]# 

rm:删除文件

  • 格式:rm [option] <file…
  • rm -i file:交互式删除,默认存在
  • rm -r directory:递归删除
  • rm -f file:强制删除
[root@localhost opt]# rm test.txt 
rm: remove regular empty file ‘test.txt’? yes
[root@localhost opt]# ls
rh  test1.txt
[root@localhost opt]# 

[root@localhost /]# rm /opt/test1.txt 
rm: remove regular empty file ‘/opt/test1.txt’? yes
[root@localhost /]# ls /opt
rh
[root@localhost /]# 

mkdir:创建空目录

○ mkdir -p:递归创建目录 ○ rmdir:删除空目录

[root@localhost /]# mkdir /opt/test1
[root@localhost /]# ls /opt/
rh  test1
[root@localhost /]# 

file:查看文件类型(Linux中没有文件后缀名)

[root@localhost /]# file /opt/test1/
/opt/test1/: directory
[root@localhost /]# 
  • 分享:
评论
还没有评论
    发表评论 说点什么