1.MBR Partition Partitioning command
fdisk【选项】
If the fdisk -l
current disk information is listed as Representative
Suppose we later added a hard drive that was identified by the system as /dev/sdb
but not partitioned, which is displayed doesn‘t contain a valid partition table
, we can partition it by the following steps:
Fdisk/dev/sdb# Enter partition mode# Enter M to view the command's Help information# Enter N, which represents add a new partition# now pops up two options, a P (primary partition), an E (extended partition)# input P# option, which requires the input of the partition number, the default is 1, the direct enter# pops the first sector option, That is required to set the starting location of the partition, direct enter, that is, the default # popup Last sector option, that is, the need to set the end of the partition, you can incrementally set the size of this partition, such as +2048m, that is, 2G size # Complete the primary partition add # Enter P, view the added partition # input N, select E, add an extended partition, followed by enter, use the default value *# input n, you can see that there is a primary partition, an extended partition, and then on the extended partition on the logical partition, and the logical partition number can only start from 5, Because 1~4 is for the main partition and the extended partition to use the # input L, add a logical partition, such as Give it 2G# Repeat the steps to add a logical partition, select the size of the time directly enter, the rest of the space to give it full # complete partition, You can see that two logical partitions are in the extended partition # At this point if you want to delete a partition, enter D, the input partition corresponding to the partition number, such as 2, the extended partition is deleted, the logical partition is not there, only the primary partition # Last input W, that is, the actual disk partition
2.swap Partitioning
How do I add a swap partition to my hard disk?
- Build a common Linux partition
- Modifying the 16 encoding of a partition type
- Format swap partition
- Enable swap partition
fdisk /dev/sbdp # 打印第二块硬盘的分区信息t6 # 选择最后一个分区作为swap分区L # 查看编码列表,82是swap分区编号82p # 再次查看w # 保存mkswap /dev/sdb6 # 格式化swap分区swapon /dev/sdb6 # 启用swap分区free # 查看swap分区启用状况swapoff /dev/sdb6 # 停用swap分区wq # 保存退出
3.vim Editor operating mode three modes
- Command mode-commands mode
- Insert mode-Input mode
- Last lines mode-bottom line mode (tail line, end line)
vim abc# 按I键进入insert modehello world111111222222333333# 按esc键进入last line mode:wq # 保存退出vim abc # 再次进入文件# 连按两下D键删除第一行,这便是command mode,通过命令直接操作
4.vim Editor's command mode
vim abc
Navigate to First row
vim + abc
Navigate to Tail Line
vim +3 abc
Navigate to the third row, the other numbers sequentially, and if the maximum number of rows is exceeded, the cursor is positioned to the tail line
vim +/xxx abc
Navigate to the first occurrence of XXX line, by pressing the N key to switch back and forth to locate other XXX lines
vim aa bb cc
Create or open multiple files at once, start with the first file, and enter the other file as you type in the bottom row mode :n
, :N
or :prev
go back to the previous file
5. Find
find .
can view all nested files in the current directory
find .|grep .txt
Using pipe breaks
find . -type f
Just want to see the file
find . -type d
Just want to see the directory
find . -type f -exec ls -l ‘{}‘ ‘;‘
Which ‘{}‘
represents the found file
can also be used ack
, from beyondgrep.com
, specific use seehappycasts.net/episodes/26
6. Scripting Specifies the parser
If the first line #!/usr/bin/env bash
of the script specifies bash as the parser, you can also change bash to Python, Ruby, etc.
Statement is a command, a command is a statement
Terminal
$echo "hello"
hello
Script
#!/usr/bin/env python
echo "hello"
Script statements are sensitive to whitespace
Position parameters
$
Which is the positional parameter
For example $peter.sh a.txt b.txt
, the first argument is used, the second one, the $0
$1
third one $2
, and so on
The statements in the script are not executed in the current shell
$ lsbin Desktop happygrep mydir peter.sh$ ls mydir/$ vim peter.sh#!/usr/bin/env bashcd /home/peter/mydirtouch a.txt$ ./peter.sh$ ls mydir/a.txt当前工作目录没有改变,如果将第八行改成source peter.sh,当前目录就会变成脚本所在目录
Loop control
$ ls mydir/
A b C
$ vim rename.sh
!/USR/BIN/ENV Bash
CD $ # corresponds to the first parameter passed in when executing a script
For file in a B C
Do
MV $file $file. txt
Done
$ chmod +x rename.sh
$./rename.sh mydir/
$ ls mydir/
A.txt B.txt C.txt
Remote execution
Executes a script locally that commands in this script work on the server
If you write a script locally mkfile.ssh:
ssh -t [email protected] ‘touch a.txt‘
Execute script:
./mkfile.ssh
This is the equivalent of executing this command for a servertouch a.txt
7. Process view all current processes
ps aux|grep【要查找的内容】
ctrl+shift+c
Copy content
ctrl+shift+v
Paste Content
Example: vim
start vim to ps aux|grep vim
see the process number, as 4646, to end the process withkill 4646
Background execution
【程序名】 &
The program executes in the background
Using the ctrl+z
End program
End Process
kill【选项】
Options such as 9
forcing the kill process
Linux has 7 workstations running at the same time, when the use of the deadlock situation, the ctrl+out+f1
Switch Workbench, here can kill the cause of the process of death, and then ctrl+out+f7
back to the original workbench
8. Software Installation and installation method Ⅰ
Use the unzip command to unzip, then place the program echo $PATH
under any path, or use a soft link, such as a ln -s ~/.sublime3/sublime_text ~/bin/subl
subl
shortcut command name
Installation mode Ⅱ
Unzip and go to the software directory, then do three steps:
./configure
make
sudo make install
Deb Package Installation "only for Ubuntu system"
Program itself configuration file installation location dependency
HAPPYCASTS.NET/EPISODES/14 will explain how to package the source code as a Deb package
In the directory where Deb is locatedsudo dpkg -i 【包名】.deb
dpkg -l
List all the Deb packages on the system
Install from Apt-get Warehouse
sudo apt-get install git
Install Git
sudo apt-get remove git
Delete git
sudo apt-get purge git
Delete git, and even the configuration files are deleted together
It also has tab completion when installed, and it can automatically handle dependency problems by knocking the TAB key twice.
9. Network operation
As long as it ssh
runs, it can be used.rsync
rsync -r mydir happycasts.net:【服务器上的路径】
The representative uploads the local directory Mydir to the service
In turn, the rsync -r happycasts.net:【服务器上的路径】mydir.
representative downloads the directory on the server to local, and the last .
represents the current directory
rsync -r mydir/ happycasts.net:mydir/
Can synchronize the corresponding directory of the client and server, note that two can /
not save, and the general use -a
of parameter substitution -r
, -av
to print out some useful information
-a
Can only synchronize the newly created files on the client, and sometimes the local will also delete some files, need the server also do the corresponding delete, it should rsync -av --delete mydir/ happycasts.net:mydir/
, but this is also risky, generally in the above command after adding one --dry-run
, will turn on the verification
10. User and file permissions three kinds of permissions
READ: r
; write: w
; Execute:x
Three types of people
Owner: owner
; user group: group
; other person:world
The actual consideration is whether each type of person has rwx three kinds of authority
Chmod--change file Mode
ls -l a.txt# -rw-rw-r-- 1 peter peter 0 Aug 30 11:57 a.txt# a.txt对world没有写和执行权限chmod rw-rw-rw- a.txt # wrong!chmod 110110110 a.txt # wrong!chmod 666 a.txt # right! 6对110就是二进制转八进制
In fact, you can also chown
change the permissions of the user by command, specifically see Billie66 's book "Linux Command Line," chapter tenth--Permissions
Linux Basics (31-40)