Important commands in Linux Essentials section

Source: Internet
Author: User
Tags parent directory

This is a summary of the first 14 lessons of the l005-old Boys ' effectiveness education-operation and Basic command exam explaining.

Command:

Basic form

command [parameters] [path or file]

Example: Ls-ld/data

pwd Current directory

1 [[email protected]/]# pwd2 /

mkdir Creating a directory command

1  as 2 [[email protected] tmp]# ls 3  as  Lkj.txt  oldboy.txt  yum.log

ls-ld displaying a list of directories or files

1 [[email protected] tmp]# ls-ld244096:56  .

CD [path] toggles the directory hierarchy. CD. For the current directory. Cd.. As the parent directory.

1 2

touch [file] to create a file

1 123 . txt 2 [[email protected] tmp]# ls 3 123. txt as    lkj.txt  oldboy.txt  yum.log4

vi [file] Create a notepad if the file does not exist, create a new file

1 123. txt

cat [file] view file contents

1 123 . txt 2 lkj

echo Prints the output, and double quotation marks if there are spaces in the words that need to be printed.

1 " Hello " 2 Hello

If you overwrite a single line of text into a file, you can use ">" but the original content will be emptied. Be careful to use

123"like"123 123. txt like

If you do not want to overwrite the original content, you want to append ">>" at the end

123"like"123123.txt lkjlike

CP [path file] [path] copy (copy) can only copy files cannot copy the directory, if you want to copy the directory with the-A or-R parameter.

1 [[email protected]/]# cp-a/io/tmp/2 [[email protected]/]# ls/tmp/3123. TXT as    io  lkj.txt  oldboy.txt  yum.log

mv [File path] [path] moves, you can move files or move folders.

RM Delete (remove) Delete folder to add parameter-R Force Delete to delete the specified directory and file with-F-FR

1 [[email protected]/]# rm/tmp/123.txt2 [[email protected]/]# rm-r/oi
   
    3 [[email protected]/]# rm-f/tmp/
    123.
    txt
    4 [[email protected]/]# Rm-fr/oi
   

*grep-v [specify character] [file] to filter the line of the specified character in the file.

1 321  2Liyun3Lichaoran4Wangyanhua5 [[email] Protected]/]# grep-v li/3216 Wangyanhua

If you do not add-V, the line that you select characters is displayed.

1 [root[email protected]/]# grep li/321.    txt2Liyun3 Lichaoran

head header, which can also be used to search for specific content in a file.

1 [[email protected]/]# head-23212Liyun3 Lichaoran 4 # #显示前两行, if no number defaults to the first 10 rows

*sed to take a variety of content, the function is very powerful.

 1  [[email protected]/]# sed-n/li/p  .txt  2  liyun  3  lichaoran  4  ##-n to cancel the original output without- 5  # #p为print print, print rows containing Li  6  # #搜索的关键字要放在 //  Middle, such as/li/ on top 
1 321  2Liyun3Liyun4Lichaoran5Lichaoran  6Wangyanhua7 # #如果不加-N, prints out and copies the contents of a row
1 321  2Wangyanhua3

mkdir-p Loop to create a folder, recursive creation.

1 [[email protected]/]# mkdir-p/1/2/3/4/5

Tree, which displays the folders under a folder.

1 [[email protected]/]# tree/1/2 /1/324     3  5         46             57840 files

alias aliases; 1) by adding a protection parameter to a dangerous command, you can prevent accidental operation. 2) turn a lot of strings into a simple string or command.

1[[Email protected]/]# alias2Alias cp='cp-i'3Alias l.='ls-d. *--color=auto'4Alias Ll='ls-l--color=auto'5Alias ls='ls--color=auto'6Alias mv='mv-i'7Alias rm='rm-i'8Alias Which='alias |/usr/bin/which--tty-only--read-alias--SHOW-DOT--show-tilde'9# #默认的别名

As above, the default Cp-i alias is cp,-i as the parameter that prompts for confirmation, and if I is not required, you can use Unalias.

1 [[email protected]/]# Unalias CP
# #但是在重启后失效.

Default alias location Cat ~/BASHRC This can be permanently modified.

Find [path]-type (type) f (file)-name (name) "Cat" (file name) Lookup

Read more about this Weibo blog. Http://www.cnblogs.com/lcrbg/p/5301795.html

           Find can also query the specified address directory 5 days ago

1 " *.log " -mtime +5

This is Ntime time diagram, must understand, otherwise will be wrong.

Xargs by line, multi-mate pipe "|" Use (for the time being so understood, later added)

1 321. Txt|xargs rm-f
# #查找/tmp/directory 321.txt file, the name is deleted by row, if there is no xargs is not correct because the search is output by row, without adding xargs is wrong.

seq sequence (sequence) prints a sequence of numbers.

1 6 2 1 3 2 4 3 5 4 6 5 7 6

Across the beat. (spaces in quotation marks, or other symbols, for each digit interval)

1 " " 6 2 1 2 3 4 5 6

Which view the path to the command Whereis,locate,find

1 [[email protected]/]# which CP2 alias cp='cp-i' C18>3         /BIN/CP

Something else besides the command.

Cp
If you do not want to prompt for confirmation protection under commands such as copy move delete, you need to add "\" to the command before

1 [[email protected]/]# cp/tmp/test.txt/mnt/2# #会提示 3 [[email protected]/]# \CP/TM p/test.txt/mnt/4 # #不会提示
5 [[email protected]/]#/bin/cp/tmp/test.txt/mnt
6 # #另一种方法, the exact location of the command see the which command above

Symbol

; Delimiter for multiple commands
/root or path delimiter
> Standard output redirection (data flow in the direction of the arrow) overwrites the original file
>> Follow-up orientation (data flow in the direction of the arrows), then the "End" of the original file append content
< or < standard input redirection: Input redirection is used to change the input of the command, specifying the input, followed by the file name.
<< or << input redirection: followed by a string to denote ' input end ' or ctrl+d to end the input.
.. Parent Directory
. Current directory
^ Beginning for example sed/^oldboy/d test.txt Delete the line at the beginning of the Oldboy in Test.txt show up
~ User's Home directory
| Pipe, the left command output to the right of the pipe to the right to execute, no space on both sides of the pipe

Little Tricks

View 20-30 lines of a file, how do I view it?

We use SED, we can also use head and tail (but cumbersome)

1  - 321. txt

Important commands in Linux Essentials section

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.