A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service
Lin Bingwen Evankaka original works. Reprint please specify the source Http://blog.csdn.net/evankaka
Abstract: This article mainly describes the Linux command Daquan----common file Operation command, and attached an example
This command is often used to show what files are in the current directory, LS the most commonly used parameters are three:-a-l-F.
Description: The files on Linux are "." The files at the beginning are treated as hidden files by the system, only the LS command is not visible to them, and the hidden files are displayed with Ls-a in addition to the generic filenames.
Ls–f (Note that is the uppercase F)
Note: Using this parameter means adding more symbols for the file type after the file, such as * for executable,/for directory, @ for the Nexus file, because the-f parameter is used. But now basically all Linux distributions of LS have built-in the-f parameter, that is, we can see a variety of resolution symbols without entering this parameter.
Linux CD commands can be said to be the most basic Linux command statements, the other command statements to operate, are based on the use of the CD command. Toggle current directory to DirName
Note: Enter the system root directory, the above command after the execution of the LS command to see, the current directory has been to the system root directory
Description: Enter the system root directory to use the CD. "Always back, you can reach the root directory
Cd.. /.. //
Description: Use the CD command to implement the parent directory into the parent directory of the current directory.
The mkdir command is used to create a new directory, RmDir is used to delete the established directory
mkdir Create directory, if the directory exists will be an error
Note that if the Linlin content is not empty
rmdir command can only delete empty folders, if the folder is not empty, it will not be deleted, it does not have the-f option, so your command is wrong.
To delete a non-empty folder, you can use the RM command, plus RF two options, such as:
The CP command is used to copy one or more source files or directories to a specified destination file or directory. It can copy a single source file into a specific file with a specified file name or a directory that already exists. The CP command also supports copying multiple files at once, and when copying multiple files at a time, the target file parameter must be a directory that already exists, or an error will occur.
-A: This parameter has the same effect as specifying the "-DPR" parameter;-D: When a symbolic connection is copied, the destination file or directory is also established as a symbolic connection, pointing to the original file or directory connected to the source file or directory;-F: Forcibly copying the file or directory, regardless of whether the destination file or directory already exists; I: Ask the user before overwriting the existing files;-L: Make a hard connection to the source file, not copy the file;-P: Preserves the properties of the source file or directory;-R/R: Recursively handles all files in the specified directory with subdirectories;-S: Establish symbolic connections to source files, not copy files; U: When this parameter is used, the file will only be copied when the source file is changed more than the target file is updated or the target file corresponding to the name does not exist;-S: Replaces the default suffix of the file with the specified suffix "SUFFIX" when backing up the file;-B: Backup the target file before overwriting the existing file target; V: Verbose display of actions performed by the command
As below, copy the LINLIN.C under/home/linlin1 to/home/linlin2
As below, copy the LINLIN.C under/home/linlin1 to/home/linlin2 and rename it to hello.c
When we use the CP command to copy files under Linux, sometimes we will need to overwrite some files with the same name, when overwriting the file, we will have to keep pressing Y to determine the execution overwrite. The number of files is not much good, but if hundreds of estimates press Y to vomit blood, so toss a half-day summed up a method:
CP aaa/*/bbb Copy directory AAA under All to/BBB directory, at this time if the/BBB directory has the same name as the AAA file, you need to press Y to confirm and will skip the sub-directory under the AAA directory. Cp-r aaa/*/bbb This time still needs to press Y to confirm the operation, but does not ignore subdirectories. Cp-r-a aaa/*/bbb still needs to press Y to confirm the operation, and the AAA directory and subdirectories and file attributes are also passed to the/bbb. Cp-r-a aaa/*/bbb successful, no prompt pressed Y, passed the Directory property, did not skip the directory.
This command is used to delete files, and DOS under the RM (delete an empty directory) is a difference, we must pay attention to. There are three common parameters for RM commands:-i,-r,-f.
rm–r Directory Name: This operation can be deleted with the subdirectories below this directory, functionally and rmdir similar.-F,--force ignores nonexistent files and never gives hints. -I ,--interactive for interactive Delete- R,-R,--recursive instructs RM to delete all directories and subdirectories listed in the parameters recursively. - V,--verbose details the steps performed --help Display this help information and exit --version output version information and exit
As below, interactively delete
Force Delete all
The function of this command is to move the directory or file, and the extended function is to rename the directory or file. When you use this command to move a directory, he will also remove it along with subdirectories under that directory.
File renaming-B: Overwrite the previous backup if you need to overwrite the file. -f:force mandatory Meaning, if the target file already exists, will not be asked to directly overwrite;-I: If the target file (destination) already exists, you will be asked to overwrite it! -U: If the target file already exists and source is newer, update-T :--target-directory=directory move all source arguments to directory, That is, the target directory for the MV, which is used when moving multiple source files to a directory, when the destination directory is in front of the source file.
MV Original file (directory) name a new file (directory) name.
The du command can display the disk space occupied by the current directory, and the DF command can display the disk space remaining on the current disk. If the du command does not add any parameters, then the entire disk usage is returned, if the directory is added later, it is the directory on disk usage
To view the current directory and the size of the subdirectory:
View the entire disk size
There are three major features of cat:
1. Display the entire file at once. $ cat FileName
2. Create a file from the keyboard. $ cat > FileName
Only new files can be created and existing files cannot be edited.
3. Merge several files into one file: $cat file1 file2 > file
-N or--number starts at 1 for all output lines number-B or--number-nonblank and-n similar, except for blank lines that do not number-s or--squeeze-blank when encountering a blank line that has more than two consecutive lines, replace the blank line with a row-V or --show-nonprinting
Its usage is as follows:
Cat text displays text in this file;
Cat File1 File2 Displays the contents of the file1,file2 in sequence;Cat File1 File2>file3 The contents of File1,file2, and then "redirects (>)" to file3 files.
Append the contents of the text.c and text1.c files to the text2.c after adding the line number (blank line not added).
Here are two instructions for displaying a generic text file. If a text file is too long for more than one screen, it is not ideal to use cat, so you can try more and less two instructions. The more instruction can make more than one page of the file temporarily stay on the screen, wait until you press any of the keys before continuing to display. and less in addition to more features, you can also use the arrow keys to scroll up or down the file, so you feel free to browse, read the article, less is a very good choice.
MORE: Option file name
+n starting from joys N rows
-N defines the screen size as n rows
+/pattern searches for the string before each file is displayed, and then starts from the first two lines of the string
-C clear the screen from the top and then display
-D hint "press space to continue, ' Q ' To quit (press SPACEBAR to continue, pressing Q key to exit)", disable the ringing function
-L ignores Ctrl+l (page break) characters
-p to page a file by clearing the window instead of scrolling, similar to the-C option
-S displays a contiguous number of empty rows as a row
-U Remove the line from the contents of the file
Search for the string Lin before each file display, and then start the display after the first two lines of the string
The less tool is also a tool for paging through files or other output, which is a very powerful tool for Linux to view the contents of a file. The usage of less is more resilient than more. In more, we have no way to turn front, can only look back, but if use less, you can use [PageUp] [PageDown] and other key functions to go to look at the file, more easily used to view the contents of a file! In addition, in less you can have more search function, not only to search down, but also to search upward.
Less option file name
-B < buffer size > Set buffer size-e When the file display ends, automatically leaves the-F force to open special files such as peripheral code, directory and binary file-G only flag the last search keyword -i Ignore search case-m displays a percentage like the more command-n displays the line number of each line-o < file name > save less output in the specified file-Q does not use warning tone-S to display continuous empty behavior line-S the line too long will be out of the partial discard-x < number > the "tab" key is displayed as the specified number of spaces/strings: Search down the "string" function? String: Search Up "string" function N: Repeat previous search (with/or? related) N: Reverse repeat previous search (with Or? About) b turn back one page D back half page H display Help interface Q exit less command u forward scroll half page y forward one line space key scroll a line enter [PageDown]: [PageUp]: Flip one page up
Exit Press Q
Search down the string containing Lin
There are three commands in the Linux system that can be used to view all the files, namely the cat, more, and less commands. Their access to the use of the file is also relatively simple command file name, but the three are different.
Also used to view the contents of a file
Tail syntax format:
tail [-f] [-c number |-N number |-M number |-B number |-K number] [File]
Tail [- R] [-N number] [file]
Instruction for use:
the tail command writes the file specified by the files parameter to standard output starting at the specified point. If no file is specified, standard input is used. The number variable specifies how many cells are written to standard output. The value of the number variable can be a positive or negative integer. If the value is preceded by A + (plus sign), the file is written to standard output starting at the number of cells specified at the beginning of the file. If the value is preceded by a-(minus sign), the file is written to standard output starting at the number of cells specified at the end of the file. If the value is preceded by A + (plus sign) or-(minus sign), the file is read from the unit number specified at the end of the file.
-B number starts reading the specified file from the 512-byte block position represented by the number variable.
-C number reads the specified file starting at the byte position represented by the number variable.
-F If the input file is a regular file or if the filename parameter specifies a FIFO (first-in, in-out), then the tail command does not terminate after the last specified unit of the input file is copied, but continues to read and copy additional cells from the input file (when those cells are available). If the File parameter is not specified and the standard input is a pipe, the-f flag is ignored. The tail-f command can be used to monitor the growth of files that another process is writing.
-K number reads the specified file starting at the 1KB block position represented by the number variable.
-M number reads the specified file starting from the multibyte character position represented by the # variable. Use this flag to provide consistent results in a single-byte and double-byte character code set environment.
-N number reads the specified file from the first or last row position, represented by the sign of the number variable (+ or-or none), and is shifted by the Line No.
-R Displays the output in reverse order from the end of the file. The default value of the-R flag is to display the entire file in reverse order.
If the file is larger than 20,480 bytes, the-R flag displays only the last 20,480 bytes. The-r flag is valid only with the-n flag. Otherwise, it will be ignored.
The tail-f command can be used to monitor the growth of files that another process is writing. Especially useful when looking at the log, you update the log in real time, it is displayed in real time
Description: Perform the PWD command to instantly know the absolute path name of your current working directory.
Used to find which line in a file matches a string.
Such as. Display lines containing St, and their line numbers Will not appear to show the ST's
Finding a directory recursively based on file content
# grep ' energywise ' * #在当前目录搜索带 ' energywise ' line file # grep-r ' energywise ' * #在当前目录及其子目录下搜索 ' energywise ' File # grep-l -R ' energywise ' * #在当前目录及其子目录下搜索 ' energywise ' file, but does not display matching rows, only matching files are displayed
grep function is very powerful, here is only a brief explanation, interested students come down to study it!
For example, the current directory looks for files that end in. c$ find -name "*.txt"-print used to find all the ' *.txt ' files in the current directory and subdirectories $ find -name "[a-z]*"-print used in the current directory and subdirectories to find the file name beginning with an uppercase letter $ find/etc-name "host*"-print find files in the/etc directory with file names beginning with host $find -name "[a-z][a-z][0--9][0--9].txt"-print find files in the current directory The name starts with two lowercase letters followed by two digits, and finally the. txt file
1. Look for a file named "elm.cc" in a directory find/home/lijiajia/-name elm.cc 2. Find files in file names that contain a character (such as "Elm") find/home/lijiajia/-name ' *elm* ' find/home/lijiajia/-name ' elm* ' find/home/lijiajia/-name ' *elm ' 3. Query according to the characteristics of the file find/home/lijiajia/-amin-10 #查找在 Files accessed in the last 10 minutes of the system find/home/lijiajia/-atime-2 #查找在系统中最后48小时访问的文件find/home/lijiajia/-empty #查找在系统中为空的文件或者 Folder find/home/lijiajia/-group Cat # Find files that belong to Groupcat in the system (tried, the command is incorrect.) find/home/lijiajia/-mmin-5 # Find files modified in the last 5 minutes of the system find/home/lijiajia/-mtime-1 modified files in #查找在系统中最后24 hours fin d/home/lijiajia/-nouser #查找在系统中属于作废用户的文件 (don't understand what that means) find/home/lijiajia/-amin #查找在系统中最后10分钟访问的文件find /home/ftp/pub-user Lijiajia #查找在系统中属于lijiajia这个用户的文件 (PS: All the above is done under the/home/lijiajia/folder) 4. Find a file using a mixed Find method Find/tmp-siz E +10000000c-and-mtime +2 #查找 a file larger than 10000000 bytes in the/tmp directory and modified within 48 hours Find/tmp-user Tom-or-user George #查找/T The MP directory belongs to Tom or George of the two user files Find/tmp! -USR Fred #查找/tmp DirectoryFiles that do not belong to Fred 5. Find and display files find/home/lijiajia/-name ' elm.cc '-ls #在目录下查找名为 "elm.cc" files and display information about these files
Copyright NOTICE: This article for Bo Master Lin Bingwen Evankaka original article, reproduced please indicate the source Http://blog.csdn.net/evankaka
Linux command Daquan----common file operation commands
Start building with 50+ products and up to 12 months usage for Elastic Compute Service