Linux directory and file, delete command

1. Important catalog

Root directory: /

The root directory refers to the top-level directory of the file system, which is relative to the subdirectory; it is like the "root" of a big tree, and all branches start from it, so it is named the root directory.
  • pwd View the current path

[root@localhost text2]# pwd
/root/text/text2
  • cd .. Return to the previous folder

[root@localhost text2]# cd ..
[root@localhost text]# pwd
/root/text
  • cd / back to the root folder

[root@localhost text]# cd /
[root@localhost /]# pwd
/
  • cd ~ Return home directory: root's home directory is /root; normal user's home directory is /home/username

#root用户
[root@localhost /]# cd ~
[root@localhost ~]# pwd
/root
#普通用户
[dada@localhost ~]$ cd ~
[dada@localhost ~]$ pwd
/home/dada
  • tree view directory structure

安装tree包
[root@localhost ~]# yum install tree  -y
[root@localhost ~]# tree
.
├── anaconda-ks.cfg
└── text
    └── text2
        ├── 2.txt
        └── 4.txt

2 directories, 3 files

2. Hidden files and commonly used commands for files

Format: .filename

View hidden files: ls -a

[root@localhost ~]# ls  -a
.                .bashrc
..               .cshrc
anaconda-ks.cfg  .tcshrc
.bash_logout     text
.bash_profile

file file name: view file properties

[root@localhost ~]# file text
text: directory
[root@localhost ~]# file a.txt
a.txt: empty

du -s -h file name (statistical file size, -s total, -h display size in K, M, G)

[root@localhost ~]# du -s -h /etc/passwd
4.0K    /etc/passwd

ll/ls -l View file details

[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

3. Path

Absolute path : start from / and go down layer by layer, never wrong path, it has nothing to do with where it is now, one-way

Relative path : not at the beginning of /, with the current folder as a reference, forward and backward, bi-directional

Classic relative path nouns:

. current folder

.. Upper level folder

4. Create a new folder/file

1.mkdir

mkdir -p filename

1. Existing files do not report errors

2. If the parent file does not exist, create a new one

[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. Create a new empty file;

2. Update file time (update time if it exists)

[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	

5. Delete command rm

Command format: rm [option] file

rm -rf * deletes all files (excluding hidden files), and cannot be used in the root directory, otherwise the virtual machine will crash

rm -rf .* delete hidden files (excluding . .. )

-r delete recursively

-f delete directly without confirmation

[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

Guess you like

Origin blog.csdn.net/zheng_long_/article/details/129400163