4, Create, delete, copy, move directory

Posted by Kitty on Mon, 30 Mar 2020 16:10:54 +0200

1 create directory

Use: mkdir [options] [Directory...]

(1) Create folder a at the root

mkdir /a
ls /a

(2) Create multiple directories

mkdir a  b  c

(3) Create multi-level directory, eg: create b under a directory, create c under b Directory

mkdir -p  a/b/c/d
ls -R a

2 delete directory

rmdir can only delete the blank directory. If there is an empty directory in the directory, it cannot be deleted (linux: everything is file)

rm
rm -r deletes directories, even if they are not empty. Confirm at the first level
rm -rf deletes directories, even if they are not empty. No level 1 confirmation

3 copy directory

Introduction: cp copied files or directories
Use:
cp [options] file path
cp [options] file... Directory

(1) Copy file: cp + copied file + to which directory

user1@SC02ZRC4KMD6N normal % cp a/temp b
user1@SC02ZRC4KMD6N normal % 

(2) Copy directory: cp-r + copied file + to which directory

user1@SC02ZRC4KMD6N normal % ls -R a
tmp

a/tmp:
user1@SC02ZRC4KMD6N normal % ls b
user1@SC02ZRC4KMD6N normal % cp a/tmp b 
cp: a/tmp is a directory (not copied).
user1@SC02ZRC4KMD6N normal % cp -r a/tmp b
user1@SC02ZRC4KMD6N normal % 

(3) The progress bar will be displayed when copying files under windows. Under linux, you can use: cp-v + to copy files + to which directory

(4) After copying successfully, the time of the copied file may change. You can use the - p option to keep the last modification time of the file: cp -p + copied file + which directory to copy to

user1@SC02ZRC4KMD6N a % ls -l
total 0
-rw-r--r--  1 user1  staff   0  3  8 20:24 temp
drwxr-xr-x  2 user1  staff  64  3  8 20:14 tmp
user1@SC02ZRC4KMD6N a % date
2020 Sunday, March 8, 2008 20:25:30 CST
user1@SC02ZRC4KMD6N a % cp -p temp ../b 
user1@SC02ZRC4KMD6N a % ls -l ../b
total 0
-rw-r--r--  1 user1  staff   0  3  8 20:24 temp
drwxr-xr-x  2 user1  staff  64  3  8 20:15 tmp

4 mobile directory

Introduction: mv file / folder move and rename function

(1) Rename the file temp to temp1

user1@SC02ZRC4KMD6N a % ls
temp    tmp
user1@SC02ZRC4KMD6N a % 
user1@SC02ZRC4KMD6N a % 
user1@SC02ZRC4KMD6N a % mv temp temp1
user1@SC02ZRC4KMD6N a % ls
temp1   tmp

(2) Move files

user1@SC02ZRC4KMD6N a % ls
temp1   tmp
user1@SC02ZRC4KMD6N a % ls ../b
temp    tmp
user1@SC02ZRC4KMD6N a % mv temp1 ../b
user1@SC02ZRC4KMD6N a % ls ../b
temp    temp1   tmp
user1@SC02ZRC4KMD6N a % ls
tmp

(3) Rename while moving

user1@SC02ZRC4KMD6N normal % ls a
a   temp    tmp
user1@SC02ZRC4KMD6N normal % ls b
user1@SC02ZRC4KMD6N normal % mv a/temp b/temp1
user1@SC02ZRC4KMD6N normal % ls a
a   tmp
user1@SC02ZRC4KMD6N normal % ls b
temp1

(4) Move directory

user1@SC02ZRC4KMD6N normal % mkdir dirc
user1@SC02ZRC4KMD6N normal % 
user1@SC02ZRC4KMD6N normal % mv dirc a 
user1@SC02ZRC4KMD6N normal % ls a 
a   dirc    tmp

wildcard

Two wildcards are introduced here?
(1)Name it file Start file copied to b Directory, matching multiple characters

user1@SC02ZRC4KMD6N a % ls ../b 
user1@SC02ZRC4KMD6N a % touch filea fileb filec
user1@SC02ZRC4KMD6N a % ls
filea   fileb   filec
user1@SC02ZRC4KMD6N a % cp -v file* ../b
filea -> ../b/filea
fileb -> ../b/fileb
filec -> ../b/filec
user1@SC02ZRC4KMD6N a % ls
filea   fileb   filec
user1@SC02ZRC4KMD6N a % ls ../b
filea   fileb   filec

(2) Match? Match only one character

user1@SC02ZRC4KMD6N b % ls file*
filea   fileaa  fileabc fileb   filec
user1@SC02ZRC4KMD6N b % ls file?
filea   fileb   filec

Topics: Linux Windows Mobile