Sixth day _linux Basic command use method

Source: Internet
Author: User
Tags aliases syslog

Linux Format

command [parameters] [path file]

rm-rf/etc/passwd


# Linux/All directories are in the directory/below

# Wow path starting from the root directory

# called relative path starting at current position

Shortcut keys

Tab Completion command best hit two times Ctrl + C terminate foreground run program Ctrl+d exit Current Environment Ctrl + a jump to the front history view historical record! + History line number execute command! s command above the first letter


1,mkdir Creating a directory

2,ls View list file information

3,CD Switching directories




mkdir Create a file directory Linux Create folder

[[email protected] ~]# mkdir/data/#可以同时当前目录创建多个 [[email protected] ~]# mkdir 1 2 3[[email protected] ~]# LS1 2 3 Anacon Da-ks.cfg Install.log install.log.syslog#-p recursive creation [[email protected] ~]# mkdir-p/data/www/log[[email protected] ~]# ll/ data/www/log/-ddrwxr-xr-x. 2 root root 4096 Jan 1 19:02/data/www/log/


LS View list file

[[email protected] ~]# lsanaconda-ks.cfg install.log install.log.syslog#-l column form details [[email protected] ~]# ls-ltotal 40-r W-------. 1 root root 1069 Jan 1 03:25 anaconda-ks.cfg-rw-r--r--. 1 root root 23040 Jan 1 03:25 install.log-rw-r--r--. 1 root root 6240 Jan 1 03:24 install.log.syslog#-ld Show directory properties [[email protected] ~]# ls-ld/data/drwxr-xr-x. 2 root root 4096 Jan 1 18:58/data/[[email protected] ~]# lsanaconda-ks.cfg install.log install.log.syslog


CD Switch Directory

#pwd See the current decision path (where I am) [[email protected] ~]# cd/data/www/log/[[email protected] log]# PWD/DATA/WWW/LOG#CD. /switch to parent directory [[email protected] log]# CD. /[[email protected] www]# PWD/DATA/WWW#CD-Switch to the last directory [[email protected] www]# CD-/data/www/log[[email protected] log]# p WD/DATA/WWW/LOG#CD ~ Switch home directory [[email protected] log]# CD ~[[email protected] ~]# pwd/root


Touch Create text file

[[email protected] log]# Touch Aa.txt[[email protected] log]# lsaa.txt


VI Edit file (editor in Linux)

[[Email protected] log]# VI aa.txta or I start editing text q! Do not modify forced exit wq! Forced postponement


Cat View File Contents

[email protected] log]# cat Aa.txt AABBCC


echo Print Output command

> redirect the output from the front to the back will overwrite the information (empty the original content)

>> Append does not overwrite information

<< input information into the previous file

[[email protected] log]# echo aaaa[[email protected] log]# touch bb.txt# write bb.txt and overwrite all information inside [[Email bb.txt] Log ]# echo "Hell Bb.txt" > bb.txt [[email protected] log]# cat bb.txt hell bb.txt# append Hello bb.txt to bb.txt [email Protec Ted] log]# echo "Hello bb.txt" >> bb.txt [[email protected] log]# cat bb.txt Hell Bb.txthello bb.txt# There is also a way to write [[Emai L protected] log]# cat >> aa.txt <<EOF> aa> bb> cc> eof[[email protected] log]# cat Aa.txt AABBCC


CP Copy File

#拷贝1/cc.txt  to/data/www/log/[[email protected] ~]# cp 1/cc.txt /data/www/log/[[ Email protected] ~]# ll /data/www/log/total 8-rw-r--r--.  1 root root  11 jan  1 19:18 aa.txt-rw-r--r--.  1 root root 25 jan   1 19:15 bb.txt-rw-r--r--.  1 root root  0 jan  1  20:41 cc.txt# Copy Files directory   add r# copy 2 directories   under/data/www/log/[[EMAIL&NBSP;PROTECTED]&NBSP;~]#&NBSP;CP  -r 2 /data/www/log/[[email protected] ~]# ll /data/www/log/total  12drwxr-xr-x. 2 root root 4096 jan  1 20:41 2-rw-r--r--.  1  root root   11 jan  1 19:18 aa.txt-rw-r--r--.  1  Root root   25 jan  1 19:15 bb.txt-rw-r--r--.  1 root  root   &nBsp;0 jan  1 20:41 cc.txt 


MV moving files or files directory

[Email protected] log]# LS2 aa.txt bb.txt cc.txt[[email protected] log]# mv *.txt./2/[[email protected] log]# ll 2/to Tal 8-rw-r--r--. 1 root root Jan 1 19:18 aa.txt-rw-r--r--. 1 root root Jan 1 19:15 bb.txt-rw-r--r--. 1 root root 0 Jan 1 20:41 cc.txt-rw-r--r--. 1 root root 0 Jan 1 20:41 dd.txt


RM Delete command-RF do not prompt to delete all

[[email protected] log]# ls2[[email protected] log]# rm-rf 2[[email protected] log]# Ls[[email protected] log]#



grep filtering

[email protected] log]# cat aa.txt 112233[[email protected] log]# cat Aa.txt | grep "11" 11

| The previous command output of the pipeline can be used for multiple | Pipelines in the back processing line

#排除11显示内容 [[email protected] log]# grep-v aa.txt 2233# display content by line [[email protected] log]# grep "one" Aa.txt 11


SED command

#过滤出来11 [[email protected] log]# sed-n/11/p aa.txt 11# except 11 all display [[email protected] log]# sed/^11/d aa.txt 2233


awk filtered out 11

[Email protected] log]# Awk/11/aa.txt 11

Head Display before tail display

Head-n aa.txt-n (number of rows) display the first few lines

Tail-n aa.txt-n (number of rows) shows the number of end lines

[[email protected] log]# seq >> aa.txt [[email protected] log]# head-3 aa.txt 123[[email protected] log]# Tai L-3 Aa.txt 9899100


To view the location of a command

[email protected] log]# which Cpalias cp= ' cp-i '/bin/cp[[email protected] log]#



View aliases

[[email protected] log]# which cpalias cp= ' CP  -i '         /bin/cp[[email protected] log]# alias  alias cp= ' cp -i ' alias l.= ' ls -d .* --color=auto ' alias ll= ' ls -l  --color=auto ' alias ls= ' ls --color=auto ' alias mv= ' mv -i ' alias rm= ' rm -i ' Alias which= ' alias | /usr/bin/which --tty-only --read-alias --show-dot -- Show-tilde ' [[email protected] log]# alias aa= ' echo  ' hello.com. ' [[Email protected] log]# aahello.com. [[email protected] log]# alias aa= ' cat  '/etc/sysconfig/network-scripts/ifcfg-eth0 '  [[email protected] log]# aa 
Device=eth0hwaddr=00:0c:29:5a:7e:03type=ethernetuuid=0a75fde7-0364-4b2c-bfa0-73c28aa36930onboot=yesnm_ Controlled=yesbootproto=dhcp

Unalias Canceling aliases

[[email protected] log]# unalias aa[[email protected] log]# Aa-bash:aa:command not found

All of these are temporary. Modify the configuration file for permanent entry

[[email protected] log]# Cat ~/.BASHRC #. bashrc# User specific aliases and Functionsalias rm= ' rm-i ' Alias cp= ' Cp-i ' Alias mv= ' mv-i ' # Source global definitionsif [-F/ETC/BASHRC]; Then. /etc/bashrcfi


Find File

[[email protected] log]# Find/-type f-name "Cat"/bin/cat

Find a file to delete

Find/-type F-name "Cat"-exec rm-rf {}\;find/root/-type f-name "*.log"-mtime-5 rm-rf {}\; #查找 root modified log all deleted in 5 days Except


SEQ Command

#输出 1-2[[email protected] log]# seq 212# output 5-8[[email protected] log]# seq 5 85678# Line show 1+2+3+4+5[[email protected] log]# s Eq-s "+" 51+2+3+4+5# display data upside down [[email protected] log]# SEQ 1 5 | tac54321


View 30-35 Head Tail method

[Email protected] log]# head-35 aa.txt | tail-6303132333435

Show 20-30 lines sed awk method

[[email protected] log]# sed-n 30,35p aa.txt 303132333435[[email protected] log]# awk ' {if (nr>29&&nr< () print $} ' aa.txt 303132333435NR rows to show row count


View the last five elements of/etc/passwd first column

[[email protected] log]# awk-f ":" ' {print $} '/etc/passwd | Tail-5saslauthpostfixsshdtcpdumpoprofile[[email protected] log]#


SED Replace command

[[email protected] log]# echo "Linux" >> bb.txt [[email protected] log]# cat bb.txt Linux put bb.txt file l Inux change to Windows[[email protected] log]# sed-i s#linux#windows#g bb.txt [[email protected] log]# cat Bb.txt windows[[email p Rotected] log]#


Change windows for all bb.txt files to Linux

[[email protected] log]# Find/-type f-name "Bb.txt"/data/www/log/bb/bb.txt/data/www/log/bb.txt[[email protected] log] # Find/-type f-name "Bb.txt" | Xargs sed-i s#windows#linux#g[[email protected] log]# Find/-type f-name "Bb.txt" | Xargs Cat Linuxlinux
Xargs the output (FIND/LS) to the back to perform the SEQ print digit echo {1. 5}{} with echo print sequence man view command how-to help



Author Personal blog: www.021soso.com

Baidu Cloud Disk Search: http://pan.yunpanos.com (Always use the search video tutorial site, so recommend to everyone)


This article is from the "Good Note ops" blog, please be sure to keep this source http://021soso.blog.51cto.com/11045979/1730639

Sixth day _linux Basic command use method

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.