Linux System Command Learning Series 8-File related Operations Touch,rm,mv,cat,head,tail command

Source: Internet
Author: User
Tags create directory touch command

Previous section content:

1. System and Directory Management

2. PWD command

3. ... and.. Directory

4. Relative path and absolute path

Job: Enter the OPT path, using the relative path method and the absolute path method to enter into the actually any sub-directory

Cd/opt

Relative path CD RH

Absolute path CD/OPT/RH


File related actions:


1. Create a file: Touch command


Easiest way to use: Touch file name, create or modify file access and modify time for current time if file does not exist directly create empty file

First we create a file Test.txt, perform touch test.txt

Can see that I created a file, the time is March 17 14:41 minutes, this is not test.txt this file, now that the file already exists, then we execute the Touch test.txt command again, to see the details of the file:

You can see that the date of the file changed and became 14:43

The touch command has some parameters:

Take the first parameter as an example to illustrate the use of a parameter with

Touch–a test.txt only modifies access time

You can see that the recent change time has not changed.


2. Delete Files: RM command


The RM command is used to delete files or remove links.

Basic usage is RM [options] File

To delete a file:

The simplest usage, RM file name, for example we want to delete test.txt file, execute RM test.txt can

Can be found, the deletion will let us confirm that the input Y will not perform the delete operation, by adding the-f parameter, you can force the deletion, do not need our confirmation, such as:

To delete a folder:

Direct use of RM folder, will error

To add the –d parameter, you can delete the directory

Similarly, add-f parameter, do not need to confirm to delete

When we add a file Test.txt under the Test folder, and then use Rm–d test, you cannot delete

Add –r can cascade delete files under the folder, RM–DR test

After confirming 3 times, delete the test folder, again, we add the-f parameter, can be deleted directly

More parameters that can be viewed with rm–help


3. Move or rename files: MV command


MV Command: Move the source file to the directory location, or move multiple files to the directory

Basic usage:

MV [options] source file directory

For example, we move the test.txt under the root directory to the test folder

Also we can rename a file by moving a file in the same directory, for example, we have the name of the Test.txt Test.doc, only need to use MV Test.txt Test.doc

Move multiple files, you can enter more than one file name, compare we want to put the test folder below the two files Test.txt,test2.txt moved to the Test2 folder below, you can use the following command


4. View files: Cat command


Basic usage: Cat file name

For example, we want to view/var/log/maillog, we can view it directly with Cat/var/log/maillog


5. View file header: Head command


The head command is used to view the contents at the beginning of the file, the first 10 rows are displayed by default, and the number of rows of output can be specified by the-n parameter, as well as maillog for example, Head/var/log/maillog

Specify to display the first 2 rows, Head/var/log/maillog–n 2

6. View end of File: Tail command


The tail command displays the trailing information of the file, displaying the first 10 rows by default and using-N to specify the number of rows to display

Take Maillog as an example, Tail/var/log/maillog

Specify 2 rows to display Tail/var/log/maillog–n 2


Job: Create file Test.txt in root directory, create directory Test (command is mkdir), move test.txt to test directory, and rename to Test.doc


Follow the public number "get kicked genius" and watch the free video tutorial

Linux System Command Learning Series 8-File related Operations Touch,rm,mv,cat,head,tail command

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.