Linux basic file operation commands

Source: Internet
Author: User
Linux basic file operation command-Linux general technology-Linux technology and application information, the following is a detailed description. Enter the specific directory order: "cd"
For example, go to the home directory under the root directory.
# Cd/home
Go to the share directory under the current directory
# Cd share
Back to parent directory
# Cd ..
Return to the root directory
# Cd/
The usage of the "cd" command in linux is similar to that of the "DOS" command.
[Note] * enter the lowercase letter "cd" instead of the uppercase letter "CD". In linux, it is a case-sensitive parameter: "cd" = "CD"

Command for displaying the Directory and file list: "ls"
For example, the root directory and file list are displayed.
# Ls/
Display content in the etc directory under the root directory
# Ls/ect
Display contents in the current directory
# Ls
Common parameters:
# Ls-l' list the details of each directory and file in the current directory as follows:
Total usage 136616
-Rwxrwxrwx 1 root 14171744 July 5 2006 M2M-The day you went away. mpeg
-Rwxrwxrwx 1 root 9875351 July 5 2006 NANA-LONEY.wmv
-Rwxrwxrwx 1 root 13884366 sent a 2006 email to your malicious. wmv
-Rwxrwxrwx 1 root 14239997 2006 Zhou huajian-hard to resist. wmv
-Rwxrwxrwx 1 root 8675552 2006 Zhang Shaohan-fable. wmv
-Rwxrwxrwx 1 root 12848837 June July 8 2006 Wang xinling_eyelash bending. wmv
-Rwxrwxrwx 1 root 16050388 July 5 2006 WANG Rong-oh. wmv
-Rwxrwxrwx 1 root 11059489 September July 5 2006 Xiao Yao-Love to be frank. wmv
-Rwxrwxrwx 1 root 11647679 June July 5 2006 Xiao yaxuan-the most familiar stranger. wmv
-Rwxrwxrwx 1 root 10317222 2006 Dong Yanni-dragon family. wmv
-Rwxrwxrwx 1 root 17078937 July 5 2006 Blue Qin-Legend of the world. wmv
# Ls-c 'sort by the time when the file is created. The time is from near to far to display the content of the current directory:
Believe in your evil spirits. wmv Xiao-I want to be honest. wmv lanqin-Legend of the world. wmv
Wang xinling_eyelash bending. wmv WANG Rong-oh. wmv Zhou huajian-hard to resist. wmv
NANA-LONEY.wmv M2M-The day you went away. mpeg Xiao yaxuan-the most familiar stranger. wmv
Dong Yanni-dragon family. wmv Zhang Shaohan-fable. wmv

Parameters:
"-S" is sorted by file length. The longest file is in front
"-U" sorts files by the last access time
"-T" sort by file modification time
"-R" displays items in reverse order
"-R" displays the file information of the local directory and Its subdirectories.
"-U" is listed in the order of directories.
Multiple parameters can be used in combination, such as "ls-lt" and "ls-ls"

Copy FILE command
For example, copy the 123.txt file under the current directory to the/home/temp directory:
# Cp 123.txt/home/temp
[Note] * The Copy command "cp" in linux is unfriendly. If a file is overwritten, no prompt will be displayed, therefore, you need to add the parameter "-I" to force the prompt before overwriting the file:
# Cp-I 123.txt/home/temp
Because the root user is a super administrator and has a high permission, the linux system will force a prompt by default, that is, "cp" = "cp-I". Because the root user often copies and overwrites a large number of files, it is annoying to lock every time a file is overwritten. In this case, the system will forcibly ignore the prompt: # cp-f *. "-f" in doc/home/doc indicates that the "-I" is ignored.
In the dossystem, files in subdirectories and subdirectories cannot be copied using the COPY command. In this case, DOS has to introduce an external command XCOPY to perform this operation. In Linux, the "cp" command has the following effect:
For example, copy the content in the directory test and Its subdirectories to/home/temp:
# Cp-R test/home/temp
Generally, after the source file is copied to the target directory, the permissions of the copied file are different from those of the source file, the permission to copy the file to the target directory is the permission of the command operator. To ensure that the two files have the same permissions, you must add a parameter "-p"
Example: # cp-p 123.txt/home

Delete files/Directories
Example: delete all txt files in the current directory
# Rm *. txt
In linux, the rm interface is unfriendly. No confirmation operation prompt is provided before the file is deleted. Therefore, files are often deleted by mistake. In order to force the operation confirmation before the file is deleted, you can add the parameter "-I"
Example: delete 123.txt from the current directory.
# Rm-I 123.txt
Example: Delete the test directory under the current directory
# Rm-r test
Generally, the root user has a large permission. To prevent misoperations, the system determines that the root user must confirm before executing the rm operation, that is, "rm" = "rm-I ". If the root user wants to delete the entire directory or multiple files at a time, it must be confirmed multiple times. This is inconvenient, so we need to add the parameter "-f" to ignore the confirmation information, for example:
# Rm-rf test

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.