preface

This article mainly tells about the most basic four commands in Linux, touch, mv, cp and rm, respectively corresponding to the file creation, delete, move and copy, hope to help you! .

Touch command

The touch command is used to create files but not folders. The mkdir command is used to create folders.

1. Create a single file

touch test1.txt

2. Create multiple files

touch test1.txt test2.txt

In addition to creating files, the touch command has another function: changing the timestamp of files.

#View file timestamp: ll orstat test1.txt
$ stat test1.txt. Access: 2019-05-11 07:48:53.307598828 +0800 Change: "Access" indicates the Access time, "Modify" indicates the Change time, and "Change" indicates the Change time, that is, the timestamp of the file
#Modify file timestamp (past or future time can be specified)Touch - at 202001010745.20 test1. TXT
#Notice The time format is [[CC]YY]MMDDhhmm[.ss], that is, the accuracy is only seconds
## Wrong example
$Touch - at 202001010745.20222 test1. TXTTouch: Invalid date format '202001010745.20222'Copy the code

The mv command

Mv, short for move, is used to move files or folders.

1. Move test. TXT to dir

mv test.txt dir/

2. Move multiple files

mv test1.txt test2.txt dir/

The cp command

Cp, short for copy, is used to copy files or folders.

#Copy files to dir directory
cp test1.txt dir/ 

#Copy the test. TXT file with the new name test2.txt
#Note: the copied test2. TXT timestamp is the current time, not the time of test1. TXT
cp test1.txt test2.txt  

#Copy folder
cp -r dir1  dir2 

#Copy all files from dir1 to dir3
cp -r dir1/*  dir3  
Copy the code

The rm command

Rm, short for remove, is used to delete files or folders.

The rm command has two important parameters, -r and -f.

-r: deletes the directory and all files in the directory recursively. If the deleted files do not exist, a message is displayed indicating that the files are forcibly deleted. If the deleted files do not exist, no message is displayed indicating that the files are deletedCopy the code

Note: Running rm -rf does not put the deleted file into the recycle bin. Therefore, use caution when running this command to avoid file recovery failure. If you delete a project managed by The Jetbrain family bucket using rm -RF, don’t panic because the Jetbrain family bucket keeps a record of the deleted files. If you delete a project by mistake, right click in your project directory and there is a Local History option. Click on the “Show History” suboption, which has a record board, and right-click again to restore deleted files.

Write in the last

Dear bosses, creation is not easy, but it needs to be honed and summarized constantly, welcome to pay attention to me, I am Yan Gan, I will share with you all kinds of practical programming knowledge and skills, your praise and attention is the biggest motivation for my progress and creation!!