Directory and file Management (ii)

Source: Internet
Author: User

Today we continue to explain the directory and file management, this time to explain the common directory and file management commands and basic use, if you want to learn more about the parameters of the system command and usage please check the Linux command in detail, you can also use the man to see more ways to use the command.

I. Viewing the contents of a file

    • Cat Displays the full contents of the file
-n或-number:有1开始对所有输出的行数编号;-b或--number-nonblank:和-n相似,只不过对于空白行不编号;-s或--squeeze-blank:当遇到有连续两行以上的空白行,就代换为一行的空白行;-A:显示不可打印字符,行尾显示“$”;-e:等价于"-vE"选项;-t:等价于"-vT"选项;
[root@localhost ~]# cat shopping.txt coffee    29car   120000ipone     6000banana    17apple     30dog   300
    • More Paging view
-<数字>:指定每屏显示的行数;-d:显示“[press space to continue,‘q‘ to quit.]”和“[Press ‘h‘ for instructions]”;-c:不进行滚屏操作。每次刷新这个屏幕;-s:将多个空行压缩成一行显示;-u:禁止下划线;+<数字>:从指定数字的行开始显示。
    • Less paging view
-b 《缓冲区大小》 设置缓冲区的大小-e 当文件显示结束后,自动离开-f 强迫打开特殊文件,例如外围设备代号、目录和二进制文件-g 只标志最后搜索的关键词-i 忽略搜索时的大小写-m 显示类似more命令的百分比-N 显示每行的行号-o 《文件名》 将less 输出的内容在指定文件中保存起来-Q 不使用警告音-s 显示连续空行为一行-S 行过长时间将超出部分舍-x 《数字》 将“tab”键显示为规定的数字空格
    • Head view the beginning of the file
-n<数字>:指定显示头部内容的行数;-c<字符数>:指定显示头部内容的字符数;-v:总是显示文件名的头信息;-q:不显示文件名的头信息。
    • Till viewing the end of a file
--Retry: That is, when the tail command starts, the file is inaccessible or the file becomes inaccessible later, always trying to open the file. This option needs to be used with the option "--follow=name";-c<n> or--bytes=<n;: n(integer) byte contents of the tail of the output file;-f<name/descriptor> or--follow<nameldescript>: Displays the latest additions to the file. "Name" means that the file changes are monitored in the form of file names. "-F" is equivalent to "-fdescriptor";- F: same function as option "-follow=name" and "-retry"; -n<n> or--line=<n;: The end of the output file n(n -bit number) line content. --pid=< process number;: With the "-f" option, when the specified process number process terminates, the tail command is automatically exited;-Q or--quiet or--silent: When there are multiple file parameters, do not output each file name;-s< seconds > or--sleep-interal=< seconds;: In conjunction with the "-F" option, specify the number of seconds to monitor the file changes;-V or--verbose: when there are multiple file parameters, always output each file name;--help: Display the help information of the instruction;--version: Displays the version information of the instruction. 
    • WC Statistics Command
-c或--bytes或——chars:只显示Bytes数;-l或——lines:只显示列数;-w或——words:只显示字数。
    • grep filtering commands
-a Do not omit binary data. - A< Show columns > displays the contents of the row, in addition to the row that conforms to the template style. -B Displays the line that matches the template style, and displays the contents before the row. -C calculates the number of columns that conform to the template style. - C< show columns > or-< Displays the number of columns > In addition to displaying the column that conforms to the template style, and displays the contents before the column. -d< Action > When you specify that you want to find a directory rather than a file, you must use this parameter, otherwise the grep command returns information and stops the action. -e< Template Style > Specify a string as the template style for finding the contents of a file. - E uses the template style as an extended normal notation, which means that extended regular expressions can be used. -f< Template File > Specify a template file with the contents of one or more template styles so that grep finds the content of the file that conforms to the template criteria, formatted as a template style for each column. - F treats the template style as a list of fixed strings. - G Use the template style as a normal notation. -h does not indicate the name of the file to which the column belongs until it displays the column that conforms to the template style. - H before displaying the column that conforms to the template style, indicate the file name of the column. -I-hu character case difference. -l lists file names that match the file contents to the specified template style. - L lists file names that do not conform to the specified template style. -n indicates the column number before displaying the column that conforms to the template style. -Q does not display any information. - R/-r The effect of this parameter is the same as specifying the "-D recurse" parameter. -s does not display an error message. -v Reverse lookup. -W displays only the columns that match the whole word. -x displays only the columns that are eligible for all columns. -y This parameter effect is the same as "-I". -o output only the portion of the file that matches. 

Ii. Compression and Archiving commands

    • gzip command
 -9 高压缩 -d 解压缩 
    • bzip2 command
 -9 高压缩 -d 解压缩  注解:以上两个命令只能压缩文件  不能压缩目录

Tar archive command

-c:创建 .tar 格式的包文件-x:解开.tar格式的包文件-v:输出详细信息-f:表示使用归档文件-p:打包时保留原始文件及目录的权限-t:列表查看包内的文件-C:解包时指定释放的目标文件夹-z:调用gzip程序进行压缩或解压-j:调用bzip2程序进行压缩或解压

Third, Text editor (Vi)
1) Command mode:

Start the VI Editor by default into the command mode, the main completion of the mode such as cursor movement, string lookup, and delete, copy, paste the contents of the file and other related actions

2) Input mode:

The main operation in this mode is to enter the contents of the file, you can modify the text file body, or add new content. When in input mode, the last line of the VI editor appears "–
insert– "Status Tip information

3) last line mode:

In this mode, you can set the VI editing environment, save the file, exit the editor, and find and replace the contents of the file. The last line of the VI editor appears with a colon ":" Prompt when in last-row mode

    • Common operations
Type of operation Operation Keys Function
Move Cursor Direction ?、?、?、? Up, down, left, right
Page Page down or ctrl+f Flip a full page of content
Page up or Ctrl+b Flip up a full page of content
Quick Jump in line Home key or "^", number "0" Jump to beginning of line
End key or "$" key Jump to end of line
Quick Jump between rows 1G or GG Jump to the first line of a file
G Jump to the end of the file line
#G Jump to line # in a file
Line number Display : Set Nu Display line numbers in the editor
: Set Nonu Cancels the line number display in the editor
Delete X or Del Delete a single character at the cursor
Dd Deletes the current cursor in the row
#dd Delete the # line content that starts at the cursor
d^ Delete all characters before the current cursor to the beginning of the line
d$ Delete all characters at the end of the line at the current cursor
Copy Yy Copy the contents of the entire row of the current row to the Clipboard
#yy Copy the # line content starting at the cursor
Paste P Pastes the contents of the buffer after the cursor position
P Before pasting at the cursor position
———-
Operation Keys Function
/word Look up the string "word" from the top down in the file
? word Bottom find the string "word" in the file
N Locate the next matching found string
N Locate the previous matching found string
U Press Cancel the most recent operation multiple times repeatedly press the U key to resume a multi-step operation
U Used to cancel all edits made to the current line
Zz Save the current file contents and exit the VI editor
: E ~/install.log Open a new file for editing
: R/etc/filesystems Read other file contents into the current file
Command Function
: s/old/new Replace the first character "old" string found in the current line with "new"
: s/old/new/g Replace all the string "old" found in the current row with "new"
: #,# s/old/new/g Replace all strings "old" with "new" in the line number "#,#" range
:% s/old/new/g Replace all strings "old" with "new" for the entire file range
: s/old/new/c Adding the C command at the end of the Replace command will prompt the user for each substitution action to confirm
Function Command Note
Save File : W Save current changes only, do not exit
: W/root/newfile Save As other file
Exit VI : Q Exit not modified
: q! Discard changes to the contents of the file and Exit VI
Save File Exit VI : Wq Save and exit

This time we wrote here, VI is a very powerful text editing tools, want to learn more about the partners than Baidu and the man to learn it!!!

Directory and file Management (ii)

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.