Linux Basic file operations

Source: Internet
Author: User

LS: Lists directory contents (files).

CP: Copy files.

MV: Rename (move) the file.

RM: Delete files.

LN: Create a file link.

ls command

ls [options] [Files]

The LS command lists the properties of files and directories. It directly lists the contents of the current directory when no parameters are added:

$ ls

You can also list what is included in the specified directory:

$ ls dir1 dir2 dir3

or list individual files:

$ ls file1 file2 file3

The most important options for the LS command are-a,-l, and-D. The LS command does not display files with a name that begins with "." By default, and option-a displays all files.

$ ls-a

The-l option is used to display details such as file names and properties in a long format:

$ ls-ldrwxrwxr-x 3 FUHD FUHD 4096 December 9 11:26 Android

From left to right: file access rights (Drwxrwxr-x), owner (FUHD), owning Group (FUHD), size (4096), last Modified date (December 9 11:26), and file name.

The-D option lists directory information (information for the directory itself). As an example:

$ ls-ld androiddrwxrwxr-x 3 FUHD fuhd 4096 December 9 11:26 Android/

LS Common options:

-A
Lists all files, including hidden files.
-L
Long format lists files that contain file attributes. The plus-h option indicates that a byte byte is substituted for a unit that is more suitable for user reading, such as KB,MB,GB.
-F
A symbolic type of symbol to decorate a specific file name, such as "/" for the Directory, "*" for the executable file, "@" for the symbolic Link, "|" Represents a named pipe, and "=" represents a communication pipeline. These symbols are just an identification that helps you identify file types, not part of the file name.
-I.
Add the inode number for the file before the filename.
-S
Add a block number of files before the file name, which is useful when arranging files by file size: $ ls-s | Sort-n
-R
When a file directory is encountered, its contents are recursively listed
-D
Lists the directory itself, not its contents.


CP command

CP [Options] files (File | directory)

The CP command is often used to copy a file:

$ CP File File2//copy file to File2

or copy multiple files to a directory:

$ cp file1 file2 file3 file4 destination_directory

With the-a option, you can also copy the entire directory recursively.

Common options for the CP command:

-p                   &NB Sp                    
Copy the contents of the file, together with the access rights, the timestamp to the new file, and if the permission allows, the original file owner and the owning group are copied to the new file as well. (If this option is not specifically specified, the owner of the new file is you, because you created it; the timestamp of the new file is the current time; Access rights are the intersection of the original file's access rights and your umask.)
-a
recursively copy entire directory Tree, and preserves all attributes of the file and all file links.
-r
recursively copy entire directory tree 。 This option does not preserve file attributes, such as access rights and timestamps, but retains symbolic connections.
-i
interactive mode. Ask before overwriting the target file.
-f
forced replication. Even if the target file exists, it is still unconditionally overwritten.

MV Command

MV [options] source target

The MV command can be used to rename a file:

$ mv File1 file2

or move files and directories to another directory:

$ mv file1 file2 dir3 dir4 destination_directory

MV Command common options:

-I.
Interactive mode. Ask before overwriting a target file
-F
Force the move. Even if the target file exists, it is unconditionally overwritten

RM command

RM [Options] files | Directories

The RM (remove) command is used to delete files, such as:

$ rm file1 File2 File3

Or recursively delete the entire directory, such as:

$ rm-r Dir1 Dir2

RM Command Common options:

-I.
Interactive mode. Ask before deleting each file.
-F
Force Delete, ignoring any errors or warnings.
-R
Recursively deletes the directory and its contents. Use sparingly, especially when paired with the-f option.


Linux Basic file operations

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.