Linux file Directory related commands

Source: Internet
Author: User

File directory related commands


Chong file built


Touch 111 Create a file 111

echo 'aaaaa' > 111 Write aaaaa to file 111 (overwrite the content in the previous 111)
echo 'bbbb' >> 111 writes bbbb to file 111 (appended to the last 111 content)



Create a Directory

mkdir A to create a directory
mkdir a/B Creates a directory and creates a B directory in the A directory, the error indicates that a directory does not exist

Parameter -p enables recursive creation
mkdir -p a/B was created successfully (a directory was created and B is created within the A directory)



Delete Directory

rmdir a    Delete a directory   (  can only delete empty directory  a directory must be empty)

Rm - r a    Delete a directory   ( - r  means delete   Include directory and file  )   (  can delete files in directories and directories   but will go in the directory to ask if each directory or file is deleted   need to press  y  to confirm the deletion  )

Do not want to ask for each directory file   Direct Delete can use  - f  parameters
rm  - rf a   Delete all directories and files within a directory do not ask   (  use  )



copy

CP 1. PHP 1. Php.bak Copy a file (plus -i parameter if 1.php.bak exists then ask if the overlay test is not added -I will also ask whether to overwrite)
CP a copy a catalog error
CP -r A copy directory must add -r parameter



Move a file or directory (or rename)

Mv1. PHP Test/1. PHP moves 1.php to the test directory
Mv1. PHP Test/2. PHP moves 1.php to the test directory and renames to 2.php
Mv-I1. PHP Test/2. php (Parameter-i) move the 1.php to the test directory and rename it to 2.php but if there is a duplicate name in the test directory 2.php then the hint is overwritten
MV Dir1 Test/DIR2 move the Dir1 directory to the test directory and rename it to Dir2 (move directory without parameters)



View the contents of a file (a small amount of content can only display one screen more than the last screen content)

Cat AAA View the contents of the AAA file
Cat -n AAA Display content line number
Cat -A AAA display all content including special symbols, etc.


View the contents of a file (you can use more when the file content is more than one screen)

More AAA View AAA file contents

Space shows next page
Enter to display the next line
Q or Q exit

less and more as much as the upside down function
J Upside Down K


Use more or less to use/or what? Search to search and then press N to find the next
/search down the current line and search up the current line




Head and tail

Head AAA Displays the first 10 lines of the AAA file (default 10 lines)
Head- theAAA Displays the first 15 lines of the AAA file

Tail AAA Displays the following 10 lines of the AAA file
Tail- theAAA displays the following 15 lines of AAA files



File Lookup

Find/Root/ -Name T1 in/Root/Directory to find files with file name T1 (exact match)
If you want to blur a lookup, you can use the wildcard character find/Root/-Name T*Find files beginning with T

*: matches any of any characters

? : Matches an arbitrary character

-Size: Lookup based on file size (size in chunks) default chunk size is 512 bytes

Find/-Size+204800Finding files larger than 204,800 chunks in the root directory is larger than+Less than with-

Find/-UserChuang Find file owner in root directory is Chuang file



Linux file directory-related 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.