Linux Shell Programming Basics

Source: Internet
Author: User
Tags echo display sorts disk usage

In the process of learning Linux BASH Shell programming, it is found that many things are easy to forget because they are not used very often, so write an article to record

LS Displays the files under the current path, commonly used have-l show long format -A shows all the contents including hidden-R display folder -C according to the most Last modified time -T sorts output by modified time

echo Display-n No Line break

Touch to create a file, or to modify the access time and modification time of a file touch -A file only changes the access time-m change the actual that-T specify a specific time

CP Copy FILE-a reserved file's properties -f Force Copy, overwrite if present -I presence overwrite prompts -r Copy all existing contents in folder-U only source Replication in case of file updates

MV Move and rename MV A b move the a file to the path of B

RM Delete-I when prompted-R to delete directory and Content-F does not prompt

File View Files Type

Cat View File Contents

More view file contents, pause after full page, space and Z next page d lower half Q exit

The less-enhanced version of more B can flip back and you can turn back half a page

Tail display the contents of the following rows tail-f can dynamically refresh the most commonly used tail-n specify the number of rows

Head displays the contents of the first few lines, corresponding to the tail

PS Display process PS aux view all processes commonly used to display more, generally with the pipeline to find

Top real-time monitoring process command U view process of a user K end specified process Q exit

Kill PID End Process kill-9 pid forced end

Killall process name does not enter the PID directly to enter the process name to end the process

Mount mount mount-t Type device directory type is a disk type device that is a devices file directory is a mount address that is often used by fdisk-l to find the address of the appliance and then mount

Umount uninstalling the Unload mount point or device file if a program is in use, you cannot uninstall the lsof to see which processes are in use

DF View Disk Usage

Du view the disk usage of files in that particular directory is generally du-h intuitive

Sort sorts sort-n Sort by number-R reverse order

Cut split cut-f1-d ': ' By: Split, take first column

Grep search general mate pipeline using Cat Tt|grep number-n Add line number-C there are several matching

Tar compression and decompression is commonly used in tar and tar.gz files package TAR-CVF unpacking TAR-XVF for tar.gz packaging TAR-ZCVF unpacking TAR-ZXVF

Export takes the variable as an environment variable, and wants the restart to not disappear, it can be written in the user's home directory. Bash_profile, written in/etc/profile is valid for all users

unset Deleting environment variables

Array= (1 2 2 3 4) Enclose in parentheses as an array ${array[*]} displays the number of all ${#array [*]}

Useradd Add User-U specify uid-g specify group name or GID userrm Delete user usermod modify password passwd modify own password related files/etc/passwd/etc/shadow

Groupadd Add Group groupmod Modify Group GROUPRM Delete group related files/etc/group

chmod modify file Permissions chmod 666 a.sh Each number represents RWX permissions The first number is the one with the second is the group the third is the other, 666 is the right to write and execute for everyone

Chown Modify File Owner chgrp modify file belongs to group

Fdisk Disk Management tool

Yum Download installation tool general Yum install XXX view installed packages Yum List installed uninstall Yum remove xxx thoroughly uninstall yum erase xxx

RPM Install RPM package similar to Yum features

Date dates are generally used with date +%y%m%d

Who view user information

Double quotes enclose the information in the string, except for the escape character \ Single quotation mark and the $ variable

Reverse quotation marks the text in which it is executed as a command

Single quotation marks all the things in them as characters

> Output redirect override >> output redirect Append

< input redirection

| The output from the front of the pipeline as the back environment

$[] do mathematical operations that only support integers

BC specifically not described, support for decimal operations

$? The result of running the previous command is 0 successful

Exit 0 script exits and returns status code

The IF statement is structured according to the following

if command;then    xxxxxxfiif  command;then    xxxxxxelif  command; then    xxxxxxx Else     Xxxxxxxfi

Test because if validation can only be a command, so the introduction of test [$a-gt $b] in square brackets can be used as a judgment condition, for the file is [-F "$file"] where F is the file E is present d is a folder, etc.

Judge string only [$str 1 = $str 2] = = = > <-z-n

(()) double parentheses support sharper arithmetic operations such as + +--* * & | [[]] supports sharper string comparisons, such as regular expressions

Case command

 Case  inch AAA) xxxxxxxxx;; BBB) xxxxxxxxx;; *)    xxxxxxxxx;; Esac

For loop control while loop control until loop control is relatively simple, do not repeat

Break N exits the N-layer loop continue back to the N-layer loop

Read read input-P followed by prompt read-p "Please input A and B" a B reads the user input and exists in a B-n specifies the time-out

Local temp declares temporary variable temp in function

$ $ $ #参数数量 $ $ $. Nth parameter $* all parameters as an [email protected] all parameters

Shift move forward parameter

CTRL + Z Pause current task

CTRL + C Exit task

Ctrl+d End Input

At specifies the command run time ATQ view an existing ATRM delete

CRON Specifies the command run cycle

Currently write so much first, used to add in the

Linux Shell Programming Basics

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.