Linux Foundation--bash Basic Application and File System foundation commands

Source: Internet
Author: User
Tags aliases egrep

(i). Command aliases

Alias is used to get the definition of aliases available to the current user

[[email protected] ~]# aliasalias cp= ' cp-i ' Alias egrep= ' Egrep--color=auto ' Alias fgrep= ' Fgrep--color=auto ' Alias grep= ' grep--color=auto '

Definition alias: ~]# alias Name= ' COMMAND ' (life cycle: current shell process)

Undo alias: ~]# Unalias NAME

Note: If the alias and command name are the same, call the original command directly, non-alias: You can use "\command"

[[email protected] ~]# alias cls= ' Clear ' [[email protected] ~]# unalias cls[[email protected] ~]# \ls$ Anaconda -ks.cfg m_q rootfs textfile22016-03-04-10-27-51 initial-setup-ks.cfg n_p text12016-03-05-14-09-21 m_p

(ii). Command history

View all recorded history commands
[Email protected] ~]# history
See the 10 most recent history commands
[[Email protected] ~]# history 10
Execute order 10th in the history list
[Email protected] ~]#!10
Executes the last command in the history list that begins with Echo
[Email protected] ~]#!echo
Delete the 10th command in the history list
[Email protected] ~]# history-d 10
Appends the current buffered history row to the history file
[Email protected] ~]# history-a
Clear History list
[Email protected] ~]# history-c
Read all unread rows from the history file
[Email protected] ~]# history-n
Reads the history file and appends the contents to the History list
[Email protected] ~]# History-r

Command history-related environment variables

[Email protected] ~]# echo $HISTSIZE 1000[[email protected] ~]# echo $HISTFILESIZE 1000[[email protected] ~]# echo $HISTFIL E/root/.bash_history[[email protected] ~]# echo $HISTCMD 733[[email protected] ~]# echo $HISTCONTROLignoredups

Control how the Command history is recorded: Histcontrol has three kinds of value representation

Ignoredups: Ignoring duplicate commands; Repetition is a sequential and identical command; Ignorespace: A command that begins with a blank character is not recorded in history; Ignoreboth: The two are in effect at the same time;

(c). Shortcut keys

CTRL + A: Jump to the beginning of the command line, Ctrl+e: Jump to the end of the command, CTRL+K: Delete the cursor to the tail of the content; Ctrl+u: Delete the beginning of the line to the cursor where the content; Ctrl+w: Delete a word (not English word, but a continuous string separated by a space);

(iv). Command completion and path completion

The shell can be complete by the TAB key, not unique identification, click Tab again to give the list

[Email protected] ~]# Whiwhich while whiptail [[email protected] ~]#/etc/grgroff/grub.d/

(v). Command line expansion

~: Automatically replaced with the user's home directory;

~username: Automatically replaces the home directory for the specified user;

Example: [[email protected] ~]# Mkdir-pv/etc/rootfs/{bin,sbin,lib,lib64,tmp,usr}mkdir: Created directory "/etc/rootfs" mkdir: Directory created "/etc /rootfs/bin "mkdir: Directory Created"/etc/rootfs/sbin "mkdir: Directory Created"/etc/rootfs/lib "mkdir: Directory Created"/etc/rootfs/lib64 "mkdir: Directory Created "/etc/rootfs/tmp" mkdir: The Directory "/ETC/ROOTFS/USR" was created

Directory Management class Commands:

mkdir (recommended directory):

[[email protected] ~]# Mkdir-pv/tmp/abcdmkdir: Created directory "/TMP/ABCD"

-M,--mode=mode: Directly given directory permissions;

RmDir (delete directory):

[[email protected] ~]# rmdir-pv/tmp/abcdrmdir: Deleting directory "/TMP/ABCD" rmdir: Deleting directory "/tmp" RMDIR: Delete directory "/tmp" failure: Directory Non-empty

(vi). Execution status results of the command

[[email protected] ~]# echo $ (date +%h:%m:%s) 22:13:06[[email protected] ~]# echo ' date +%h:%m:%s ' 22:13:24[[email protecte D] ~]# Echo $?0

(vii). References in bash

[[email protected] ~]# echo ' $SHELL ' (' strong quote ') $SHELL [[email protected] ~]# echo "$SHELL" ("" weak reference)/bin/bash[[email protected] ~]# echo ' echo ' $SHELL ' (' Command Reference) $SHELL

① File View command:

The More:more command is similar to cat, which displays pages in a page-by-page format, press space to page down, and press B to page back.

The document contents of Testfile are displayed starting from line 20th. More +20 Testfile

Less:less is similar to more, but with less you can browse files at will, and more can only move forward, but not back, and no will load the entire file before viewing it.

View command history usage records and display via less paging [[email protected] test]# | Less 1 ls 2 mount/dev/cdrom/mnt 3 ls 4 cd/nt 5 cd/mnt 6 ls 7 CD PACKAGES/8 ls

Head: View the first 10 lines of the file by default;-N 5: View the first 5 rows;

[[Email protected] ~]# history |head-n 5 1 ls 2 mount/dev/cdrom/mnt 3 ls 4 cd/nt 5 cd/mnt

Tail: View the following 10 lines of the file by default;-N 5: View the following 5 rows;

Look at the bottom line 5th:

[Email protected] ~]# history |tail-5 680 man Tail | Tail-5 681 Man Tail | Tail-5 |tail 1 682 man Tail | tail-5 |tail-1 683 man Tail | Tail-5 |head-1 684 |tail-5[[email protected] ~]# history |tail-5 | Head-1 681 Man Tail | Tail-5 |tail 1

Start: Display inode content

View the Inode content content of the Text2 file [[email protected] ~]# stat text2 file: "text2" Size: 0 Block: 0 IO block: 4096 plain empty file device: fd00 h/64768d inode:206363417 Hard Link: 1 permissions: (0644/-rw-r--r--) Uid: (0/root) Gid: (0/root) Environment: Unconfined_u:object _r:admin_home_t:s0 last visit: 2016-03-05 14:18:26.985156998 +0800 Last modified: 2016-03-05 14:16:59.502151869 +0800 Recent Changes: 2016-03-05 14:16:59.502151869 +0800 creation Time:-

Touch: Change the file or directory time, and create a file if there is no file;

[email protected] ~]# Touch Testfile | Ls-l Testfile-rw-r--r--. 1 root root 0 March 6 17:04 testfile

② File Management tools:

CP: Copy the file, if the target file does not exist, then create the file beforehand, then copy the content import;

[Email protected] ~]# ll/etc/text2-rw-r--r--. 1 root root 66 March 5 22:12/etc/text2[[email protected] ~]# cp/etc/text2-if/tmp/text2 |LL/TMP/TEXT2CP: Overwrite "/tmp/text2 "? -rw-r--r--. 1 root root 66 March 6 17:12/tmp/text2y Other usage: Man CP

MV: Move an existing file or directory, or change the name of a file or directory,

MV FileName File name Change the source file name to the target file name
MV FileName Directory Name To move a file to the destination directory
MV Directory name Directory name The destination directory already exists, and the source directory
Move to the target directory;
Rename if directory does not exist
MV Directory name File name Error
If you move all files and directories under/usr/student to the current directory, the command behaves: $ mv/usr/student/*.

RM: Delete a file or directory.

    • -I ask for confirmation before deleting.

    • -F Even if the original file attribute is set to read-only, it is deleted directly without confirmation.

    • -R the directory and the following files are also deleted.

Note: Please do not perform "RM-RF/" or "RM-RF/*"

(eight). File name Wildcard

Displays all numbers in/etc that begin with E, K, M, and finally the file details that end with. conf: [[email protected] ~]# ls-l/etc/[ekm]*[[:d igit:]]*.conf-rw-r--r--. 1 root root 6 2015/etc/e2fsck.conf-rw-r--r--. 1 root root 495 Mar 6 2015/etc/krb5.conf-rw-r--r--. 1 root root 936 Mar 6 2015/etc/mke2fs.conf
Common wildcard characters: *: matches any character of any length;?: matches any single character; []: matches any single character in the specified set; [^]: matches any single character outside the specified set; other usage: Man 7 glob

(ix). variables

Bash is a weakly typed programming language, and all of the variables in bash are default to character data and can be used directly without prior declaration.

Bash Variable type:
Local variable: scope is the current shell process, excluding its child processes;
Environment variables: Use the domain as the current shell process and its child processes;
Local variables: Scopes are functions that define this variable;
Positional parameter variables
Special variables

Local variable declarations and references:

[Email protected] ~]# Name=wangqiang[[email protected] ~]# echo $namewangqian

Undo variable: unset name; (PS: All local variables are automatically revoked when the shell process terminates)

environment variable declaration and reference:

[[email protected] ~]# Name=wangqiang[[email protected] ~]# echo $namewangqiang [[email protected] ~]# Export view environment variables Command: Export,declare-x,env,printenvdeclare-x name= "Wangqiang" [[email protected] ~]# unset name

Read-Only variables: constants (shell termination, variable termination), no re-assignment is supported, and undo operations are not supported;

[Email protected] ~]# declare-r myvar= "How is it?" [Email protected] ~]# readonly myvar= "How is it?" [Email protected] ~]# readonly declare-r myvar= "How is it?"

(10). I/O redirection and piping

Input data flow: <--, standard input (stdin) file descriptor is 0 output data stream:-->, standard output (stdout) file descriptor is 1 Error data stream:--> standard error Output (stderr) file descriptor 2

Standard output redirection:

[Email protected] tmp]# echo "How IS Is?" > Demo #覆盖 [[email protected] tmp]# echo "How is old is you?" >> dem o #追加

Standard Error Output redirection:

[Email protected] tmp]# echoooo "How is it?" 2> demo #覆盖 [[email protected] tmp]# echoooo "How is old is you?" 2>> Demo #追加

Merge standard output with standard error output:

[Email protected] tmp]# echo "How IS Is?" &> demo #覆盖 [[email protected] tmp]# echo "How is old is you?" &&G t;> demo #追加或者 [[email protected] tmp]# echo "How is You?" > Demo 2>&1 #覆盖 [[email protected] tmp]# Echo "How old is You?" &>> Demo 2>&1 #追加

Standard input redirection:

[Email protected] ~]# TR [A-z] [a-z] </etc/issue\skernel \ r on a \mmage education learning serviceshttp://www. Magedu.com

Here Document:

Cat << EOF >/tmp/issue.doc\skernel \ R on \mmage education learning serviceshttp://www.magedu.comeof

Pipeline:

[Email protected] ~]# Cat/etc/issue | tee/tmp/$ (Date +%y%m%d%h%m%s)


Linux Foundation--bash Basic Application and File System foundation commands

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.