CentOS File New, delete, move, copy and other commands

Source: Internet
Author: User
Tags tmp folder

Create a Directory

mkdir file name

Mkdir/var/www/test

CP Copy Command

CP command copies files from one location to another. If the destination file exists, the file will be overwritten, and if the destination directory exists, the file will be copied to that directory (the directory will not be replicated).



Grammar:
Syntax is
CP [command Switch] ... SOURCE DEST
CP [OPTIONS] ... SOURCE ... DIRECTORY
CP [Options]...–target-directory=directory SOURCE ...

Command switch:

-A Equivalent to-DPR.
–backup[=control] Make a backup of each existing target file.
-B Like –backup, but does not accept parameters.
-F If the existing destination file cannot be opened by a write operation, delete it and try again.
-P Equivalent to –preserve=mode,ownership,timestamps (retention mode, owner, and timestamp information).
–preserve[=attr_list] Retains the specified property (default property: Mode, owner, timestamp) and security configuration, adding additional properties if possible: Connect, all.
–no-preserve=attr_list The specified property is not preserved.
–parents Add the source path under the directory.




Example:

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

    2. To back up the copied files:
      Cp-b file1.php file2.php
      Create a file file1.php with the symbol ' ~ ' backup file file2.php~.
    3. To copy folders and subfolders:
      Cp-r Scripts Scripts1
      The above CP command copies folders and subfolders from scripts to Scripts1.
MV Move Command

The MV command is the abbreviation for move. Use it to move/rename files from a directory to a directory. The MV command differs from the CP command, where the MV command is completely moving files from the source and moving the files to the specified directory, where the CP command simply copies the contents of the file from one file to another file.

Grammar:
Syntax is
MV [-F] [-i] original name new name

Command switch:

-F Do not prompt before overwriting (equivalent to equivalent to –reply=yes). Mv-f will move the file (multiple files) without prompting, even if it will replicate the existing destination file.
-I. Make a note before copying another file




Example:

    1. To rename/move a file:
      MV File1.txt File2.txt
      This command renames the File1.txt file with the name File2.txt.
    2. To move a directory
      MV Hscripts TMP
      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.
    3. 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.
RM Delete command

The RM Linux command is used to remove/Remove files from the directory.

Grammar:
Syntax is
RM [command switch:] [File | directory]

Command switch:

-F Do not prompt the user to delete all files under the directory.
-I. Interactive mode. With this option, the RM command prompts the user for confirmation before deleting any files.
-R (or)-R Recursively deletes the directory and its subdirectories in the parameter table. The directory will be emptied and deleted. When you delete a directory that contains a write-protected file, the user is usually prompted.




Example:

    1. Remove/Delete files:
      RM file1.txt
      Here the RM command will remove/delete the file file1.txt.
    2. To delete a directory tree:
      Rm-ir tmp
      Here the RM command recursively deletes the contents of all subdirectories under the TMP directory, prompting you to delete each file, and then deleting the TMP directory itself.
    3. Delete multiple files at once.
      RM file1.txt File2.txt
      The RM command also deletes files File1.txt and file2.txt.

CentOS File New, delete, move, copy and other 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.