Linux is the most widely used server operating system based on Unix, a free open source, due to the high stability and security of the system, the market share has almost become the best system environment program code runs. linux can not run for a long time we write program code can also be installed in a variety of computer hardware devices, such as mobile phones, routers, Android lowest level program is run on linux system.
A, linux directory structure
- bin ( bin aries) to store binary executable file
- sbin ( S UPER the User bin aries) to store binary executable file, only root can access
- etc ( etc etera) storage system configuration files
- usr ( U nix S hared R & lt esources) for storing the shared system resources
- home storage root directory of user files
- superuser root directory
- dev ( dev ICES) device for storing the file
- lib ( lib Rary) stored with the file system to run the required shared libraries and kernel modules
- mnt ( m OU NT ) system administrator temporary installation point of the file system
- storing boot used for various system boot files
- tmp ( T E MP orary) for storing various temporary files
- var ( var file iable) for storing data needed to change the runtime
Two, linux common commands
- Format: command - option parameters (options and parameters can be null)
- 如: -the ls / usr
2.1 operating files and directories
command | parameter | Examples | Explanation |
cd | cd /home | Change directory | |
pwd | pwd | Displays the current working directory directory | |
touch | touch 1.txt | Create an empty file | |
mkdir | mkdir testdir | Create a new directory | |
-p | mkidr -p dir1/dir2/dir3/ | Create multi-level directory, parent directory to the parent directory Mr. absence | |
cp | cp 1.txt | Copy the file or directory | |
-r | cp -r dir1/ | Recursive processing, the files and subdirectories in the specified directory together with a copy | |
mv | etc. dir1 dir2 | Move a file or directory, rename the file or directory | |
rm | rm 1.txt | Delete Files | |
-r -f |
rm -rf dir1 | r delete all the files in the directory, f force delete a file or directory |
|
rmdir | rmdir dir1 | Delete empty directories | |
cat | cat 1.txt | Display text files | |
more | more 1.txt | Pagination text file, you can flip back and forth, back space, b forward |
|
less | less 1.txt | Page display the contents of a text file, you can flip back and forth, back space, b forward support line mode (described later) |
|
head | head 1.txt | Check the beginning of the text, the default ten lines | |
-[on one] | head -20 1.txt | Section specifies the number of lines of text beginning View | |
tail | tail 1.txt | Check the end of the text, the default ten lines | |
-[on one] | tail -20 1.txt | Specified number of rows to see the end of the text | |
-f | tail -f 1.txt | Rolling cycle reads the file and dynamically displayed on the screen, according to tracking file attributes | |
-F | tail -F 1.txt | Rolling cycle reads the file and dynamically displayed on the screen, the file name of the file tracking | |
wc | wc 1.txt | Statistics the number of lines of text, words, characters |
|
-m |
wc -m 1.txt | Number of characters | |
-w | wc -w 1.txt | Text Word Count | |
-l | wc -l 1.txt | Lines of text | |
find | -name | find / -name 1.txt | Find the specified file in the specified directory in the file system |
grep | grep aaa 1.txt | Find the specified file containing the content of the line, for example: to find all lines containing aaa in the 1.txt | |
ln | ln 1.txt 1_bak.txt | Linking files, | |
-s |
ln -s 1.txt 1_bak.txt | Creates a symbolic link to the source file, rather than hard-wired |
2.2 system commonly used commands
command | parameter | Examples | Explanation |
top | top | Displays current system process consuming the most resources |
|
date | date | The system displays the current time | |
ps | Less alone, with parameters according to the needs, ps -ef or ps-aux | ||
-and the | ps -e | Display all processes, environment variables |
|
-f | ps -if | Full format | |
-a | PS-A | Display all processes for all users (including other users) |
|
-u | ps -at | Order a user name and start time to show progress |
|
-x | ps aux | Showed no process control terminal | |
kill | -9 | kill -9 pid | Forced to kill a process |
df | df | Usage displays the file system disk space | |
-h | df -h | Displaying a human-readable manner, Kb, Mb, GB, etc. | |
of | The sum of the disk space to display the specified directory and its subdirectories that have been used |
||
-s | You -s * | The sum of the display into the specified directory, the current directory * represents all | |
-h | you -sh * | Displaying a human-readable manner, Kb, Mb, GB, etc. | |
free | free | Display current memory usage and swap space | |
ifconfig | ifconfig | NIC network configuration, commonly used to view the current IP address | |
ifconfig eth0 192.168.12.22 | Temporary changes to the system IP (after the restart failure) | ||
ping | ping baidu.com | 测试网络的连通性 | |
hostname | hostname | 查看主机名 | |
shutdown | -r | shutdown -r | 先关机,再重启 |
-h | shutdown -h | 关机后不重启 | |
halt | halt | 关机后关闭电源,相当于shutdown -h |
|
reboot | reboot | 重新启动 相当于shutdown -r |
2.3 压缩解压缩
命令 | 参数 | 示例 | 说明 |
gzip | gzip 1.txt | 压缩后面的文件或者文件夹 | |
-d | gzip -d 1.txt.gz | 解压后面的压缩文件 | |
-[num] | gzip -9 1.txt | 用指定的数字num调整压缩的速度,-1或--fast表示最快压缩方法(低压缩比),-9或--best表示最慢压缩方法(高压缩比)。系统缺省值为6 |
|
tar | -c | tar -cvf 1.tar 1.txt | 建立一个压缩文件的参数指令,例,将1.txt压缩为1.tar,也可指定多个文件或文件夹 |
-x | tar -xvf 1.tar 1.txt | 解开一个压缩文件的参数指令 | |
-z | tar -zcvf 1.tar.gz 1.txt tar -zxvf 1.tar.gz 1.txt |
是否需要用 gzip ,使用gzip压缩或解压 | |
-v | 压缩的过程中显示文件 | ||
-f | 使用档名,在 f 之后要立即接档名 |
2.4 文件权限操作
- linux文件权限的描述格式解读
-
- r 可读权限,w可写权限,x可执行权限(也可以用二进制表示 111 110 100 --> 764)
- 第1位:文件类型(d 目录,- 普通文件,l 链接文件)
- 第2-4位:所属用户权限,用u(user)表示
- 第5-7位:所属组权限,用g(group)表示
- 第8-10位:其他用户权限,用o(other)表示
- 第2-10位:表示所有的权限,用a(all)表示
- r 可读权限,w可写权限,x可执行权限(也可以用二进制表示 111 110 100 --> 764)
命令 | 参数 | 实例 | 说明 |
chmod | chmod u+r 1.txt | 修改文件或目录的权限 u表示当前用户,g表示同组用户,o表示其他用户,a表示所有用户 r表示可读,w表示可写,x表示可执行 例:修改1.txt文件给当前用户添加可执行权限 |
|
-R | chmod -R u+r dir1 | 修改指定目录及其子目录的所有文件的权限 | |
三位数字 | chmod 764 1.sh | 直接指定文件的权限 7:表示可读可写可执行,4+2+1 6:表示可读可写,4+2 ... |
|
chown | chown user1:group1 1.txt | 修改文件的所属用户和组 例:将1.txt文件的所属用户指定为user1,组为group1 |
|
-R | chown -R user1:group1 1.txt | 修改目录下所有文件及子目录的所属用户和组 用数字来表示权限(r=4,w=2,x=1,-=0) |
三、linux系统常用快捷键及符号命令
命令 | 参数 | 实例 | 说明 |
ctrl + c | 停止进程 | ||
ctrl + l | 清屏 | ||
ctrl + r | 搜索历史命令 | ||
ctrl + q | 退出 | ||
tab | 自动补全 | ||
> | echo "haha" > 1.txt | 将前一条命令的输出,写入到后面的文本中 将文本清空,然后写入 |
|
>> | echo "lala" >> 1.txt | 将前一条命令的输出,写入到后面的 文本中 不清空文本,追加到文本最后 |
|
| | cat 1.txt | grep 'hello' | 管道命令,以前一个命令的输出作为输入,然后进行运算 例:打印1.txt中带有hello字符串的行 |
|
* | 通配符,指所有 |
四、vim编辑器
vi / vim是Linux上最常用的文本编辑器而且功能非常强大。只有命令,没有菜单,下图表示vi命令的各种模式的切换图。
4.1 修改文本
i | 在光标前插入 |
I | 在光标当前行开始插入 |
a | 在光标后插入 |
A | 在光标当前行末尾插入 |
o | 在光标当前行的下一行插入新行 |
O | 在光标当前行的上一行插入新行 |
:wq | 保存并退出 |
4.2 定位命令
:set nu | 显示行号 |
:set nonu | 取消行号 |
gg | 跳到首行 |
G | 跳到末行 |
:n | 跳到第n行 |
4.3 替换和取消命令
u | undo,取消上一步操作 |
Ctrl + r | redo,返回到undo之前 |
r | 替换光标所在处的字符 |
R | 从光标所在处开始替换,按Esc键结束 |
4.3删除命令
x | 删除光标所在处字符 |
nx | 删除光标所在处后的n个字符 |
dd | 删除光标所在行。ndd删除n行 |
dG | 删除光标所在行到末尾行的所以内容 |
D | 删除光标所在处到行尾的内容 |
:5,7d | 删除指定范围的行 |
4.4 常用快捷键
Shift+ zz | 保存退出,与“:wq”作用相同 |
v | 进入字符可视模式 |
V | 进入行可视模式 |
Ctrl + v | 进入块可视模式 |