Linux Study Notes-Common Instructions Description

Contents of this article

1. Linux command notes

2. "It is better to teach a man to fish than to teach him to fish."

1. Linux command notes

0. The cd command is the abbreviation of change dir, which can switch the current path of the terminal to the target path.

1. mkdir creates a folder. Is the abbreviation of make directory, which can create a new directory in the file system. Format: mkdir [-p] directory name. The "directory name" in the command format is the directory path to be created. The "-p" option does not need to be entered. If the "-p" option is used, when the superior directory contained in the created directory name does not exist, it will be created automatically. All directories that do not exist.

2. The mv move command can also rename, command the moved file location + rename, for example: mv oldname newname, mv oldname /././newname

3. rm delete command, delete files. The command is the abbreviation of remove. Its function is to delete one or more files or directories. Example: rm filename. When using the rm command, add the -i parameter as much as possible, and try not to use the -f parameter to avoid irreparable losses.

4. The rmdir delete folder command is the abbreviation of remove directory. Its function is to delete empty directories. Example: sudo rm -r folder name (forced deletion and prompt), sudo rm -rf folder name (forced deletion without prompt); rmdir empty folder (rmkir deletes empty folder)

5. cat displays the file content, for example: cat hello.c. The cat command is the abbreviation of concatenate, which is translated as concatenation, that is, it can concatenate two contents. We usually use it to output the contents of the file under the terminal for viewing.

6. scp copies the server-side files to the local folder 

scp [email protected]:/home/xxx/Desktop/main /home/xxx/Desktop/demo

Copy local files to the server-side folder

scp  /home/xxx/Desktop/demo/main [email protected]:/home/xxx/Desktop

Download entire directory from server 

scp -r [email protected]:/home/xxx/Desktop  /home/xxx/Desktop2

Upload directory to server        

scp -r /home/xxx/Desktop2 [email protected]:/home/xxx/Desktop

7. FTP connects to the server ftp 192.168.164.155 (ftp server address). The server downloads the specified file to the specified directory get [remote-file] [loacl-file] and obtains a batch of files mget [remote-file]; uploads the file put [ loacl-file] [remote-file] . Note: bye disconnect the ftp connection. ? help command.

8. rz upload files. rz-be

9. sz download files.

10. chmod changes file permissions. chmod 777 a.out. Execute the compiled file ./a.out and report an error ./a.out: Permission denied. The reason is that the executable file does not have permissions. Use the chmod command to modify the permissions chmod 777 a.out and execute it again. (7=0x111 (read, write, execute): 4 read, 2 writable, 1 executable).

11. ifconfig displays or configures the network interface (network device). ifconfig -a displays all interface information.

12. echo echo. echo hello displays hello; echo hello > 1.txt; writes hello to 1.txt. cat 1.txt displays the content of 1.txt: hello. echo hello2 >> 1.txt Continue writing hello2 to 1.txt; cat 1.txt displays the content of 1.txt: hello line break hello2 line break. echo $PATH: Display environment variables.

13. ls displays files; ls -l displays file information; ll displays file information

14. -l: gcc -o testApp testApp.c -lpthread. Use the -l option to specify the link library pthread. The reason is that pthread is not in the default link library of gcc, so it needs to be specified manually.

15. The mouse is an input device, and its corresponding device file is in the /dev/input/ directory. Normally it is mouse sudo od -x /dev/input/event2. After executing the command, moving the mouse or pressing and releasing the mouse will print out the corresponding data in the terminal.

The keyboard is also an input device, but the keyboard is the standard input device stdin. The process will automatically inherit standard input, standard output, and standard error from the parent process. The file descriptor corresponding to the standard input device is 0, so it is used directly in the program. That's it, no need to call open to get the file descriptor.

16. su enters super administrator mode; exit exits super administrator mode.

17. ulimit -n displays the maximum number of files that a process can open.

18. Check the file inode number: ls -i or stat filename. In the information printed by ls, a number in front of each line represents the inode number of the corresponding file.

19. Use the df -h command to view the disk partitions mounted by the root file system of the Ubuntu system. The result is /dev/sda1

20. tune2fs -l /dev/sda1 | grep "Block size" Check the block size of disk partition /dev/sda1. Directly tune2fs -l /dev/sda1 | grep "Block size" prompts that there is no permission. You can use sudo tune2fs -l /dev/sda1 | grep "Block size".

21. Check the execution time of the executable file. time ./execution file.

22. ls -l /dev/: View devices. In Linux systems, hardware devices can be divided into character devices and block devices, so there are two file types: character device files and block device files. Although there is a device file, the device file does not correspond to a file on the disk. That is to say, the device file does not exist on the disk, but is virtualized by the file system and is generally maintained by memory. When the system is shut down, The device files will disappear; character device files are generally stored in the /dev/ directory of the Linux system, so /dev is also called the virtual file system devfs.

23. The chown command is also used to change the owner and group of the file. For example, change the owner and group of the testApp.c file to root: sudo chown root:root testApp.c.

24. ln: Use the ln command to create a soft link file or a hard link file for a file. The usage is as follows: Hard link: ln source file link file; soft link: ln -s source file link file.

The two hard link files created using the ln command have the same inode number as the source file test_file. Since the inodes are the same, it means that they point to the same block of the physical hard disk. They just have different file names. Hard link files and source files have a completely equal relationship with the file system.

Method to establish a soft link: ln -s source address and destination address. For example: For example, if I soft link the Linux file system rootfs_dir to the /home/jyg/ directory, ln -s /opt/linux/rootfs_dir /home/jyg/rootfs_dir is enough.

Guess you like

Origin blog.csdn.net/weixin_46158019/article/details/132374165