Create a file (Touch) command
The Linux Create File command is primarily used for touch commands, which can be used to modify the access time of the file, modify the time, or, if no time is specified, the current time, and if the specified file does not exist, the touch command creates the file.
Command format:
Touch
[-ACFM]
[-R file (reference files)]
[-t Decimtime (time value)]
[-D Time value]
[--time={atime,access,use,mtime,modify}]
[--date=time]
[--reference=file]
[--no-create] does not establish any files, and-C functions want to use
[--help] online Help
[--version] Display version information
[--]
File (Files) ...
-A modifies the access time of file files.
-C does not create file files.
-M to modify files file
-R ref_file The reference file Ref_file the value of the corresponding timestamp as the new value for the specified file time stamp.
-T time uses the value of the specified timestamp as the new value of the corresponding timestamp for the specified file, which can be either MMDDHHMM or YYYYMMDDHHMM
For example:
TOUCH-T 10112200 ABC to change the time of the ABC file to October 11 22 o'clock
TOUCH-T 200910112200 ABC to change the time of the ABC file to October 11, 2009 22 O'Clock
TOUCH-R baidu.com ABC changes the time of the ABC file to the same time as the baidu.com file
Touch ABC create ABC file (file time defaults to current time)
Of course, the Linux create File command also like: CP (copy file), MV (mobile file) is also a bar.
In addition, as long as the command can redirect output to a nonexistent file, the command can also create a file, such as the following command:
echo Hello World >/home/abc string output to/home/abc file
Cat baidu.com >/HOME/ABC Output the contents of baidu.com file to/home/abc file
Less testless >/home/abc
Tail-f-N 20/home/abc >/home/abc
Linux Delete files, Folder command RM
Linux Delete files, the folder is mainly used in the command is RM, the following will be a simple introduction to the Linux RM command.
Grammar:
RM [Options] DirName
The options in this command are commonly used in the following ways:
-I delete the query confirmation before
-F Even if the deleted file's properties are read-only, and deleted directly, without confirmation, the default is to be confirmed one by one.
-R Deletes the directory and all of the following files individually
Example:
Rm-i *.php Delete all files that are suffix PHP; ask for confirmation before deleting
Rm-r Phpernote deletes all files in the Phpernote directory and subdirectories, and when the file is read-only, prompts to delete
Rm-rf/var/access will delete the/var/access directory and all the files and folders under it, without any deletion confirmation prompts
Attention:
(1) There is no Recycle Bin in Linux, so when using the RM command, remember that the file or directory is deleted and cannot be recovered.
(2) If the prompt does not have permission to run the command, you can use sudo to elevate the user's permissions and then execute the command
View File Contents
Under Linux, there are many commands can view the contents of the file, the various commands have different usage and characteristics, you can choose the appropriate command to quickly and efficiently view the contents of the file, the following will be the Linux view of the contents of the command to do a summary.
Cat displays content from the first line and outputs all content
TAC displays content from the last line in reverse, and outputs all content
More based on the size of the window, a page of realistic file content
Less is similar to more, but its advantages can be leafed forward and can be searched for characters
Head only shows the first few lines
Tail shows only the last few lines
NL is similar to cat-n, output line number when displayed
The following is a detailed comparison of the use of the various commands, as follows:
1.cat command
Cat syntax: Cat [n] FileName
Parameter Description:-N: When displayed, the line number is output together
The function of cat is to output the content to the screen sequentially from the first line. But cat is not commonly used, because when the file is large, the number of rows is relatively long, the screen can not fully accommodate, only to see part of the content.
The function of the TAC is to output the content data to the screen, which is reversed from the last line of the file. We can find that the TAC is actually cat in turn to write.
2.TAC command
TAC Syntax: TAC filename
This command outputs the contents of the file and the content of the cat output is completely reversed. Generally no abnormal demand is rarely used.
3.more command
More syntax:
More file name
More function is to start the file from the first line, according to the size of the Output window, the appropriate output file content. When a page cannot be fully exported, you can use the "Enter key" down 3 lines (my environment is 3 lines, other Linux versions may be different), or use the SPACEBAR to page down. To exit the view page, press the "Q" key. This is a more commonly used command.
In addition, the more can also be with the pipe character "|" (pipe) Use, for example: Ls-al | More
4.less command
Syntax for Less:
Less file name
Less function and more similar, but use more can not turn the page forward, only backwards. Less you can use the "PageUp" and "PageDown" keys to make the front and rear pages look more convenient.
In addition, less also has a function, you can search in the file for what you want to find, if you want to find in the passwd file has no WWW.ABC strings, then you can do this:
[Sylar@ub2 etc]# less passwd
Then enter:
/www.abc
Enter
At this point, if there is a WWW.ABC string, Linux will display the character highlighted.
To exit the view page, press the "Q" key.
5.head command
Head's syntax:
Head "-N number" filename
The head is usually used only in the first few lines of the file, or in the last few lines.
For example:
[Sylar@ub2 etc]# head-n 5 Error.log--Displays only the first 5 lines of the Error.log file
6.tail command
Syntax for tail:
tail [-N number] file name
The function of tail is exactly the opposite of head, showing only the last few lines of content, in the same way, no examples here.
7.nl command
NL's Grammar:
NL filename
The functions of the NL command are the same as the cat-n, which also outputs all the contents from the first line and displays the line numbers.
chmod (file or folder permissions setting
The purpose of the Linux chmod command is to set the permissions for files or folders on a Linux system (hereinafter referred to as files), and to illustrate some of the detailed usage of the command below.
Command format: chmod [-CFVR] [--help] [--version] Mode file ...
mode sets the string for the permission, and the parameter format is as follows:
[Ugoa ...] [[+-=][RWXX] ...] [,...]
where u represents the owner of the file, G indicates that the owner of the file belongs to the same group (group), and O means the other person, and a says all three are.
+ means to increase permissions,-to indicate cancellation rights, = to represent a unique set of permissions.
R is readable, W is writable, x (lowercase) is executable, x (uppercase) means only if the file is a subdirectory or the file has been set to executable.
-C If the file permissions have been changed to show the change action
-F do not display error messages if the file permissions cannot be changed.
-V Show details of permission changes
-R makes the same permission change (that is, one by one) for all files in the current directory with subdirectories
--HELP Display Auxiliary instruction information
--version Display version Information
Use the case description below:
There is such a file in the system:/home/www/exam.sh
(1) Set the above file for everyone to read:
chmod ugo+r/home/www/exam.sh
Or:
chmod a+r/home/www/exam.sh
(2) The above file and another file/home/www/test.sh set as the owner of the file, and the same group of people who belong to write, but others are not writable:
chmod ug+w,o-w/home/www/exam.sh/home/www/test.sh
(3) The above documents should be set up only by the owner of the file to execute:
chmod u+x/home/www/exam.sh
(4) To set all files and subfolders under the current directory to be readable by anyone:
Chmod-r A+r *
Also note that you can use numbers to represent the appropriate permissions, the syntax format is: chmod ABC file
The A,b,c each represents a number, representing the permissions of User, Group, and other respectively.
R=4 (Read), w=2 (write), X=1 (execute)
To rwx the property is: 4+2+1=7
To rw-the property is: 4+2=6
To r-x the property is: 4+1=5