Linux basic Commands (i)

Source: Internet
Author: User
Tags diff syslog

Today we will work with you to learn the commands of the basic command line inside the Linux system.

1. The composition of the command is basically divided into command words + options + parameters
2. Command word: Common basic commands
3. Option: Make a detailed distinction between the command words
(1) long option: Format (--plus one or more words)
(2) Short option: Format (-plus one letter, where multiple letters can be written together)
4. Parameters: Who is acting on the command
5. Note that most of the options and parameters can be flipped in order, some parameter formats are dead only: command word + options + parameters

Let's see some examples.
1.CD + path (must be a directory at the end, otherwise it will be an error)
(1) CD in my opinion CD is like a navigation, as long as you can tell me where you want to go, CD can help you finish.
(2) CD + ENTER (this is a direct switch to the current user's home directory is generally used ~ to indicate that the root user is/root, the other users placed in the/home/user name)
(3) CD +-(return to previous directory)
(4) CD +. (Return to the previous level of the directory)
(5) Add here. The role of (. Represents the current directory and can also be used. + executable file)

 [[email protected] ~]# ./1.sh 1

2. Path
(1) Relative path: only applies to the current directory (the head can not add/)
(2) Absolute path: Acting on all directories (header to add/)

3.pwd + ENTER
(1) PWD (shows which path you are currently under, is displayed as an absolute path)

4.ls
(* supplement) Ls-r (view multi-level catalogs) Ls-b (see Special characters: spaces, for example)

(1) LS + ENTER (default display of files in the current directory)

[[email protected] ~]# ls1    2.c              ha                  log                                  scriptfifo  tining.LOG                 zabbix-3.0.41.c  anaconda-ks.cfg  install.log         mariadb-10.0.20-linux-x86_64.tar.gz  sun.txt     zabbix-3.0.0alpha2         zabbix-3.0.4.tar.gz2    file_sum.md5     install.log.syslog  output.session      -----(2)ls + a(显示当前目录下的所有文件包括隐藏的文件,隐藏文件一般是以  .  开头的文件)

[Email protected] ~]# ls-a
. 1.sh. bash_history. CSHRC install.log.syslog output.session. SSH

Tining. LOG zabbix-3.0.0alpha2.tar.gz
.. 2

(3) Ls-l (column display details, due to the frequent use of this command so Ls-l set an alias, using the same effect as LL)

[[email protected] local]# ls -ltotal 48drwxr-xr-x.  2 root root  4096 Sep 23  2011 bindrwxr-xr-x.  2 root root  4096 Sep 23  2011 etc以空白作为分隔对应的意思分别是 (权限,硬链接数,拥有者,所属组,文件大小-字节,日期,文件/目录名)

(4) Ls-t (display files in a time-based manner)

[[email protected] local]# ls -lattotal 56drwxr-xr-x. 14 root root  4096 Apr 16 15:06 .lrwxrwxrwx.  1 root root    29 Apr 16 15:06 mysql -> mariadb-10.0.20-linux-x86_64/drwxr-xr-x. 12 root mysql 4096 Apr 16 15:06 mariadb-10.0.20-linux-x86_64drwxr-xr-x.  6 root root  4096 Apr 16 14:01 zabbix-serverdrwxr-xr-x. 13 root root  4096 Apr 11 22:41 ..drwxr-xr-x.  5 root root  4096 Apr 11 22:41 sharedrwxr-xr-x.  2 root root  4096 Sep 23  2011 bin

(5) LS-LH (humanized display file size)

[[email protected] local]# ls -lhtotal 48Kdrwxr-xr-x.  2 root root  4.0K Sep 23  2011 bindrwxr-xr-x.  2 root root  4.0K Sep 23  2011 etc

(6) Ls-ld + directory name (displays information about the directory itself)

[[email protected] local]# ls -ldh src/drwxr-xr-x. 2 root root 4.0K Sep 23  2011 src/

(7) Supplement (if the command item does not know how to use the command item +--HELP, out of the help information is in English, you can also set the Chinese font)

(8) Touch + file name (create a new file, you can also modify the file's timestamp) (* supplemental): (Touch "can contain special characters" created is a file)

[[email protected] local]# touch dajiahao[[email protected] local]# lsbin  dajiahao

(9) Stat + File/directory name (similar to Windows right-click property)

[[email protected] local]# stat dajiahao   File: `dajiahao‘  Size: 0           Blocks: 0          IO Block: 4096   regular empty fileDevice: 802h/2050d  Inode: 915067      Links: 1Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)Access: 2018-04-18 12:12:51.850001341 +0800Modify: 2018-04-18 12:12:51.850001341 +0800Change: 2018-04-18 12:12:51.850001341 +0800

(Ten) Touch-a file name (modify file timestamp)

[[email protected] local]# touch -a dajiahao [[email protected] local]# stat dajiahao   File: `dajiahao‘  Size: 0           Blocks: 0          IO Block: 4096   regular empty fileDevice: 802h/2050d  Inode: 915067      Links: 1Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)Access: 2018-04-18 12:16:29.883002668 +0800Modify: 2018-04-18 12:12:51.850001341 +0800Change: 2018-04-18 12:16:29.883002668 +0800

Access: Visit time, Modify: Content modification Time, change: File modification time
(one) touch-c file (do not create this file, mostly in script)
Touch file File ..... (Create multiple files)

[[email protected] boke]# touch a b c[[email protected] boke]# lsa  b  c

Touch {1..5} (create 1-5, 5 files.) {} Both sides can add letters, text, numbers)

[[email protected] boke]# touch {1..5}[[email protected] boke]# ls1  2  3  4  5  a  b  c

RM + file (delete file, original command should be prompt to delete file rm-i, alias alias is made here, so directly with the prompt RM delete)

[[email protected] boke]# ls1  2  3  4  5  a  b  c[[email protected] boke]# rm arm: remove regular empty file `a‘? y[[email protected] boke]# ls1  2  3  4  5  b  c

[[email protected] boke]# 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‘(15)rm -f + 文件(不带提示的删除文件)

[[email protected] boke]# ls
1 2 3 4 5 b C
[Email protected] boke]# Rm-f b
[[email protected] boke]# ls
1 2 3 4 5 C

(16)rm -r(递归删除或者删除目录都可以)

[[email protected] boke]# ls
1 2 3 4 5 C Mulu
[Email protected] boke]# tree mulu/
mulu/
├──1
└──2

1 directory, 1 file
[Email protected] boke]# RM-RF mulu/
[[email protected] boke]# ls
1 2 3 4 5 C

(17)rm + 通配符(?代表一个字符??代表两个字符--没有包含关系,*代表全部。)

[[email protected] boke]# Touch 123 1234
[[email protected] boke]# ls
1 123 1234 2 3 4 5 C
[Email protected] boke]# rm-f???
[[email protected] boke]# ls
1 1234 2 3 4 5 C
[Email protected] boke]# rm-f????
[[email protected] boke]# ls
1 2 3 4 5 C
[Email protected] boke]# Rm-f *
[[email protected] boke]# ls
[Email protected] boke]#

(18)mkdir + 目录名(创建目录)

[Email protected] boke]# mkdir a B
[[email protected] boke]# ls
A a1b b c2d

(19)mkdir -p 目录名/目录名...(递归创建目录)

[Email protected] boke]# mkdir-p A/C/D
[Email protected] boke]# tree A
A
└──c
└──d

2 directories, 0 files

(20)rmdir 空目录(只能删除空目录)

[Email protected] boke]# RmDir a
rmdir:failed to remove ' a ': Directory not empty
[Email protected] boke]# rmdir a/c/d/
[Email protected] boke]# tree A
A
└──c

1 directory, 0 files

(21)cp + 文件名+目录/文件(如果最后的cp目标为目录,那么文件会存放到该目录下,如果是文件,里面的内容会被覆盖:这个会有提醒)

[email protected] boke]# CP a1b/opt/
[Email protected] boke]# cd/opt/
[[email protected] opt]# ls
A1B RH

(22)cp -pr(-r 递归复制或目录复制)(-p  保留原属性)

[Email protected] boke]# CP-PR a/opt/
[Email protected] boke]# CD-
/opt
[[email protected] opt]# ls
A A1B RH
[Email protected] opt]#

(23)mv 文件/目录(移动或者修改名称)

[Email protected] opt]# MV a C
[[email protected] opt]# ls
A1B C RH
[Email protected] opt]# MV A1B-
[Email protected] opt]# CD-
/usr/local/boke
[[email protected] boke]# ls
A a1b b c2d
[Email protected] boke]# MV c2d/opt/
[Email protected] boke]# CD-
/opt
[[email protected] opt]# ls

    • C C2D RH
      (24)mv 1目录/1文件  2目录/2文件  (移动并改名,同理cp亦可以做到)

      [Email protected] boke]# mv/opt/-C
      [[email protected] boke]# ls
      A a1b b C
      [Email protected] boke]# CD-
      /opt
      [[email protected] opt]# ls
      C C2D RH
      [Email protected] opt]#

      (25)scp + 用户@ip/域名:文件/目录 + 路径(远程复制,可跨系统相互传输,亦可以作为中间人scp+机器1 机器2,可以做免密,亦可

With the hand two machine password, if the contents of the transmission directory SCP back to add-R, this SCP works based on the SSH protocol)
(+) Cat/tac + file (positive/Flashback view small file)

[[email protected] boke]# cat /etc/hosts127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4::1         localhost localhost.localdomain localhost6 localhost6.localdomain6[[email protected] boke]# tac /etc/hosts::1         localhost localhost.localdomain localhost6 localhost6.localdomain6127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4

More + large files (view large files, spaces for the display of the next page, enter to show the next line, b display the previous page, Q or Ctr+c exit)
(+) less + large file (Operation method and more connected, more than more a search function, press/In the back to follow the content you are looking for, will be highlighted)
Head-n lines + large files (default output file first 10 lines, customizable)
(10) Tail-n lines + large files (default output file at the end of the line, can be customized, tail-f for real-time viewing)
echo + content > Files (Echo has the ability to create files,> This is the overwrite file content,>> This is the Append file content)

[[email protected] boke]# echo 1 > file[[email protected] boke]# cat file 1[[email protected] boke]# echo 2 > file [[email protected] boke]# cat file 2[[email protected] boke]# echo 3 >> file [[email protected] boke]# cat file 23

grep + keyword + file (filter file content contains all lines of the keyword)

[[email protected] boke]# grep root /etc/passwd --color (这里我是6.5系统所以,加了一个--color长选项,7系统不用)root:x:0:0:root:/root:/bin/bashoperator:x:11:0:operator:/root:/sbin/nologin

grep + ^ keyword $ + file (filtered by line at the beginning or end of the keyword)

[[email protected] boke]# grep ^root /etc/passwd --colorroot:x:0:0:root:/root:/bin/bash

(cut-d):-f1,6 + file (cut is used to intercept the column after-D if you follow the non-legal characters must be added "",-f followed by the number, multi-line, separate)

[[email protected] boke]# cut -d: -f1,6 /etc/passwdroot:/rootbin:/bindaemon:/sbinadm:/var/admlp:/var/spool/lpd

(35) | (| pipeline, the output of the previous command is the input of the latter command, the pipeline can be used, but must obey order)

[[email protected] boke]# cut -d: -f1,6 /etc/passwd | grep ^root root:/root

Sort (default to 26 English letters, which is the ACII code)
-R Descending Sort
-N Number size sorting (small-large, 1-10)
-U rejects duplicate rows
-K Specify a column
-T delimiter
(Panax Notoginseng) Uniq + file (excluding duplicate lines, but I have tried here, you can also comment after the test)
(+) diff + file + file (This is a comparison of two similar files, diff will show a different place)

    [[email protected] boke]# uniq file 2o32o3[[email protected] boke]# vim file1[[email protected] boke]# cat file2o32o3[[email protected] boke]# cat file1 2[[email protected] boke]# diff file file12,4d1< o3< 2< o3
(39)wc +目录/文件(目录/文件统计)          -l  只显示行                    -w 只显示字节                    -c 只显示大小
[[email protected] boke]# ll |wc -l8[[email protected] boke]# ll |wc       8      65     328[[email protected] boke]# ll |wc -w65[[email protected] boke]# ll |wc -c328

Well, let's share this with you today, I will continue tomorrow.

Linux basic Commands (i)

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.