Basic operations on files and directories

Source: Internet
Author: User
Tags touch command

Basic operations on files and directories under the Linux Command Line:

1. Create a file:

Touch file name --> the file name cannot contain spaces. To create a file name with spaces, the file name must be enclosed in double quotation marks.

Eg. Touch program file --> This command will create a connected file program and file.

Touch "program file" --> This command creates a file in program file. (It is not recommended to create a file name with spaces)

 

2. Create a directory:

Mkdir directory name --> create a directory, which is similar to the touch command and cannot be simpler.

When the mkdir ho/fk/test command is executed, if there is no FK directory or the ho directory, an error is returned. Parameters must be added at this time:

Mkdir-P ho/fk/test will recursively create sub-directories.

 

3. delete a directory or file

(Never experiment with the/etc directory .... Never beat me)

Rmdir directory name --> delete an empty directory (only empty directories can be deleted, and files or directories under the directory cannot be deleted.

Rm [-RF] directory or file name --> if you delete a file, you can directly Delete the RM file name. To delete a directory, you must add-R, for example, Rm-r/etc, to delete the directory. Otherwise, an error is returned.

So what is the use of f? If the directory you want to delete contains many directories and files, after the RM-R command is executed, ask every file or directory before it is deleted. Do you want to delete it? (Annoying). But if you add the parameter F to delete it directly, you will not be asked that much.

The RM-RF/etc command directly deletes the entire/etc directory. (For example, do not try this directory ...)

4. Copy and cut directories or files

CP [-RP] original file or directory target file or directory --> copy operation. r generally indicates that the operation is a directory in the parameter. Here, r also indicates that the operation object is a directory. The p parameter indicates the object and directory attributes [Creation Time, etc.] are retained.

Move [-RF] the target file or directory of the original file or directory --> cut operation. r indicates the operation directory, and F indicates the execution.

5. View File Information

In Linux, ls can be used to display the contents of directories and information of some files and directories;

Ls [-ALDH] [file or directory]

A --> display all files, including hidden files starting.

L --> displays detailed information about a file.

D --> view directory Properties

H --> Human, displayed in a way that humans can understand.

Ls-I file --> View the Object ID

PWD can view the current directory... (In other words, you often cannot find where you are .... Very depressing !!!!)

When I was writing this essay, I came to ask for a tutorial from instructor Podo .... So I am reading this tutorial from instructor Podo .. -_-''. Please do not despise me...

Basic operations on files and directories

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.