Linux Common commands

Source: Internet
Author: User

1. Find usage

" Text.txt "/tmp/text.txt/root/text.txt

#找到文件后, give it to the pipe to delete
[Email protected] tmp]# Find/-type f-name "Text.txt" | Xargs rm-f

Interview title: Delete all files in a directory, but keep a specified file (keep File10)

[email protected] tmp]# Touch file{1.. 10}[[email protected] tmp]# ll total dosage0-rw-r--r--1Root root0May - Ten: thefile1-rw-r--r--1Root root0May - Ten: OneFile10-rw-r--r--1Root root0May - Ten: thefile2-rw-r--r--1Root root0May - Ten: theFile3-rw-r--r--1Root root0May - Ten: thefile4-rw-r--r--1Root root0May - Ten: theFile5-rw-r--r--1Root root0May - Ten: theFile6-rw-r--r--1Root root0May - Ten: theFile7-rw-r--r--1Root root0May - Ten: theFile8-rw-r--r--1Root root0May - Ten: thefile9# Method One: [[email protected] tmp]# Find/tmp-type f! -name"File10"|xargs RM-F Method Two: [[email protected] tmp]# Find/tmp-type f! -name"File10"-exec rm-f {} \;

#find找到的内容,-exec is a parameter, {}: The target to look for, you can generally do not write \: Backslash escape character
! The effect is: take the reverse

2, RM remove delete files or directories

-F Mandatory

-R Delete Directory

 Note: The production scenario should not use RM, if not to use, must first CP backup

0 1 0 May  : 0

3. Echo Usage

Print out content, with "> or >>" to overwrite and append content to the file

">" means redirect, which clears all previous data in the file.

">>" For additional content

4. Cat View File contents

Special usage: Add multiple lines of content

[email protected] tmp]# cat >>/tmp/nulige.txt <<EOF> I am studying Linux. >41 root root  0 May  :  File10  1 May  :  nulige.txt[[email protected ] tmp]# Cat Nulige.txt I am studying Linux.

5. CP command

Grammar:

CP source file directory file (cp parameter Apr)

Parameters:

-A: equivalent to-PDR

-D: If the source file is a linked file, the link file property is copied instead of the file itself

-F: Mandatory, the right directory file already exists and cannot be opened, then try again after removing

-I: If the target file already exists, the overwrite will be asked first

-P: Copy the past together with the attributes of the archive, not the default properties

-R: Recursive for copying directories

-U: If the destination file exists, the destination file is copied before the source file

Tip: If the source file is multiple, then the destination file is at the end, and the directory

6.

Linux Common 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.