Linux Basic Operations (cont.)

Source: Internet
Author: User

(iv) Operation of directories and files

#mkdir/test//Create a Test directory (folder) under the root directory

#mkdir-P/test/test//Recursive creation of directories (without the Test directory under the previous root), also known as the creation of multi-tier catalogs

#touch file.txt//Create a file.txt file in the current directory

Copy the/test/file.txt file to the/test/test folder #cp/test/file.txt/test/test//Copy file

#rm/test/file.txt//delete file.txt file

#rm-R/test/test//delete Test directory, need to add "–r" before

# rm-f/test/file.txt//Force Delete file no confirmation required

#mv/test/file.txt/test/test//move file.txt file to/test/test folder

#mv/test/file.txt/test/test/file01.txt//move file.txt file to/test/test folder and rename to File01.txt

#cat/test/file.txt//view File.txt file contents (mainly for small files)

#more/test/file.txt//view file.txt file contents Space Press ENTER to turn down a line of space bar is turned down a screen turned back to the original

#less/test/file.txt///Also view file contents press ENTER to turn down a line of space bar is down the page with more different things can be used up and down the front of the content to view the page is completed will not automatically jump press "Q" will return to the original interface

# Tail/test/file.txt//View the last 10 lines of a file

#head/test/file.txt//View 10 lines of the beginning of a file

#tail-N 3/test/file.txt//View the last 3 lines of the file

#head-N 3/test/file.txt//view the first 3 lines of the file (change the number of rows viewed by changing the number)

# wc-l/test/file.txt//View the number of lines of file contents

#ls –l/root >/test/file.txt//Writes the contents of the "ls–l/root" command to/test/file.txt (the contents of the original file are deleted) (This command is called a redirect)

#ls –l/root >>/test/file.txt//Append the contents of the "ls–l/root" command to/test/file.txt (the contents of the original file are not deleted)

#grep word/test/file.txt//Search out the/test/file.txt file containing "word" for each line and display it

#grep Word--color/test/file.txt//Search out the/test/file.txt file containing "word" for each line and display it, highlighting the search keywords

#grep word-v/test/file.txt//Search out every line in the/test/file.txt file that does not contain "word"

#grep word-i/test/file.txt//Search out each line in the/test/file.txt file that contains "word", ignoring case

#grep ^word/test/file.txt//Search out every line in the/test/file.txt file that begins with "word"

#grep word$/test/file.txt//Search out every line in the/test/file.txt file that ends with "word"

Fifth section vim text editor

The Tips:vim text editor is equivalent to a Notepad program under Windows

(1) Three modes of vim text editor

Command mode: When a file is opened with the VIM command, entering the text is the command mode

Input mode: can be edited

Last-line mode: Implement Find-replace-save, equivalent to the menu bar of Notepad under Windows

(2) Detailed instructions

A inserts a character after the cursor

A move the cursor to the line and end into insert mode

I insert a character before the cursor

I move the cursor to the beginning of the line and into insert mode

o Insert a new line under the cursor

O insert a new line on the cursor

Input mode/last row mode--Return to command mode

ESC key

Command mode--Enter the last line mode

: Save exit

:/ Look down

:? Look up

: W Save

: Q exit

: Wq Save and exit

: X Save and exit

ZZ Save and exit (Command mode)

:! Forced

: Save W file as

: R file Read in

:!cmd Execute external command

: X sets the password for the file

Cursor movement

Up or down key

Page

PgDn = Ctrl +f

PgUp = Ctrl +b

Cursor in line jump

Home Key ^ 0 move to beginning of line

End key $ move to line tail

Cursor between rows jumps

1G file Header

G File Line End

NG file N rows

Copy, paste, delete (Command mode)

YY copies the current cursor in the row

NYY copy current cursor down n rows

P Paste

x = Del key deletes the current cursor character

DD deletes the current cursor in the row

NDD Delete current cursor down n rows

d^ Delete the current cursor to the beginning of the line

d$ Delete the current cursor to the end of the line

String Lookup undo (last-line mode)

/world backwards to find the string world

World Search up String world

n/n n look for N.

U Undo Last Action

U Undo Current line so action

CTRL +r Anti-undo

String lookup substitution (last-line mode)

: S/old/new replaces the current line the first old is new

: S/old/new/g replaces the current line all old is new

: n,m s/old/new replace N-m row The first oldold is new

:%s/old/new/g Replace file all old is new

:%S/OLD/NEW/GC Pre-Replacement confirmation

Switch settings

: Set Nu|nonu Display/Cancel line number

: syntax on|off enable/disable syntax highlighting

: Set Hls|nohls Enable/disable highlighting of query results

: Set autoindent| No autoindent Enable/disable auto indent

Permanently set the above switch

# VIM ~/.VIMRC//Open config file

Set Nu

Set Autoindent

Set Nohls

Linux Basic Operations (cont.)

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.