File management related commands

First introduce the file types on the linux file system as follows:

 -:表示普通文件
 d:表示目录文件
 b:表示块设备文件
 c:表示字符设备文件
 l:表示软链接文件
 p:表示管道文件
 s:表示套接字文件

Example 1
View file type

[root@centos7 ~]# ll 
total 40
-rw-------.  1 root root 1897 Sep 20  2019 anaconda-ks.cfg
-rw-r--r--   1 root root  181 Oct 15  2019 base.repo
drwxr-xr-x.  2 root root    6 Sep 20  2019 Desktop
drwxr-xr-x.  2 root root    6 Sep 20  2019 Documents
drwxr-xr-x.  2 root root    6 Sep 20  2019 Downloads
drwx------. 38 root root 4096 Oct 10  2019 etc
-rw-r--r--   1 root root    6 Nov  7  2019 filel
-rw-r--r--   1 root root   33 Nov  7  2019 filel.ciper

显示结果中,第一个位置的符号“-”就代表了文件类型为普通文件。

Example 2
shows the current working directory

[root@centos7 ~]# pwd
/root

Example 3
Get the base name of /etc/sysconfig/

[root@centos7 ~]#basename /etc/sysconfig/
sysconfig

Example 4
Get the directory name of /etc/sysconfig/

[root@centos7 ~]#dirname /etc/sysconfig/
/etc

Example 5
Switch to the user's home directory

[root@centos7 /etc/sysconfig]#cd
[root@centos7 ~]#
或
[root@centos7 /etc/sysconfig]#cd ~
[root@centos7 ~]#

Example 6
Switch to the parent directory

[root@centos7 /etc/sysconfig]#cd ~
[root@centos7 ~]#

Example 7
Switch to the /etc/sysconfig directory

[root@centos7 ~]#cd /etc/sysconfig/
[root@centos7 /etc/sysconfig]#

Example 8
Switch to the last directory

[root@centos7 /etc/sysconfig]#cd -
/root

Example 9
Display all files in the current directory

[root@centos7 ~]#ls -a
.                Documents                  .pki
..               Downloads                  private2.key
anaconda-ks.cfg  .esd_auth                  private2.keyu
base.repo        etc                        private.key
.bash_history    filel                      Public
.bash_logout     filel.ciper                public.key
.bash_profile    .ICEauthority              .rnd
.bashrc          initial-setup-ks.cfg       .tcshrc
.cache           .initial-setup-ks.cfg.swp  Templates
.config          .lesshst                   Videos
.cshrc           .local                     .viminfo
.dbus            Music                      .vimrc
Desktop          Pictures                   .Xauthority

Example 10
displays additional information about the contents of the directory

[root@centos7 ~]#ls -l
total 40
-rw-------.  1 root root 1897 Sep 20  2019 anaconda-ks.cfg
-rw-r--r--   1 root root  181 Oct 15  2019 base.repo
drwxr-xr-x.  2 root root    6 Sep 20  2019 Desktop
drwxr-xr-x.  2 root root    6 Sep 20  2019 Documents
或
[root@centos7 ~]#ll
total 40
-rw-------.  1 root root 1897 Sep 20  2019 anaconda-ks.cfg
-rw-r--r--   1 root root  181 Oct 15  2019 base.repo
drwxr-xr-x.  2 root root    6 Sep 20  2019 Desktop
drwxr-xr-x.  2 root root    6 Sep 20  2019 Documents

Example 11
Recursively display directory contents

[root@centos7 ~]#ls -r
Videos       private2.keyu         filel.ciper  Desktop
Templates    private2.key          filel        base.repo
public.key   Pictures              etc          anaconda-ks.cfg
Public       Music                 Downloads
private.key  initial-setup-ks.cfg  Documents

Example 12
Combined Application

[root@centos7 ~]#ls -ar
.Xauthority    Pictures                   Desktop
.vimrc         Music                      .dbus
.viminfo       .local                     .cshrc
Videos         .lesshst                   .config
Templates      .initial-setup-ks.cfg.swp  .cache

Example 13
View the status of the filel file, pay attention to the three timestamps

[root@centos7 ~]#stat filel
    File: ‘filel’
    Size: 6             Blocks: 8          IO Block: 4096   regular file
Device: 802h/2050d  Inode: 201551289   Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2020-09-12 18:36:47.799983521 +0800
Modify: 2019-11-07 10:22:48.764939245 +0800
Change: 2019-11-07 10:22:48.764939245 +0800
 Birth: -

Example 14
Create an empty file tist.sh

[root@centos7 /data]#touch tist.sh
[root@centos7 /data]#ll tist.sh 
-rw-r--r-- 1 root root 0 Oct 20 14:48 tist.sh

Example 15
Copy the /etc/virc file to the current directory

[root@centos7 /data]#cp /etc/virc ./
[root@centos7 /data]#ll
total 16
-rw-r--r--  1 root  root  1026 Sep 16 10:50 anaconda-ks.cfg
-rw-r--r--  1 root  root  1761 Sep 10 08:29 awktest.txt
drwxr-xr-x  2 root  root     6 Sep 14 11:08 cdrom
drwxr-xr-x  2 root  root     6 Oct 31  2019 dir
drwxr-xr-x  5 mysql mysql  110 May 17 15:32 mysql
drwxr-xr-x. 2 root  root  4096 Oct 11 17:09 script39
-rw-r--r--  1 root  root     0 Oct 20 14:48 tist.sh
-rw-r--r--  1 root  root  1982 Oct 20 14:52 virc

Example 16
Copy the /data/script39 directory and all files and subdirectories under it to the current directory

[root@centos7 ~]#cp -R /data/script39/ ./
[root@centos7 ~]#ls script39/
argsnum.sh     disk.sh     mkcdrom.sh  sumfile.sh     yesorno.sh
backup.sh      hello.sh    pass.sh     sumid.sh
chkscore.sh    initial.sh  REG         sysinfo.sh
createuser.sh  links.sh    rename.sh   systeminfo.sh

Guess you like

Origin blog.51cto.com/14233656/2542617