1. Help commands
man 命令
/【要搜索的内容】
The level of man
1 Help for viewing commands
2 viewing Help for functions that can be called by the kernel
3 Viewing the Help for functions and function libraries
4 view Help for special files (mostly files in the/dev directory)
5 Viewing the Help for a configuration file
6 Viewing the game's help
7 See other miscellaneous Help
8 viewing Help for commands available to system administrators
9 viewing and kernel-related files Help
See what level of Help the command has
man -f 命令
Equivalent towhatis 命令
For example man -f passwd
, you will see the passwd
command has a configuration file, so man 5 passwd
you can see the configuration file with Help, whereis passwd
you can see the location of the file
View all commands that contain keywords
man -k 关键字
Equal to apropos 关键字
, as inapropos passwd
2. Aliases and shortcut key viewing and setting aliases
alias
View all command aliases in the system
alias 别名=‘原命令‘
To set the alias of a command
such as alias rm=‘rm -i‘
oralias ll=‘ls -l‘
It's equivalent to setting up a shortcut command, but it's temporarily in effect
Aliases are permanently active and delete aliases
vi ~/.bashrc
Write environment variable configuration file
unalias
Temporarily remove aliases
Common shortcut keys
shortcut Keys |
meaning |
ctrl+c |
Force the current command to terminate |
ctrl+l |
Clear Screen |
ctrl+a |
Cursor moves to the beginning of the command |
ctrl+e |
Cursor moves to the end of the command line |
ctrl+u |
Delete the cursor at the beginning of the row |
ctrl+z |
Put the command in the background |
ctrl+r |
Search in the history command |
3. Common Directory Role
/
root directory
/bin
command to save the directory (normal user can read the command)
/sbin
/usr
System Software Resources Directory
/boot
Start directory, start related files
/dev
Device File Save Directory
/etc
Configuration File Save Directory
/lib
system function Library Save directory
/mnt
System Mount Directory
/media
Mount Directory
/sys
/proc
Save Memory mount point, cannot be manipulated directly
/tmp
Temp directory, storing temporary data
/var
Save system Variable Document directory
/usr
Under the /bin
/sbin
same directory, the same as /
the two directories to save the system command, the /sbin
next command only Superuser can execute
You can leave the contents of the home directory, or the root directory /
, as well as the /tmp
directory under the content, others do not move, but also do not recommend in the root directory, only to put the necessary data
4. Mount commands
Equivalent to the allocation letter in win, except that Linux is called mount
Query and Auto Mount
mount
Querying devices that are already mounted in the system
~ on ~ type ~
This is the structure of the show.
- Such as
/dev/sda5 on / type ext4 (rw)
Which sda5
represents the first SATA hard disk fifth partition, /
which represents this is the root partition, ext4
representing the file system is EXT4, permission is read and write;
- Similarly, the
/dev/sda1 on /boot type ext4 (rw)
first partition that represents the first SATA hard drive is the boot partition, the file system is EXT4, and the permissions are read-write
mount -a
According to the contents of the configuration file /etc/fstab
, all the devices written in this file are mounted once, such as /,/boot,/home,swap
these partitions are in the file, so the system will automatically mount these partitions at each boot
Mount command format
mount【-t文件系统】【-o特殊选项】设备文件名 挂载点
-t 文件系统
Add the file system type to specify the type of mount, you can ext3,ext4,iso9660 the file system
-o 特殊选项
Additional options for mounting can be specified, with various parameters, can be multiple together, separated by commas
Special look at this exec/noexec
, on behalf of the execution/not execution, set whether to allow executable files in the file system, the default is the exec file
For example, to mount -o remount,noexec /home/
re-mount /home
the partition, and do not allow executable files, at this time if you go again ./hello.sh
will show insufficient permissions
5. Shutdown and restart command shutdown command
shutdown 【选项】时间
-c
Cancels the previous shutdown command
-h
Shutdown
-r
Restart
- Use the
date
command to see the system date
shutdown -r 05:30
Indicates a restart at 5:30 A.M., this time into the countdown state, can no longer operate, by ctrl+c
canceling.
- At the end of the add
&
, so that the command in the background, do not occupy the operation interface, two times after the return to continue their operations. If you do not want to execute this command in the background, you can use it shutdown -c
to cancel.
shutdown -r now
Indicates a reboot now.
- Avoid using this command when you telnet to the server!
Other shutdown commands
halt
poweroff
init 0
But none of these three are safe.
Other Restart commands
reboot
More secure
init 6
Not safe
What do the 0 and 6 here mean?
Represents seven levels of system operation
0 Turn off the machine
1 single user, can be regarded as the safe mode in win, used for system repair
2 not fully multi-user, without NFS service (file sharing service)
3 full multi-user, is the black-bottom white character interface
4 Not assigned
5 graphical interface
6 restart
Init means calling a level
Use runlevel
to see exactly at what level the system is running, MAC OS does not support
cat /etc/inittab
Change the system boot default level by locating the fields in the file id:3:initdefault
and modifying the numbers. But it must not be set to 0 and 6.
Exit Login Command
logout
6. Pipeline than characters command sequence execution
Multi-Command executor |
format |
function |
; |
Command 1; Command 2 |
Multiple command order execution, no logical connection between commands |
&& |
Command 1 && Command 2 |
Logical AND, command 1 executes correctly only if command 2 is executed, command 1 does not execute correctly, and command 2 does not execute |
Shift+\shift+\ |
Command 1 shift+\shift+\ Command 2 |
Logical OR, command 2 does not execute when command 1 is executed correctly, and command 2 does not execute when command 1 is executed correctly |
* Which shift+\
means that|
For example, date ; tar -zcvf etc.tar.gz /etc ; date
you can calculate the time-consuming execution of intermediate packed compression commands
Again, the ls && echo yes || echo no
first command executes correctly, output Yes, error execution, output no
Pipe character
Command format: 命令1 | 命令2
, there is a certain programming idea inside the command 1 the correct output as the operand of command 2, and the logic is not the same as
Example:
ls -l /etc | more
Represents ls -l /etc
the output split-screen display
netstat -an | grep ESTABLISHED
Represents netstat -an
a row with established in the search output
If it becomes again netstat -an | grep ESTABLISHED | wc -l
, this is a multi-pipe character command, representing the number of rows with established to the last statistic, you can see how many people are connected on the server
- If
cat
there is a lot of repetition in the content of the output, you can add it to the back |uniq
7. How the script executes the echo output command
echo【选项】【输出内容】
echo "cangls he bols ni xi huan na yi ge?"
double quotes are required as long as there are spaces in the output
Option -e
to indicate support for antisense characters
Echo can support the antisense character (also can be used in Python)
anti-semantic characters |
function |
\a |
Output warning tone |
\b |
Backspace key, that is, delete key to the left |
\ n |
Line break |
\ r |
Enter |
\ t |
tab, which is the TAB key |
\v |
Vertical tab |
\0nnn |
Output characters according to the Octal Ascⅱ code table. Where 0 is a digital zero and NNN is a three-bit octal number |
\xhh |
Output characters according to the hexadecimal Ascⅱ code table. Where HH is a two-digit hexadecimal number |
For example echo -e "\x68\x65\x6c\x6c\x6f"
, to manually enter a hexadecimal Ascⅱ code value for a character, the output ishello
The pure character interface of Linux native is not supported in Chinese!
In addition, in the remote tool interface such as Xshell can support the color display, such as echo -e "\e[1;31m 嫁人就要嫁凤姐 \e[0m"
, which \e[1;31m
is the open color, \e[0m
is the turn off color, 31m
indicating red, can support the color from 30 to 37
First script
vim hello.sh#!/bin/bash#注释echo -e "\e[1;34m 天上掉下个林妹妹 \e[0m"
Script execution
- Give execute permission, invoke script
chmod 755 hello.sh
./hello/sh
#相对路径
- Execute scripts directly from bash
bash hello.sh
8. Historical Command History command
history 【选项】【历史命令保存文件】
Options:
-c
Clear History Command
-w
Write the history command in the cache to the history command to save the file~/.bash_history
The history command saves 1000 by default and can be modified in the environment variable configuration file /etc/profile
HISTSIZE=1000
Invocation of the history command
- Use
上下箭头
to invoke previous history commands
- Using the
!n
repeat nth command
- Use
!!
repeat to execute previous command
- Use
!字串
repeat to execute the last command that starts with the string
Command and file completion
In bash, command and file completion are very handy and common functions we just press the Tab
key to automatically complete the command or file when we enter it.
9. Link Command Link command
ln -s 【原文件】【目标目录】
function is to generate a linked file
-s
Create a soft link
Features of hard links
- Hard links have the same I node and storage block blocks, which can be seen as the same file
- Can be identified by the I node
- Cannot span partitions
- Cannot use for directory
ln desktop/Learning_Python/hello_world.py documents/hello_world.hardls -l desktop/Learning_Python/hello_world.py-rw-r--r-- 2 Jeff staff 3379 3 14 10:30 desktop/Learning_Python/hello_world.pyls -l documents/hello_world.hard-rw-r--r-- 2 Jeff staff 3379 3 14 10:30 documents/hello_world.hardls -i desktop/Learning_Python/hello_world.py documents/hello_world.hard2231081 desktop/Learning_Python/hello_world.py2231081 documents/hello_world.hard
Features of soft links
- Similar to win under the shortcut
- The soft link has its own I node and block blocks, but the data block only saves the original file name and I node number, and there is no actual file data
Irwxrwxrwx
I
the permissions for soft link soft link files arerwxrwxrwx
- Modify any file and the other changes
- Delete original file, soft link cannot be used
10. Command format
[root@localhost ~]#
root
Segment represents the current user, localhost
is the host name
If it is a superuser, the current directory is the /root
root directory, and if it is a normal user user1, the/home/user1
#
Represents the current user bit super user, $
or normal user
Format:命令 【选项】【参数】
Query Directory Contents command
ls 【选项】【目录/文件】
ls -l ~/desktop[email protected] 3 Jeff staff 102 3 8 11:08 $RECYCLE.BINdrwxr-xr-x 6 Jeff staff 204 4 9 16:13 A*算法drwxr-xr-x 10 Jeff staff 340 4 9 16:14 Learning_Python-rw-r--r-- 1 Jeff staff 1441 3 30 11:43 SSH设置-rw-r[email protected] 1 Jeff staff 48640 3 8 11:08 Thumbs.dbdrwxr-xr-x 10 Jeff staff 340 4 9 18:07 myBooksdrwxr-xr-x 10 Jeff staff 340 4 10 11:02 毕业规范-rw-r[email protected] 1 Jeff staff 6313 4 8 21:36 实习小结.md
-l
Show more information
Permissions 10-bit-rw-r—r—
The 1th digit represents the file type:-file d directory l soft link file
rw-
U owner Class
r--
G belongs to group Meimei
r--
O Other people's deputies, silly monks.
r
Read and w
write x
execution
3,6,10 These numbers represent reference counts
102,204,340 These numbers represent the size of the bytes and are converted to ls -lh
KB for easy reading
ls -a ~/desktop$RECYCLE.BIN.DS_StoreLearning_PythonmyBooks..localizedSSH设置毕业规范..A*算法Thumbs.db实习小结.md
-a
Show all files, including hidden files
-la
Show all files in detail
ls -ld ~/desktopdrwx------+ 12 Jeff staff 408 4 10 17:07 /Users/Jeff/desktop
-d
Show Directory Properties
-ld
Show directory properties in detail
If the directory does not have W permissions, even if the file has write permissions, you can not move the file, rename the operation, at this time, you need to add the directory W permissions: chmod +w
(note that the CWD is this directory)
Linux Basics (1-10)