editing, compressing, archiving, and manipulating Linux files

Source: Internet
Author: User
Tags bz2 dmesg

One, the file content operation (/ETC/PASSWD)

1. Cat View file content is relatively small

2. More can be paginated display

3. Less than more comprehensive

4. Head default display file header 10 line

-N Digital display head n rows

5. Tail Default display end of file 10 lines

-N number shows tail n rows

- F Live View

6. WC Statistics

7. grep outputs the line containing the specified string

- I ignores case

- v take reverse

^root start with root

root$ End With Root

^$ Matching blank lines

- e find multiple keywords, match any of them to output

8. DMESG View boot information

Add:

| The pipeline gives the output of the previous command to the latter command as input

> Write (Erase previous file contents, write new content)

>> Append

# echo XXXXXX As-is in terminal output

Ii. Compression and archiving

1. Gzip

gzip file name compression

gzip-d file name. GZ Uncompressed

2. bzip2

bzip2 file name compression

bzip2-d file name. bz2 Decompression

3. zip

ZIP file name. zip file name compression

Unzip file name. Zip Decompression

- D Specify decompression location

4. Tar Packaging

- C Create a tar package

- Z call gzip

-j Call bzip2

- x unpack the package

- T view

- C Specify decompression location

- F using an archive file

--remove Delete the original file after the package is finished

TAR-ZCF xxx.tar.gz XXX call gzip compression

TAR-JCF xxx.tar.bz2 xxx call bzip2 compression


TAR-ZTF xxx.tar.gz view xxx.tar.gz inside file

TAR-JTF xxx.tar.bz2 view xxx.tar.bz2 inside file


TAR-ZXF xxx.tar.gz decompression xxx.tar.gz

TAR-JXF xxx.tar.bz2 decompression xxx.tar.bz2


Third, use the Vim text editor

1. Three modes

Shell


Command mode


Input mode end-of-line mode

From command mode to input mode:

I insert a null character before the current cursor

o Add a new blank line under the current cursor

From command mode to last line mode:

:

?

/

Return command mode from input mode and last line mode:

ESC key

2. Vim's opening and exiting

(1), vim file If file exists, open file

New file If file does not exist

(2), Flip page

PgUp up a full page of content = Ctrl + b

PgDn down a full page of content = Ctrl + F

(3), in-line jump

^ Move the cursor to the beginning of line character = Home key and number 0

$ to jump the cursor to the line trailing character = End key

(4), the jump between the file line and the row

1g=gg Jump to the first line of the file

G Jump to the end line of the file

#G Jump to the # line of the file (Command mode)

: # Jump to the # line of the file (last line mode)

(5), copy and paste

YY Copies the current cursor in the row

#yy Copy the current cursor down # line

P Paste

Copy in last-line mode: 1,3y copy 1-3 rows

(6), delete operation (in command mode)

X Delete single character at cursor = Del

DD Deletes the cursor in the row

#dd Delete # lines

d^ removed from the cursor to the beginning of the line

d$ Delete from cursor to end of line

(7), string lookup (last-line mode)

/world down Find world

? World looks up for world

N locates the next matched string

N locates the previous matched string

(8), undo Edit

U Cancel the last operation, can be used multiple times

U Cancel last modification of line all operations

CTRL +r recovery using the u command undo operation

J Merges the current row and the next row

(9), Save and exit (press in the last line mode)

: Q exit

: w Save

: Wq Save exit = ZZ =: X

: X Encryption

: wq! Force Save exit

:! Command to execute outside commands in vim

: Save W file as file

: R file read into file

(10), string substitution (last-line mode)

: S/old/new replaces the first character "old" string found in the current row with "new"

: S/old/new/g replaces 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/GC replaces all strings "old" with "new" and alerts each replacement action within the entire file range

(11), the last line mode basic operation

: Set NU|NONU display/Do not display line numbers

: syntax on|off enable/disable syntax highlighting

: Set Hls|nohls Open/close query result highlighting

: Set Ai|noai enable/disable auto indent

: Set tabstop=4 to set the TAB key width to 4 spaces

(12) Other relevant documents

In the Vim ~/.VIMRC file

. filename.swp the cache file during the editing process



One, the file content operation

1, use the Cat command to view/etc/resolv.conf answer: cat/etc/resolv.conf

2, use the more command to view/ETC/MAIL/SENDMAIL.CF answer: MORE/ETC/MAIL/SENDMAIL.CF

3, use the less command to view/ETC/MAIL/SENDMAIL.CF answer: LESS/ETC/MAIL/SENDMAIL.CF

4, compare cat to less differences and features a: When the cat view file content is small, more and lesser can display the file content, but more page forward inconvenient.

5, view the top 5 lines of/etc/passwd answer: Head-n 5/etc/passwd

6, view/etc/passwd 5 line answer: Tail-n 5/etc/passwd

7, view/etc/passwd's 8–12 line A: head-n 12/etc/passwd |tail-n 8

8, how many accounts in the statistical system A: Wc-l/etc/passwd

9, calculate in/etc directory. Number of conf configuration files A: find/etc/-name "*.conf"-exec-type F | Wc-l

10, display the contents of 127.0.0.1 in/etc/hosts answer: grep "127.0.0.1"/etc/hosts

11, displays the contents of/etc/passwd as root a: grep "^root"/etc/passwd

12, displaying the contents of bash ending in/etc/passwd answer: grep "bash$"/etc/passwd

13, remove the empty lines in the/etc/hosts.allow, show the results of a: Grep-v "^$"/etc/hosts.allow

14. Find information on the ETH interface identified by Linux a: DMESG |grep ETH

15, show the contents of/etc/hosts does not start with the # number a: Grep-v "^#"/etc/hosts

16, calculate the number of users using/bin/bash as the login shell answer: grep "bash$"/etc/passwd

17. Find content in/etc/hosts that contains 127.0.0.1 or localhost answer: grep-e "127.0.0.1|localhost"/etc/hosts


Ii. Compression and archiving

1./root content in an easy-to-read property and long format to redirect the results to/root/gztest.txt inside a: ls-lh >/root/gztest.txt

2, compression and decompression of/root/gztest.txt using gzip and bzip2 and zip, respectively. A: gzip gztest.txt bzip2 Gztest.txt

3, pack/etc/mail and compress to/root/mail.tar.gz answer: Tar-zcf/etc/mail-c/root/mail.tar.gz

4, pack/etc/mail and compress to/root/mail.tar.bz2 answer: Tar-jcf/etc/mail-c/root/mail.tar.bz2

5, extract the mail.tar.gz to/tmp, recursively view the contents under/tmp/etc, then delete the/tmp/etc directory

Answer: TAR-ZXF mail.tar.gz-c/tmp ls-r/TMP/ETC rm-rf/tmp/etc

6, extract the mail.tar.bz2 to/tmp, recursively view the contents under/tmp/etc, then delete the/tmp/etc directory

Answer: TAR-JXF mail.tar.bz2-c/tmp ls-r/TMP/ETC rm-rf/tmp/etc

7, view the contents of mail.tar.gz and mail.tar.bz2 files separately

Answer: TAR-ZXF mail.tar.gz | More TAR-ZXF mail.tar.bz2 | More



Third, the use of vim

1, please create a directory named Vimtest in the/tmp directory A: mkdir-p/tmp/vimtesrt

2, enter vimtest This directory answer: Cd/tmp/vimtest

3, copy the/etc/man.config to the bottom of this directory cp/etc/man.config/tmp/vimtest

4, use Vim to open the Man.config in this directory answer: Vim Man.config

5, set the line number in Vim answer: Last line mode: Set Nu

6, move to line 58th, move to the right 40 characters, what do you see in the double quotation marks in the directory? Answer: Command mode 58g/dir/bin/foo

7, move to the first line, and search down the string ' bzip2 ', may I ask what line he is in? Answer: GG/BZIP2 118 lines

8, I want to change the ' lowercase man string ' between 50 and 100 rows to ' uppercase man string ', and if a selection needs to be modified, how can I place an instruction?  If you keep pressing ' Y ' during the selection process, the result will change a few guys in the last line. A: Last line mode 50,100/s/man/man 23

9, after the modification, suddenly back, to recover all, what are the methods? Answer: Always press U

10, I want to copy the contents of the nine lines (containing Manpath_map) from 65 to 73, and post to the last line

Answer: Command mode 65G 9yy G p

11,21 to 42 lines from the beginning of the # symbol I don't want it, how do I delete it?

Answer: Command mode 21G 23DD

12. Save this file as a Man.test.config file name

Answer: Last line mode: W man.test.config

13, go to line 27th, and delete 15 characters, what is the first word that appears? Answer: o

14, add a row in the first line, the line content input ' I am a student ... ' Answer: Command mode 1G a input I am a student ...

15, store and leave. A: Last line mode: Wq


Related Article

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.