Linux file management must be knowledge

Source: Internet
Author: User

Linux file management must be knowledge

First, the File View Class command
①less options   parameters (file name)     
             Split screen display of file contents (view to end of file does not exit, press Q to exit)
              shortcut keys
                ctrl+d down half screen
                ctrl+u flip up half screen
                  Enter down one line
                 k key up one line
                 SPACEBAR down a full screen
                b up a full screen
                  #G jump to line #

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/5D/CC/wKioL1UklwCQvRG1AAEseYuSfds198.jpg "title=" 1.png " alt= "Wkiol1uklwcqvrg1aaeseyusfds198.jpg"/>

             ★ keyword lookup:
                /+ key from header to tail
                n-next next keyword
                 n Find keywords
                 ? + keywords from tail to header
                n Next (look up)
                 n Previous (from bottom up)-- > Note: Don't look like you're in a daze, just try it.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/5D/CD/wKioL1UkpPGy_bWcAAI-X-gcTXY126.jpg "style=" float: none; "title=" 2.png "alt=" Wkiol1ukppgy_bwcaai-x-gctxy126.jpg "/>

②more option (rarely used) parameter (file name)
Split-screen display of file content (features: viewing to the end of the file automatically exit)
Note: K keys and Ctrl+u are not available (this refers to the shortcut key relative to the above less)

③tail [Options] parameter (file name)
To see how many lines are at the end of a file, note: The default number of rows (10 lines) is displayed without any options
-N #或 (-#) to see the number of rows in the countdown
-F monitoring file There is no new content (for log viewing)

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/5D/D2/wKiom1Uko6mCBBYZAARpei_ZiYQ701.jpg "style=" float: none; "title=" 3.png "alt=" Wkiom1uko6mcbbyzaarpei_ziyq701.jpg "/>

such as: View the default number of rows and settings display 5 rows

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/5D/D2/wKiom1Uko6nzBeUFAAFDpYohHm4393.jpg "style=" float: none; "title=" 6.png "alt=" Wkiom1uko6nzbeufaafdpyohhm4393.jpg "/>

If monitoring is turned on on the pseudo-terminal/dev/pts/0

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/5D/CD/wKioL1UkpPGDgiS3AACr_lE0nic084.jpg "style=" float: none; "title=" 5.png "alt=" Wkiol1ukppgdgis3aacr_le0nic084.jpg "/>

Append the string "44" to the file File.log with Echo for the pseudo terminal/DEV/PTS/1

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/5D/D2/wKiom1Uko6nAH6iLAAELjtgBIeY527.jpg "style=" float: none; "title=" 4.png "alt=" Wkiom1uko6nah6ilaaeljtgbiey527.jpg "/>

To edit a file with Vim on a pseudo terminal/dev/pts/1, add 55, 662 lines


650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/5D/CD/wKioL1UkpPHA_8mBAABypjALOBM606.jpg "style=" float: none; "title=" 7.png "alt=" Wkiol1ukppha_8mbaabypjalobm606.jpg "/>

such as: On the pseudo-terminal/dev/pts/0 on the operation of the file monitoring change situation

Conclusion: Vim Open is a copy of the text open, and echo "CCC" >> File.log directly appends the string to the file File.log (original file). So-F refers to the monitoring file itself.

④head [Options] parameter (file name)
-N #或 (-#) to see the number of rows in the header
Note: The default number of rows (10 lines) is not followed by any option

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/5D/D2/wKiom1Ukpf7AwD0LAAPPHq3Jey4435.jpg "title=" 8.png " alt= "Wkiom1ukpf7awd0laapphq3jey4435.jpg"/>

For example, to view the default number of rows and set display 6 rows

II, type of file

Iii. composition of the file View the file's metadata )

     touch [Options] parameter (file name)   Timestamp management tool for file
        -a Modify only atime of files
        -m only modify files Mtime
        -c do not create empty files
         -t [[CC]YY]MMDDHHMM[.SS] Time-written format
         Note:-AT,-MT,-CT, can be set -ta not, because the subsequent-t time has a specific value    

[[Email protected] tmp]# lsbackups  file.log  man.config  yum.log [[email protected] tmp]# stat file.log           File:  ' File.log '   Size: 26             Blocks: 8          IO  Block: 4096   regular filedevice: fd00h/64768d    inode:  3014664     Links: 1Access:  (0644/-rw-r--r--)   Uid:  (     0/    root)    Gid:  (    0/     root) access: 2015-04-03 20:14:11.326956761 +0800modify: 2015-04-03  20:14:11.326956761 +0800change: 2015-04-03 20:14:11.329956762 +0800
[[email protected] tmp]# touch -a -t  201504031010.10 file.log   #修改文件的访问时间  -a[[email protected] tmp]# stat  file.log access: 2015-04-03 10:10:10.000000000 +0800                  #此处省略其他信息 (hereinafter) modify: 2015-04-03  20:14:11.326956761 +0800change: 2015-04-03 20:37:42.448971037 +0800 
[[email protected] backups]# touch -mt  201504031111.11 file.log   #修改文件的修改时间  -m[[email protected] tmp]# stat  file.log access: 2015-04-03 10:10:10.000000000 +0800                modify: 2015-04-03 11:11:11.000000000 + 0800change: 2015-04-03 20:39:55.134955727 +0800 
[[email protected] tmp]# touch-c-t 201504031212.12 file.log #修改文件的改变时间-c[[email protected] tmp]# stat file.log Access: 2015-04-03 12:12:12.000000000 +0800 (This moment is labeled Time 1) modify:2015-04-03 12:12:12.000000000 +0800change:2015-04 -03 20:40:43.301964980 +0800

Conclusion: Both Atime and Mtime have entered into force, and ctime is not effective because of the protection mechanism of the document, so CTime will not take effect immediately.

The following actions are followed to see the effect

[[email protected] tmp]# echo  "AA"  >>  file.log [[email protected] tmp]# stat file.log               #查看文件的元数据Access: 2015-04-03 12:12:12.000000000  +0800modify: 2015-04-03 20:52:13.553956518 +0800                  (This moment is marked as time 2) change: 2015-04-03  20:52:13.553956518 +0800 
[Email protected] tmp]# vim file.log [[email protected] tmp]# stat file.log access:2015-04-03 20:53:09.984956196 +0800mo dify:2015-04-03 20:53:25.258950158 +0800 (This moment is labeled Time 3) change:2015-04-03 20:53:25.260950347 +0800

Conclusion:(Vim can change all the time, echo cannot change the access time)

Note: Often easy to make mistakes, relative path and absolute path must be divided clearly oh

Iv. File Copy command
CP [option] parameter 1 (source file) parameter 2 catalog file (file, directory)
1, the source file is a file, the target file is a file

(1) The file does not exist, the target file is created, and the content is the content of the source file, as

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/5D/D2/wKiom1Uko6nTSCk0AAIgTPgKarg889.jpg "style=" float: none; "title=" Cp2.png "alt=" Wkiom1uko6ntsck0aaigtpgkarg889.jpg "/>

(2) file exists, content is overwritten, such as

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/5D/D0/wKioL1UkzmCS8yYUAALbRsRT870626.jpg "title=" 1 "alt= "Wkiol1ukzmcs8yyuaalbrsrt870626.jpg"/>

2, the source file is a file, the target file is a directory (directly copy the file to the target directory (must exist)) as

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/5D/D4/wKiom1Ukze2BP8D6AAFboyOEMbk073.jpg "title=" Cp3.png "alt=" Wkiom1ukze2bp8d6aafboyoembk073.jpg "/>

3, the source file is a directory, must be followed by an option-R to copy the directory to the target directory as

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/5D/D0/wKioL1Ukz4fzSnrqAAEqDnqKtZQ498.jpg "title=" Cp4.png "alt=" Wkiol1ukz4fzsnrqaaeqdnqktzq498.jpg "/>

-r copy directory, recursive replication is implemented

-D does not follow the source file that the symbol points to (that is, the symbolic link file is copied, not the file pointed to)
-a equals-r +-D
-I prompts whether to overwrite the default alias already set Cp-i
-F Forced replication (not recommended)

V. File Move command
MV [option] parameter 1 (source file) parameter 2 destination file (file, directory)
1, the source file is a file, the target file is a file

(1) The file does not exist, the target file is created, and the content is the content of the source file, as

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/5D/D6/wKiom1Uk2VCwAlIUAAKL5NbhD5Q568.jpg "style=" float: none; "title=" Mv1.png "alt=" Wkiom1uk2vcwaliuaakl5nbhd5q568.jpg "/>

(2) file exists, content is overwritten, such as

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/5D/D1/wKioL1Uk2pnhhOfGAAGg7FEO1aY555.jpg "style=" float: none; "title=" Mv2.png "alt=" Wkiol1uk2pnhhofgaagg7feo1ay555.jpg "/>

2, the source file is a file, the target file is a directory (directly copy the file to the target directory (must exist)) as

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/5D/D6/wKiom1Uk2VGDiDaKAAFfPf_V_vc607.jpg "style=" float: none; "title=" Mv3.png "alt=" Wkiom1uk2vgdidakaaffpf_v_vc607.jpg "/>

3, the source file is a directory, the source directory is copied to the target directory as

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/5D/D1/wKioL1Uk2pnigCk3AAJFQtj5jBg100.jpg "style=" Float:none; "title=" Mv4.png "alt=" wkiol1uk2pnigck3aajfqtj5jbg100.jpg "/> "

-I tips whether to move

-F Force Move (not recommended)
Vi. deletion of files
RM [Options] parameter (file name)
-R recursively deletes files, and can delete directories
-F Force Delete
-I hints whether to delete

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/5D/D6/wKiom1Uk2kqDm257AAE6x8fxa8o257.jpg "title=" rm.png "alt=" Wkiom1uk2kqdm257aae6x8fxa8o257.jpg "/>

Note: Create a security mechanism for the Recycle Bin, such as
/tmp Create a directory backups, all the files to be deleted can be put here first.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/5D/D6/wKiom1Uk3IPjdRsiAAENZI4GGNA529.jpg "title=" MV Recycle Bin. png "alt=" wkiom1uk3ipjdrsiaaenzi4ggna529.jpg "/>



Note: The demonstration effect of individual commands may be slightly ignored in this article, I hope you do your own practice, you will find the Secret of Linux!!!

This article is from the "Journeys By chance" blog, make sure to keep this source http://meaningful.blog.51cto.com/4543452/1630075

Linux file management must be knowledge

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.