Linux| |Linux Tips

Linux small knowledge points


1. &

  • Means running in the background

 

2. How to open two documents under vim page

  • Use the vs command. Use crtl+ww to switch

 

3. How to directly indent multiple lines?

  • Directly in command line mode: Type [5,12>] and press Enter to indent lines 5 to 12, if it is [5,12<], press Enter to indent

  • In the command line mode, place the cursor at the beginning of the line to be indented, press [Number of lines+>>] to indent a few lines, and [Number of lines+<<] to retract a few lines

 

4. How to make multi-line comments

  • The first step: first enter the normal mode

  • Step 2: Use to crtl+venter block selection mode

  • Step 3: Use h,j,k,lto indicate lower left, upper right , and j and k to select blocks up and down

  • Step 4: After choosing, use to shift+ienter to get insert mode

  • Step 5: Enter directly//

  • Sixth step: pressing Escinto the insert mode like

 

5. How to determine whether a file exists or not

  • //access系统调用函数
    #include <unistd.h>
    int access(const char* pathname, int mode);
    参数:
        pathname:路径名,也就是文件名
        mode:检查文件的各种选项,四个
            1. F_OK 检查文件是否存在
            2. R_OK 检查文件存在并且是否具有读权限
            3. W_OK 检查文件存在并且是否具有写权限
            4. X_OK 检查文件存在并且是否具有执行权限
    返回值:
        正确的话返回0,失败返回-1

 

6. How to use C++ standard under linux

  • For the general g++ compiler under linux, it supports c++98. If you want it to support c++11 compilation, you only need to open c++11 explicitly.

#include <iostream>
#include <typdinfo>
using namespace std;
int TestAuto()
{
  return 10;
}
int main()
{
  int a = 10;
  auto b = a;
  auto c = 'a';
  auto d = TestAuto();
  cout << typeid(b).name() << endl;
  cout << typeid(c).name() << endl;
  cout << typeid(d).name() << endl;
  //auto e; 无法通过编译,使用auto定义变量时必须对其进行初始化
  return 0;
}

For the above code, which has the new syntax auto of C++11 , how to compile it?

g++ -o auto auto.cpp 
//采用这种编译的话,就显示
//‘b’ does not name a type
//表示该编译器不支持c++11,所以就要显式的使用c++11编译
g++ -std=c++11 -o auto auto.cpp
//这种进行编译的话就不会出错,显式的使用c++11

 

7. How does gcc compile a 32-bit program under 64-bit Linux

  • Just add -m32parameters

 

8. How to replace content under vim

8.1 Multi-line replacement

A,Bs/test/return
  • Parameter A indicates the start line, and B indicates the end line. If B is $, it is the last line.

  • This command means that the first test of each line from line A to the end of line B is replaced with return

A,Bs/test/return/g
  • Indicates that each test from line A to line B is replaced with return

 

8.2 Full text replacement

%s/test/return 
  • Indicates that the full text test is replaced with return

 

9. How to modify the previous prompt of the command line input under linux

  • Step 1: Under non-root users, enter ~/.bashrc

  • Step 2: Add PS1='[\u@\d||YK||\#]\$ '. u represents the user, d represents the time, # represents the function entered under linux this time

  • The third step: Use go out export PS1='[\u@\d||YK||\#]\$ 'to

 

10. strace command

strace can display all system calls issued by user space programs: use directly on the command line

This command can display the name, parameters and return value of the system call called in one line

Some common parameters:

​ -f -F option tells strace to track the process created by fork and vfork at the same time

​ -o xxx.txt output to a file

​ -e execve only records system calls such as execve

​ -p pid binds to a running process with process number pid

  • Each line of output is a system call

  • The left side of = is the name and parameters of the system call function, and the right side of the equal sign is the return value

【principle】:

  • Use the ptrace system call to trace and debug the running process

 

11. awk text processing tool

 

 

12. How to highlight and un-highlight the code in vim

12.1 Highlight

When in a code, enter the command mode , and then press # on it

 

12.2 Cancel highlight

When in the bottom line mode , after entering nohl (no high light), press enter to cancel the highlight

 

13. How to perform static compilation

During compile time add - staticto

Guess you like

Origin blog.csdn.net/qq_40399012/article/details/84135153