Linux Basics
Basic commands
CD: switch to the current working directory.
jianghouren@jianghourendeMacBook-Pro ~ % cd test
jianghouren@jianghourendeMacBook-Pro test %
Copy the code
Jump to the Downloads directory in the Test directory
jianghouren@jianghourendeMacBook-Pro test % cd ~/Downloads
jianghouren@jianghourendeMacBook-Pro Downloads %
// CD ~ jumps to its own home directory. Equivalent to CD /Users/jianghouren.
// If the directory name is omitted, the directory is changed to the user's home directory.
jianghouren@jianghourendeMacBook-Pro test % cd ~
jianghouren@jianghourendeMacBook-Pro ~ % pwd
/Users/jianghouren
jianghouren@jianghourendeMacBook-Pro ~ % cd test
jianghouren@jianghourendeMacBook-Pro test % cd /Users/jianghouren/Downloads
jianghouren@jianghourendeMacBook-Pro Downloads %
Copy the code
PWD: View the location of the current directory.
jianghouren@jianghourendeMacBook-Pro test % pwd
/Users/jianghouren/test
jianghouren@jianghourendeMacBook-Pro test %
Copy the code
Mkdir: creates a directory.
jianghouren@jianghourendeMacBook-Pro test % ls
// Create directory 111
jianghouren@jianghourendeMacBook-Pro test % mkdir 111
jianghouren@jianghourendeMacBook-Pro test % ls
111
jianghouren@jianghourendeMacBook-Pro test %
Copy the code
Create a multi-level directory
jianghouren@jianghourendeMacBook-Pro test % mkdir -p 1/2/3
jianghouren@jianghourendeMacBook-Pro test % ls
1
jianghouren@jianghourendeMacBook-Pro test % cd 1
jianghouren@jianghourendeMacBook-Pro 1 % cd 2
jianghouren@jianghourendeMacBook-Pro 2 % cd 3
jianghouren@jianghourendeMacBook-Pro 3 %
Copy the code
cd .. Is to return the upper-level directory, and CD – is to return the working directory of the last operation.
jianghouren@jianghourendeMacBook-Pro test % ls
1
jianghouren@jianghourendeMacBook-Pro test % cd 1/2/3
// Jump three levels above the current directory
jianghouren@jianghourendeMacBook-Pro 3% cd .. /.. /..// Go back to the directory of the last operation
jianghouren@jianghourendeMacBook-Pro test % cd -
~/test/1/2/3
jianghouren@jianghourendeMacBook-Pro 3 % cd -
~/test
jianghouren@jianghourendeMacBook-Pro test % cd -
~/test/1/2/3
jianghouren@jianghourendeMacBook-Pro 3 % cd ..
jianghouren@jianghourendeMacBook-Pro 2 % cd ..
jianghouren@jianghourendeMacBook-Pro 1 % cd ..
jianghouren@jianghourendeMacBook-Pro test %
Copy the code
Ls: displays information in the current directory.
This can be viewed by ls-alt (where a is for all, L is for lists, and T is in reverse order).
jianghouren@jianghourendeMacBook-Pro test % ls
111 222
jianghouren@jianghourendeMacBook-Pro test % ls -a
. .. .DS_Store 111 222
jianghouren@jianghourendeMacBook-Pro test % ls -al
total 16
drwxr-xr-x 5 jianghouren staff 160 3 12 22:43 .
drwxr-xr-x+ 55 jianghouren staff 1760 3 12 22:22. -rw-r--r--@1 jianghouren staff 6148 3 12 11:48 .DS_Store
drwxr-xr-x 4 jianghouren staff 128 3 12 22:13 111
drwxr-xr-x 2 jianghouren staff 64 3 12 22:43 222
jianghouren@jianghourendeMacBook-Pro test % ls -alt
total 16
drwxr-xr-x 5 jianghouren staff 160 3 12 22:43 .
drwxr-xr-x 2 jianghouren staff 64 3 12 22:43 222
drwxr-xr-x+ 55 jianghouren staff 1760 3 12 22:22. drwxr-xr-x4 jianghouren staff 128 3 12 22:13 111
-rw-r--r--@ 1 jianghouren staff 6148 3 12 11:48 .DS_Store
jianghouren@jianghourendeMacBook-Pro test %
Copy the code
Code block:. Represents the current directory,.. Indicates the parent directory.
jianghouren@jianghourendeMacBook-Pro test % cd .
jianghouren@jianghourendeMacBook-Pro test % ls -alt
total 16
drwxr-xr-x 4 jianghouren staff 128 3 12 11:48 .
drwxr-xr-x 2 jianghouren staff 64 3 12 11:48 111
-rw-r--r--@ 1 jianghouren staff 6148 3 12 11:48 .DS_Store
drwxr-xr-x+ 55 jianghouren staff 1760 3 12 11:44. jianghouren@jianghourendeMacBook-Pro test % cd .. jianghouren@jianghourendeMacBook-Pro ~ %Copy the code
Code block: drwxr-xr-x, d for directory, rwxr-xr-x for permission.
jianghouren@jianghourendeMacBook-Pro test % cd 111
jianghouren@jianghourendeMacBook-Pro 111 % ls
// Create a new file and write the contents.
jianghouren@jianghourendeMacBook-Pro 111 % echo "123456" >> 1.txt
jianghouren@jianghourendeMacBook-Pro 111 % ls
1.txt
jianghouren@jianghourendeMacBook-Pro 111 % ls -alt
total 8
// - This is a normal file.
-rw-r--r-- 1 jianghouren staff 7 3 12 18:24 1.txt
drwxr-xr-x 3 jianghouren staff 96 3 12 18:24 .
drwxr-xr-x 4 jianghouren staff 128 3 12 11:48. jianghouren@jianghourendeMacBook-Pro111 %
Copy the code
Cp: short for copy, copy files.
jianghouren@jianghourendeMacBook-Pro test % echo "aaaa" >> 5.txt
jianghouren@jianghourendeMacBook-Pro test % ls
5.txt
jianghouren@jianghourendeMacBook-Pro test % cp 5.txt 1.txt
jianghouren@jianghourendeMacBook-Pro test % ls
1.txt 5.txt
jianghouren@jianghourendeMacBook-Pro test %
Copy the code
Copy the 1. TXT file in directory 111 of the current subdirectory to the current directory.
jianghouren@jianghourendeMacBook-Pro test % cp ./111/1.txt .
jianghouren@jianghourendeMacBook-Pro test % ls
1.txt 111
jianghouren@jianghourendeMacBook-Pro test % ls ./111
1.txt
jianghouren@jianghourendeMacBook-Pro test %
Copy the code
Cat: View the file content.
jianghouren@jianghourendeMacBook-Pro test % cat 1.txt
123456
jianghouren@jianghourendeMacBook-Pro test %
Copy the code
Rm: Deletes a file or directory.
jianghouren@jianghourendeMacBook-Pro test % ls
1.txt 111
// Delete files.
jianghouren@jianghourendeMacBook-Pro test % rm 1.txt
jianghouren@jianghourendeMacBook-Pro test % ls
111
// You cannot delete directories in this way.
jianghouren@jianghourendeMacBook-Pro test % rm 111
rm: 111: is a directory
// Delete the directory. R for loop, f for force.
jianghouren@jianghourendeMacBook-Pro test % rm -rf 111
jianghouren@jianghourendeMacBook-Pro test % ls
jianghouren@jianghourendeMacBook-Pro test %
Copy the code
Sudo: Switch the current user’s permissions, for example, to root.
jianghouren@jianghourendeMacBook-Pro test % id
uid=501(jianghouren) ......
// Create a directory using root.
jianghouren@jianghourendeMacBook-Pro test % sudo mkdir 222
Password:
jianghouren@jianghourendeMacBook-Pro test % ls
222
jianghouren@jianghourendeMacBook-Pro test % ls -alt
total 16
drwxr-xr-x 4 jianghouren staff 128 3 12 19:00 .
// As you can see, the creator here is root.
drwxr-xr-x 2 root staff 64 3 12 19:00 222
-rw-r--r--@ 1 jianghouren staff 6148 3 12 11:48 .DS_Store
drwxr-xr-x+ 55 jianghouren staff 1760 3 12 11:44.// Create directories with normal permissions.
jianghouren@jianghourendeMacBook-Pro test % mkdir 111
jianghouren@jianghourendeMacBook-Pro test % ls -alt
total 16
drwxr-xr-x 5 jianghouren staff 160 3 12 19:00 .
// You can see that the creators of directories 111 and 222 are different.
drwxr-xr-x 2 jianghouren staff 64 3 12 19:00 111
drwxr-xr-x 2 root staff 64 3 12 19:00 222
-rw-r--r--@ 1 jianghouren staff 6148 3 12 11:48 .DS_Store
drwxr-xr-x+ 55 jianghouren staff 1760 3 12 11:44. jianghouren@jianghourendeMacBook-Pro test %Copy the code
Now you can delete the JIANGhouren directory with normal permissions. The jianghouren directory is a subdirectory of test and is created by jianghouren.
jianghouren@jianghourendeMacBook-Pro test % ls
111 222
jianghouren@jianghourendeMacBook-Pro test % rm -rf 222
jianghouren@jianghourendeMacBook-Pro test % ls
111
jianghouren@jianghourendeMacBook-Pro test %
Copy the code
However, the JIANGhouren user has the permission to create and delete the jianghouren directory. The jianghouren user has the permission to create and delete the jianghouren directory.
jianghouren@jianghourendeMacBook-Pro test % cd 222
jianghouren@jianghourendeMacBook-Pro 222 % sudo mkdir 333
jianghouren@jianghourendeMacBook-Pro 222 % ls
333
jianghouren@jianghourendeMacBook-Pro 222 % mkdir 444
mkdir: 444: Permission denied
jianghouren@jianghourendeMacBook-Pro 222 % rm -rf 333
rm: 333: Permission denied
jianghouren@jianghourendeMacBook-Pro 222 % ls
333
jianghouren@jianghourendeMacBook-Pro 222 % sudo rm -rf 333
jianghouren@jianghourendeMacBook-Pro 222 % ls
jianghouren@jianghourendeMacBook-Pro 222 %
Copy the code
Others: On Mac, Control + L clears the screen.
Installation tools
Apt: Ubuntu
The brew: Mac
Yum: Centos
Basic Vim operations
Basic commands:
-
Vim 1.txt –> Create the file (if it does not exist) and enter edit mode
-
:w –> Save the file
-
:q –> Exit the file
-
:wq –> Save the configuration and exit
-
I –> Edit mode
-
H left, L right, K up, J Down –> cursor movement (exit edit mode)
-
Yy copy, P paste, DD delete. (Exit editing mode)
-
Press Esc to exit edit mode
Linux vi/vim
Environment variables in Linux
Environment variables:
Three important environment variables:
- PATH (command executed).
For example, the ls command actually looks in the PATH environment variable
jianghouren@jianghourendeMacBook-Pro ~ % which ls
/bin/ls
jianghouren@jianghourendeMacBook-Pro ~ %
Copy the code
-
PKG_CONFIG_PATH (PKg-config).
Use the library file with the pkg-config + argument. The library files to use are also found in PKG_CONFIG_PATH.
The pkg-config command is used when C/C++ applications are developed and libraries are linked.
-
LD_LIBRARY_PATH.
Changes to environment variables:
In Windows, add at the end by setting environment variables.
For Linux:
~/.bashrc (setting environment variables for.bashrc files in the current user’s working directory)
On Mac:
Through the env to view environment variables, through env | grep PATH to check the PATH.
Edit via vim ~/.bash_profile (~/.bash_profile sets environment variables in the.bash_profile file in the current user’s working directory)
After the Settings are complete, run source ~/.bash_profile to take effect.
note
References:
Moocs – Audio and Video Basics (Li Chao)
Welcome to follow wechat official account:No reason also