File Management Commands

Source: Internet
Author: User

File Management commands:
1. cat option file name
-N Displays the number of file lines
-e Display file special characters (for example: line terminator $)

[[email protected] var]# cat 11LSSSOO99999FKLJLKJL hhljljlkhlkjl;lhlkjlkl[[email protected] var]# cat-n 1 lsssoo99 999f 2 Kljlkjl 3 HHLJLJL 4 khlkjl;l 5 HLKJLKL [[email protected] var]# cat-e 11LSSSOO99999F$KLJ LKJL $HHLJLJL $khlkjl;l$hlkjlkl$

2, more filename split screen display file content (to the end of the file will automatically exit)
Its shortcut key: ctrl+d down half screen
Enter a line down
SPACEBAR to turn down one screen
b go up and flip a screen
3, less file name split screen display file content (to the end of the file does not automatically exit)
Its shortcut key: ctrl+d down half screen
Ctrl+u turn up half screen
Enter a line down
K Up Line
SPACEBAR to turn down one screen
b go up and flip a screen
#G Jump to # line
/keywords? Key words
N Next
N Previous

4. Tail option file name to see how many lines are at the tail of a file
-# show file Last # line, not with line number default display 10 rows
-F Monitors whether a file has new content, primarily for logs (ending with. log) view

5, echo "CCC" >> documents to add CCC to the file

View the last two lines:

[Email protected] var]# Tail-2 11KHLKJL;LHLKJLKL

The contents of the listening file 11 are modified:

Turn on monitoring

650) this.width=650; "title=" QQ browser _20150408152024_87a5963dc14c49c1b68b573c9a223065.jpg "src=" http://s3.51cto.com/ Wyfs02/m00/5d/d1/wkiol1uk2dlz60qyaabweeraanq856.jpg "alt=" Wkiol1uk2dlz60qyaabweeraanq856.jpg "/>

Adding content to file 11 in another pseudo terminal

[[email protected] var]# echo "Khlkhouoi 123214" >> 11[[email protected] var]#

Monitoring results

650) this.width=650; "title=" QQ browser _20150408152242_a1b1cd60af9042f2aef83e3744ddcf43.jpg "src=" http://s3.51cto.com/ Wyfs02/m01/5d/d5/wkiom1uk102ikzd-aab6ewbwr64628.jpg "alt=" Wkiom1uk102ikzd-aab6ewbwr64628.jpg "/>

6, head    options     file name        See how many lines the header of a file
                 -#                  Show file Header # line, not with line number default display 10 lines

[[email protected] var]# head -3  11uuhgfgfugyulsssoo99999f[[email protected] var]# cat -n 11      1 uu     2 hgfgfugyu     3       4 hhkljhl      5 khij lkjl '       6 khll     7      8       9 lsssoo99999f    10 kljlkjl     11  hhljljl    12 khlkjl;l    13 hlkjlkl     14 aadfsdf    15 khlkhouoi 123214///defaults to 10 rows [[email protected]  var]# head 11uuhgfgfugyuhhkljhl khij lkjl ' Khlllsssoo99999fkljlkjl 

7. Delete Files: RM format: RM option file name
-F Force Delete (Force: mandatory)
-R Recursive Delete file, can delete directory
-I display prompt (default)

Force Delete command:

[[email protected] var]# LS11 cc dd EE lleoaoi88789afa[[email protected] var]# RM 11rm:remove regular file ' 11 '? Y[[email protected] var]# rm-f cc[[email protected] var]# LSDD ee Lleoaoi88789afa

Recursive Delete command (the directory MML contains the file ss):

[Email protected] var]# LSDD ee lleoaoi88789afa mml[[email protected] var]# rm-r mmlrm:descend into directory ' MML '? Yrm:remove regular file ' Mml/ss '? Yrm:remove directory ' MML '? Y[[email protected] var]# LSDD ee Lleoaoi88789afa

-I is the default value and can be viewed through the type command:

[[Email protected] var]# type RMRM is aliased to ' rm-i '

8. Copy files: CP format: CP option source files (files, directories) target files (files, directories)
(1, the source file is a file, if the target file does not exist to create a file, its content is the same as the source file, if the target file is overwritten 2, the source file is a file, if the target file is a directory (must exist), the contents of the source file is placed in the directory 3, the source file is a directory, You must use the option to copy the directory to the target directory)
CP option source files (files, directories) target files (files, directories)
-r copy directory, recursive replication is implemented
-d Copy the destination file to the soft connect file itself, not its pointing to the file
-A =-r+-d
-I hints whether to overwrite
-F Mandatory (not recommended)

Recursive replication:

[Email protected] ss]# mkdir mml/ee/cc[[email protected] ss]# cp-r mml/ee/cp:overwrite ' ee/mml/cc '? Y[[email protected] ss]# CD Ee/[[email protected] ee]# LSMML

The source file is a file and the destination file does not exist:

[[email protected] var]# lsdd  ee  lleoaoi88789afa  mml   ss[[email protected] var]# cp dd cc[[email protected] var]# lscc   dd  ee  lleoaoi88789afa  mml  ss[[email protected]  var]# cat dd  420  cat -n bb  421  head  -10 history >> cc  422  history |head -10   423  history |head -10 >> dd  424  ls  425   cat dd  426  cat -n dd  427  cat -n  aa  428  cat -n bb  429  history |tail -10  >dd[[email protected] var]# cat cc  420  cat -n bb   421  head -10 history >> cc  422  history |head -10   423  history |head -10 >> dd  424  ls   425  cat dd  426  cat -n dd  427  cat  -n aa  428  cat -n bb  429  history |tail  -10 >dd

The source file is a file and the destination file exists:

[[email protected] var]# cat EE ls:cannot access ff:no such file or Directory[[email protected] var]# cp ee CCCP:OVERWR Ite ' CC '? Y[[email protected] var]# cat Ccls:cannot access ff:no such file or directory

The source file is a file and the destination file is a directory:

[[Email protected] var]# CD Ss[[email protected] ss]# Lsmml[[email protected] ss]# CD. [[email protected] var]# CP cc Ss[[email protected] var]# CD Ss[[email protected] ss]# LSCC MML

The source file is a directory and the destination file is a directory:

[[email protected] var]# mkdir mml ss[[email  protected] var]# lsdd  ee  lleoaoi88789afa  mml  ss[[ email protected] var]# cd mml[[email protected] mml]# ls[[email  Protected] mml]# vim cc[[email protected] mml]# lscc[[email protected]  MML]# CD&NBSP, .... [[EMAIL PROTECTED] VAR]# CP -R MML SS[[EMAIL PROTECTED] VAR]# CD  ss[[email protected] ss]# lsmml[[email protected] ss]# cd mml[[email  PROTECTED] MML]# LSCC 

9, move file:mv    format:mv    options     source file    destination file
                                                     -i        Display Prompt
                                                   -f         force move (not recommended)

[[Email protected] var]# mv cc mml/[[email protected] var]# ls mml/cc[[email protected] var]# type MVMV is aliased to ' MV -I. '

10. Linux redirection (input and output) and pipelines
Output: Standard output (correct output) usually marked with 1
Error output is usually marked with 2
Input: Standard input 0
Redirect: Change the input and output display form
Output >> Append form, display the output to the following file or directory
The form of > Coverage
The above is the default standard output: 1 >> If you want to redirect the error, use: 2 >>
Input << exit input when the following is entered, display content
Pipeline: | The output of one command as input to the next command
Form Command 1| Command 2| Command 3 command 1 is required by command 2, command 2 is required by command 3, command 3 is what we need

Eg: The first 10 lines of the output history [[email protected] var]# history |head -10    1   vim /etc/selinux/config     2  iptables -L     3  service iptables stop    4  vim / etc/sysconfig/network-scripts/ifcfg-eth0     5  service network  restart    6  ifconfig    7  init 0     8  ls    9  type   10  ls  type redirect the first 10 rows of the history to the new file DD (not overwritten) [[email protected] var]# history |head -10  >> dd[[email protected] var]# ls11  aa  bb  cc   dd  lleoaoi88789afa  llowe2345llda[[email protected] var]# cat  dd    1  vim /etc/selinux/config     2  iptables -l     3  service iptables stop    4  vim /etc/sysconfig /network-scripts/ifcfg-eth0     5  service network restart     6  ifconfig    7  init 0     8  ls    9  type   10  ls  Type re-directs the history after 10 rows to DD, (overwrite) [[email protected] var]# history |tail -10 >dd[[ email protected] var]# cat dd  420  cat -n bb  421   head -10 history >> cc  422  history |head  -10  423  history |head -10 >> dd  424   ls  425  cat dd  426  cat -n dd  427  cat -n aa   428  cat -n bb  429  history |tail -10 >dd## The contents of the DD file have been changed # #将错误的内容输出 [[EMAIL&NBSP;PROTECTED]&NBSP;VAR]#&NBSP;LS&NBSP;FFLS:&NBSP;CANNOT&NBSP;ACCESS&NBSP;FF:  no such file or directory[[email protected] var]# ls ff 2 >> ee[[email protected] var]# cat eels: cannot access ff:  no such file or directory# #ff文件不存在, so ls ff will error, want to put this wrong information display file EE ##    &NBSP;&NBSP;&NBSP;&NBSP;TR: Format conversion, conversion is a form of     eg:echo ddd2bb tr   "2"    "S"      display: Dddsbbeg: Converts the numbers in the above file DD to a[[email protected] var]#  cat dd | tr  "0-9"   "a"   aaa  cat -n bb  aaa   head -aa history >> cc  aaa  history |head -aa  aaa   History |head -aa >> dd  aaa  ls  aaa  cat  dd  aaa  cat -n dd  aaa  cat -n aa   aaa  cat -n bb  aaa  history |tail -aa >dd



File Management 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.