First, what is the Bash shell
BashShell is a command interpreter, which in the outermost layer of the operating system, the user program and the kernel is responsible for interactive operation, an interface to translate commands input by the user to the operating system, and outputs the processed result to the screen.
When we use the remote connection tool to connect linux service, the system will open a default shell, we can execute this command interface, such as: obtaining the current time, create a user, etc.
Second, what do Bash shell?
Using the Shell management to achieve most of the Linux system, such as:
- Document Management
- authority management
- User Management
- Disk Management
- Network management
- Software Management
- and many more
Three, Bash shell implementation
Enter the command mode ---> inefficient ---> for a small amount of work
shell script ---> high efficiency ---> for complex work
Fourth, understand the Bash shell
Bash ---> GNU/Bash
[root@www ~]# bash -version
GNU bash, version 4.2.46(2)-release (x86_64-redhat-linux-gnu)
Bash is the default shell, in fact, still with a lot of other shell, such as: csh, sh, etc.
Five, shell prompt
$ = Average user, # = root user (super administrator)
[root@xuliangwei ~]# whoami
root
[root@www ~]# echo $PS1
[\u@\h \W]\$
root: the current user logged into the system
Host name of the current system: www
~: Current location
: Under normal circumstances, a super administrator of
symbol
Command line bash shell, to provide users enter, execute the command interface
Command options parameters
command [-options] [arguments]
[root@xuliangwei ~]# ls #命令
[root@xuliangwei ~]# ls -a #命令+选项
[root@xuliangwei ~]# ls -a /home/ #命令+选项+参数
The entire body shell command: Command
Options: specific functions for adjusting the command
#以 “-”引导短格式选项(单个字符),例如“-a”
#以“--”引导长格式选项(多个字符),例如“--all”
#多个短格式选项可以写在一起,只用一个“-”引导,例如“-al”
Parameters: Object command operations, such as files, directory name, etc.
Note: The options and parameters at the time when some commands, the location may change.
Note: The command must start, options and parameters may change position
Error examples:
[root@www ~]# ls-a
bash: ls-a: command not found... 找不到命令(要么命令写错了,要么就真的没有该命令)
[root@www ~]# ls /.bashrc
ls: cannot access /.bashrc: No such file or directory 没有这个文件或目录
Six, Bash shell features
- Tab key completion support
Options command completion completion completion parameters
Command completion: press the tab key and nothing happens, because at the beginning of the command has many user, the system does not know which one you need to use
[root@www ~]# user
useradd userdel userhelper usermod usernetctl users
Path completion: / etc / sysconfig / network-scripts / ifcfg-ens32
- bash shell commonly used shortcut keys
ctrl + a cursor to jump to the head of the Bank
ctrl + e cursor jumps to the Bank tail
ctrl + u is deleted from the cursor to the beginning of all characters
ctrl + k delete all characters from the cursor to the end of the line
ctrl + l clear screen You can also use the clear command
ctrl + c to terminate the current task
ctrl + d exit the server, or may be used logout exit
content before ctrl + w remove the cursor from the space
ctrl + z suspend the current task
ctrl + r search command,
ctrl + s screen lock, unlock ctrl + c [ignore]
Ctrl + direction key word in accordance with a fast jump cursor, tools provided XshellNo symbol: Note (not on behalf of the Executive)
- History history
history commands directly view the command currently being executed in the shell
! 100 call history history command numbered 100
! ! Executing a command executed
Options
Options | description |
---|---|
-w | Save command history to the history file write # to write the current user's home directory .bash_history |
-c | Clear command history, does not clear the file clear |
-d | History delete command to delete the N-th row |
Esc +. Gets the parameters on a command
例子:
保存命令历史到历史文件
[root@liyang-98 ~]# history -w
查看历史记录
[root@liyang-98 ~]# history
1 uname -n
2 man hostname
...
清除历史记录
[root@liyang-98 ~]# history -c
[root@liyang-98 ~]# history
1 history
删除第二行历史记录
[root@liyang-98 ~]# history
1 history
2 ls -al
3 history
[root@liyang-98 ~]# history -d 2
[root@liyang-98 ~]# history
1 history
2 history
3 history -d 2
4 history
- Command aliases alias
1, how to set the alias
[root@liyang-98 ~]# alias ifnet='vi /etc/sysconfig/network-scripts/ifcfg-ens32'
[root@liyang-98 ~]#
[root@liyang-98 ~]# ifnet
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens32
UUID=251eb6ed-4bf8-4144-acd1-653f7fa3e908
DEVICE=ens32
ONBOOT=yes
"/etc/sysconfig/network-scripts/ifcfg-ens32" 20L, 357C
2, how to cancel the alias
[root@liyang-98 ~]# unalias ifnet
[root@liyang-98 ~]# ifnet
-bash: ifnet: command not found
3. Why there are some default aliases:
Prevent danger during execution of instructions, misoperation occurs, such as: alias rm = 'rm -i'
Note: The current aliases are all to take effect for the current Shell, a temporary effect.
4. The permanent extension {}
The contents are written to / etc / bashrc all shell take effect
5. Command Help --help man
[root @ www ~] # ls --help
Usage: ls [option] ... [file] ...
Common options for ls
Options | description |
---|---|
-a | To view all files in a directory, including hidden files |
-i | Show details of files by way of long form |
-h | Display content humane manner, with the use -l |
-d | Only list a directory name, the contents of the directory are not listed below |
-t | Sort by modification time |
-i | inode number displayed document |
例子:
1、显示当前目录下所有文件
[root@liyang-98 ~]# ls -a
. anaconda-ks.cfg .bash_logout .bashrc .pki
.. .bash_history .bash_profile .cshrc .tcshrc
2、以长格式显示当前目录下所有文件
[root@liyang-98 ~]# ls -al
total 28
dr-xr-x---. 3 root root 147 Mar 29 10:52 .
dr-xr-xr-x. 17 root root 224 Mar 28 17:17 ..
-rw-------. 1 root root 1440 Mar 28 17:18 anaconda-ks.cfg
-rw-------. 1 root root 1088 Mar 29 14:53 .bash_history
-rw-r--r--. 1 root root 18 Dec 29 2013 .bash_logout
-rw-r--r--. 1 root root 176 Dec 29 2013 .bash_profile
-rw-r--r--. 1 root root 176 Dec 29 2013 .bashrc
-rw-r--r--. 1 root root 100 Dec 29 2013 .cshrc
drwxr-----. 3 root root 19 Mar 29 10:52 .pki
-rw-r--r--. 1 root root 129 Dec 29 2013 .tcshrc
3、以人性化的方式显示内容
[root@liyang-98 ~]# ls -lh
total 4.0K
-rw-------. 1 root root 1.5K Mar 28 17:18 anaconda-ks.cfg
4、只列出/etc目录的名字
[root@liyang-98 ~]# ls -d /etc
/etc
5、按修改时间进行排序
[root@liyang-98 ~]# ls -alt
total 28
-rw-------. 1 root root 1088 Mar 29 14:53 .bash_history
dr-xr-x---. 3 root root 147 Mar 29 10:52 .
drwxr-----. 3 root root 19 Mar 29 10:52 .pki
-rw-------. 1 root root 1440 Mar 28 17:18 anaconda-ks.cfg
dr-xr-xr-x. 17 root root 224 Mar 28 17:17 ..
-rw-r--r--. 1 root root 18 Dec 29 2013 .bash_logout
-rw-r--r--. 1 root root 176 Dec 29 2013 .bash_profile
-rw-r--r--. 1 root root 176 Dec 29 2013 .bashrc
-rw-r--r--. 1 root root 100 Dec 29 2013 .cshrc
-rw-r--r--. 1 root root 129 Dec 29 2013 .tcshrc
6、显示文件的inode
[root@liyang-98 ~]# ls -li
total 4
67158083 -rw-------. 1 root root 1440 Mar 28 17:18 anaconda-ks.cfg