Linux目录与文件,删除命令

您所在的位置:网站首页 编程培训班学校 Linux目录与文件,删除命令

Linux目录与文件,删除命令

2023-03-11 06:28| 来源: 网络整理| 查看: 265

一、重要的目录

根目录: /

根目录 指文件系统的最上一级目录,它是相对 子目录 来说的;它如同一棵大树的"根"一般,所有的树杈以它为起点,故被命名为根目录。

pwd 查看当前路径

[root@localhost text2]# pwd /root/text/text2

cd .. 返回上一级文件夹

[root@localhost text2]# cd .. [root@localhost text]# pwd /root/text

cd / 返回根文件夹

[root@localhost text]# cd / [root@localhost /]# pwd /

cd ~ 返回家目录:root的家目录是/root;普通用户的家目录是/home/用户名

#root用户 [root@localhost /]# cd ~ [root@localhost ~]# pwd /root #普通用户 [dada@localhost ~]$ cd ~ [dada@localhost ~]$ pwd /home/dada

tree 查看目录结构

安装tree包 [root@localhost ~]# yum install tree -y [root@localhost ~]# tree . ├── anaconda-ks.cfg └── text └── text2 ├── 2.txt └── 4.txt 2 directories, 3 files 二、隐藏文件及文件常用命令 格式: .文件名 查看隐藏文件:ls -a [root@localhost ~]# ls -a . .bashrc .. .cshrc anaconda-ks.cfg .tcshrc .bash_logout text .bash_profile file 文件名: 查看文件属性 [root@localhost ~]# file text text: directory [root@localhost ~]# file a.txt a.txt: empty du -s -h 文件名(统计文件大小,-s 总计, -h 以K,M,G显示大小) [root@localhost ~]# du -s -h /etc/passwd 4.0K /etc/passwd ll/ls -l 查看文件详细信息 [root@localhost ~]# ll 总用量 4 -rw-------. 1 root root 1257 3月 7 19:24 anaconda-ks.cfg -rw-r--r--. 1 root root 0 3月 8 13:39 a.txt drwxr-xr-x. 5 root root 42 3月 8 13:29 text 三、路径

绝对路径:从/开始一层层往下走,绝对不会错的路径,与现在在哪里没有关系,单向性

相对路径:不是以/开头,以当前文件夹为参照物,可进可退,双向

经典相对路径名词:

. 当前文件夹

.. 上一级文件夹

四、新建文件夹/文件 1.mkdir

mkdir -p 文件名

1.存在文件不报错

2.若父文件不存在则新建

[root@localhost text]# mkdir dct [root@localhost text]# ls dct text2 [root@localhost text]# mkdir dct1/dct2 mkdir: 无法创建目录"dct1/dct2": 没有那个文件或目录 [root@localhost text]# mkdir -p dct1/dct2 2.touch

1.新建空文件;

2.更新文件时间(存在则更新时间)

[root@localhost dct]# touch file.txt [root@localhost dct]# ll 总用量 0 -rw-r--r--. 1 root root 0 3月 8 13:32 file.txt #存在则更新 [root@localhost dct]# touch file.txt [root@localhost dct]# ll 总用量 0 -rw-r--r--. 1 root root 0 3月 8 13:33 file.txt 五、删除命令rm 命令格式: rm [选项] 文件

rm -rf * 删除所有文件(不包括隐藏文件),不能在根目录使用,否则虚拟机崩溃

rm -rf .* 删除隐藏文件(不包括. .. )

-r 递归删除

-f 直接删除,无需确认

[root@localhost text]# tree . ├── dct │ └── file.txt ├── dct1 │ └── dct2 └── text2 ├── 2.txt └── 4.txt 4 directories, 3 files [root@localhost text]# rm -rf text2/ [root@localhost text]# tree . ├── dct │ └── file.txt └── dct1 └── dct2 3 directories, 1 file


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3