Linux (CentOS) New, delete, move folder and file commands

Source: Internet
Author: User
Tags tmp folder

1. Create a new Folder

mkdir file name

Create a new folder named Test under Home

View Source1 Mkdir/home/test

2. New text

Create a new test.sh script under Home

vi/home/test.sh

3. Delete a file or folder

1. Delete the test directory in the home directory

Rm/home/test

2. This method of deleting without parameters often prompts that it cannot be deleted because of insufficient permissions.

Rm-r/home/test

3,-R is a recursive delete parameter in the table of directories and their subdirectories. The directory will be emptied and deleted. When you delete a directory that contains a write-protected file, the user is usually prompted.

Rm-rf/home/test

-4, F is not prompt users, delete all files under the directory. Please note that it is tragic to check the path and enter into another directory.

Rm-ir/home/test

5,-I is an interactive mode. With this option, the RM command prompts the user for confirmation before deleting any files.

4. Move a file or folder

MV [options] source file or directory destination file or directory

Example:

1. Move all files, directories and subdirectories in Hscripts folder/directory to TMP directory MV hscripts TMP
Analysis: In the above command, if the TMP directory already exists, the MV command will move all files, directories and subdirectories in the Hscripts folder/directory to the TMP directory. If there is no TMP directory, it renames the hscripts directory to the TMP directory.

2. move multiple files/More ask price to another directory
MV File1.txt Tmp/file2.txt Newdir

This command moves the file1.txt file of the current directory and the TMP folder/directory of the File2.txt file to the Newdir directory.

Parameters:

-I: Interactive mode operation. If the MV operation will result in overwriting an existing target file, then the system asks whether to overwrite it, asking the user to answer "y" or "n", which avoids overwriting the file by mistake.

-F: Disables interactive operation. MV operation to overwrite an existing target file without giving any indication, after specifying this parameter the I parameter will no longer work.

5. Copying files or folders

CP [Options] source files (source) destination files (destination)

Parameters:
-A: equivalent to the meaning of-pdr;
-D: If the source file is the attribute of the link file, the link file attribute is copied instead of the file itself;
-F: For force, if there is any duplication or other doubt, the user will not be asked, but forced to copy;
-I: If the destination file (destination) already exists, the overwrite will ask if the action is true!
-L: The link file for the hard link is established, not the copy file itself;
-P: Copy the past together with the attributes of the archive, rather than using the default attributes;
-R: Recursive continuous replication, used for directory replication behavior;
-S: Copy as a symbolic link file (symbolic link), i.e. "shortcut" files;
-U: Update destination If destination is older than source!
Finally, note that if the source file has more than two, then the last destination file must be "directory"!

Example:


1. Copy two files :
CP file1 File2
The CP command above copies the contents of the file file1.php to the file file2.php.

2, backup copy of the file :
Cp-b file1.php file2.php
Create a file file1.php with the symbol ' ~ ' backup file file2.php~.
3. Copy folders and subfolders :
Cp-r Scripts Scripts1
The above CP command copies folders and subfolders from scripts to Scripts1.

6. Create a Directory
mkdir file name
Mkdir/var/www/test

Linux (CentOS) New, delete, move folder and file commands

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.