Article Directory
1. Command line shortcut keys
- Ctrl+a: move the cursor to the beginning
- Ctrl+e: move the cursor to the end
- Ctrl+u: Clear the entire line
2. File operation instructions
- cd ...: jump to the parent directory
- ls : view
- pwd : view the current directory
1. Important documents
- "Everything you see is a file" in LInux system
- bin: store binary executable files
- boot: Store the boot program
- dev: store device files
- home: store users
- etc: user information and system configuration files
- lib: library file
- root: administrator host directory (home directory)
- usr: user resource management directory
2. File type
- Normal file:-
- directory file: d
- Character device file: c
- Block device file: b
- Soft link: l
- Pipeline file: p
- socket: s
- unknown file
3.cp copy instruction
Copy files:
cp file1 file2
cp file1 dirl
cp file1 ../
Copy directory:
cp dir1 dir2 -r
cp dir1 ~l -r
4. Increase permissions
chmod u+x 文件名
5. Modify the operating instructions
Create user:
sudo adduser 新用户名
Modify the user who owns the file:
sudo chown 新用户名待修改文件。
sudo chown wangwu a. c
delete users:
sudo deluser 用户名
Create user group:
sudo addgroup 新组名
Modify the user group to which the file belongs:
sudo chgrp 新用户组名待修改文件。
sudo chgrp g88 a.c
Delete group:
sudo delgroup 用户组名
3. Find and Retrieve
find command: find files
-type按文件类型搜索d/p/s/c/b/1/ f:文件
-name按文件名搜索
find ./ -name"*fi1e*.jpg"
-Imaxdepth指定搜索深度。应作为第一个参数出现
find ./ -maxdepth 1 -name "*fi1e*.jpg'
-size按文件大小搜索.单位:k、M、G
find /homelitcast -size +20M -size -50M
-atinme、 mtime、ctime 天 anin、rin、cmin分钟
exec: Execute the result set found by find
find/usr/ -name '*tmp*' -exec ls -ld {} \;
-ok:以交互式的方式将find搜索的结果集执行某一指定命令
-xargs:将find搜索的结果集执行某一指定命令。当结果集数量过大时,可以分片映射
find /usr/ -name '*tmp*’l xargs 1s -1d l
grep command: find file content
grep -r 'copy' ./ -n
ps aux | grep 'cupsd'’--检索进程结果集。
4. Installation
1. Original code installation
- Unzip the source code package
- cd you
- ./configure
detects whether the file is missing, creates a Makefile, and detects the compilation environment - make
compiles source code, generates libraries and executable programs - sudo make install
installs libraries and executable programs into the system path - sudo make distclean
remove and uninstall software
2. Software installation:
- 1. networking
- 2. Update the software resource list to the local. sudo apt-get update
- 3. Install sudo apt-get install software name
- 4. Uninstall sudo apt-get remove software name
- 5. Install using a package (.deb): sudo dpkg -i install-package-name
5. Compression and decompression
tar compression:
- 1.tar -zcvf The name of the compressed package to be generated to compress the material.
tar zcvftest.tar. gzfile1 dir2 use _gzip compression.
tar jcvftest.tar.gz fi1e1 dir2 Use bzip anti-style compression.
tar decompression:
Use gzip to decompress the c --> x tar zxvftest.tar.gz in the compression command .
tar jxvftest.tar.gz uses bzip2 to decompress.
rar compression:
- rar a -r compressed package name (with .rar suffix) compressed material.
rar a -r testrar.rar
stdio.h test2.mp3
rar decompression:
- urrar x package name (with .rar suffix)
zip compression:
- zip -r Compression package name (with .zip suffix) to compress the material.
zip -r testzip.zip dir
stdio.h test2.mp3
zip decompression:
- unzip compressed package name (with .zip suffix)
6. Three working methods of vim
Jump to the specified line:
- 88G (command mode)
- :88 (last line mode)
Pick the beginning of the line:
- gg (command mode)
Looking at the end of the line:
- G (command mode)
Auto formatter:
- gg=G (command mode)
Braces correspond to;
- % (command mode)
Move the cursor to the beginning of the line:
- 0 (command mode) execution ends, and the working mode remains unchanged.
Move the cursor to the end of the line:
- $(command mode) execution ends, and the working mode remains unchanged.
Delete a single character:
- The execution of x (command mode) ends, and the working mode remains unchanged.
Delete a word:
- dw (command mode) place the cursor on the first letter of the word to operate.
Delete from cursor to end of line:
- D or $ (command mode)
Delete the cursor to the beginning of the line:
- d0
Delete specified area:
- Press V (command mode) to switch to "visual mode", use hjk1 to move the cursor to select the area to be deleted. Press d to delete the data in this area.
Delete specified 1 line:
- On the line where the cursor is located, press dd (command mode)
Delete specified N lines:
- Delete the first line at the cursor, press Ndd (command mode)
Copy a line:
- yy
Paste:
- p: backward, P: forward.
Find:
- 1. Find the content of the idea:
In the command mode, press "!" to input the keyword you want to search, and press Enter. Use n to retrieve the next one. - 2. Find what you see:
In the command mode, place the cursor on any character of the word, press "*" "#"
One-line replacement:
- Put the cursor on the line to be replaced, enter the last line mode, enter: s /original data/new data
Replacement throughout:
- Last line mode,: %s/Original data/New data/gg: Not added, only the first one of each line will be replaced.
Replacement of specified lines:
- Last line mode,: start line number, end line number s / original data / new data / gg: do not add, only replace the first one of each line.
:29,35s /printf/print1n/g
Revocation, anti-revocation:
- u, ctr1tr (command mode)
Split Screen:
- sp: Horizontal screen. Ctrl1+ww switch. vsp: vertical screen. Ctrl1+ww switch.
Jump to the man page:
- Put the cursor on the word of the function to be viewed, and use K (command mode) to jump. specified volume, nK
View macro definition:
- Put the cursor on the macro definition word to be viewed, and use [d to view the definition statement.
Execute the she11 command in the last line mode:
- :!Order
- : ! 1s -l
7. Four steps of gcc compilation
gcc compilation 4 steps:
- -I: Specify the directory location where the header file is located.
- -c: Only do preprocessing, compilation, and assembly. get the binaries!!!
- -g: Add debug statements when compiling. Mainly supports gdb debugging.
- -wall: Display all warning messages.
- -D: Register macro definitions "dynamically" with the program.
8. Static library and dynamic library
Static library production and use steps:
1.将 .c生成.o文件
gcc -c add. c -o add. o
2.使用ar工具制作静态库
ar rcs lib库名.aadd.o sub. o
3.编译静态库到可执行文件中:
gcc test.c lib厍名.a -o a. out
Header guards: prevent header files from being included repeatedly
#ifndef _HEAD_H
#define _HAD_H
...
#endif
Dynamic library production and use:
1.将.c生成.o文件,(生成与位置无关的代码–fPIC)
gcc -c add. c -o add. o -fPIC
2.使用gcc -shared制作动态库
gcc -shared lib库名.soadd.o sub.o div.o
3.编译可执行程序时,指定所使用的动态库。-l:指定库名-L:指定库路径。
gcc test.c -o a.out -lnmymath -L./lib
4.运行可以执行程序./a.out
原因:
链接器:工作于链接阶段,工作时需要-l和-L
动态链接器:工作于程序运行阶段,工作时需要提供动态库所在目录位置。
通过环境变量:export LD_LIBRARY_PATH=动态库路径
./ a.out成功! !!(临时生效,终端重启环境变量失效)
永久生效:写入终端配置文件。 .bashrc
1) vi ~l .bashrc
2)写入export LD_LIBRARY_PATH=动态库路径保存
3) . .bashrc/ source .bashrc / 重启 终端--->让修改后的.bashrc生效
4) ./a.out成功!