preface
Linux is a Unix like operating system that is free to use and spread. It is a multi-user, multi task, multi thread and multi CPU operating system based on POSIX and Unix. With the development of the Internet, Linux has been supported by software enthusiasts, organizations and companies all over the world. In addition to maintaining a strong development momentum in the server operating system, it has made great progress in personal computers and embedded systems. Users can not only intuitively obtain the implementation mechanism of the operating system, but also modify and improve the operating system according to their own needs to make it meet the needs of users to the greatest extent.
1, What is LINUX?
2, LINUX commands
1.shell
1. A special program running in Linux system
2. Act as "translator" between users and Kernels
3. When the user logs in to the Linux system, a shell program is automatically loaded
4.Bash is the shell program used by default in Linux system
shell is located between the user and the kernel. Its main function is to convert the user's instructions into a language that the computer can understand, and convey the converted computer language to the kernel. After receiving these commands, the kernel makes instructions to make the hardware run
The file is located in / bin/bash
Linux Basics
Internal command
- It integrates with some special instructions inside the shell interpreter program, also known as bulit in instructions
- Part of the shell
- There is no separate corresponding system file
- Automatically load memory and can be used directly
External command
- Script file or binary program that can complete specific functions in Linux system
- Commands outside the shell Interpreter Program
- Each external command corresponds to a file in the system
- The corresponding file location must be known and can be executed only after being loaded by the shell
Common command line format
Command word - [options] - [parameters]
Operation - function - object to be executed
Command word:
Is the most critical part of the whole command
Identify only one command
Options:
Short format option: use "-" symbol to guide
Long format option: use '–' symbol to guide
Parameters:
Processing object of command word
It can be file name, directory (path) name or user name
The number can be zero to multiple
Auxiliary operations for editing Linux command line
Tab Key: automatic replenishment Backslash\" ###Force line feed Ctrl + U Combination key ###Empty to the beginning of the line Ctrl + K Combination key ###Empty to end of line Ctrl + L Combination key ###Clear screen Ctrl + C Combination key ###Cancel this command edit Ctrl + E Combination key ###The cursor jumps to the end of the line Ctrl + A Combination key ###The cursor jumps to the beginning of the line
Linux commands
help
- Help is an internal command. View help information for shell internal commands.
- – help applies to most external commands.
man manual
Linux command manual
Usage: man cd
- Find flipping
- "↑" and "↓" browse by line
- page up and page down
- Press Q to exit
- Search by "/"
man ls | col -b > lshelp.txt ### Set LS help Txt file export to local (Xshell)
Directory and file management commands ----- cd
Switch working directory: cd (Relative path, absolute path) cd /home ###Followed by the absolute path, switch to the home directory cd ./home ###Followed by the relative road strength, switch to the home directory cd ~ ###Switch to the current user's home directory cd ###Switch to the current user's home directory cd ~user ###Switch to a user's home directory. Only root can do it. Other users can only do it at their own home cd - ###Switch to the directory where the last operation was performed cd .. ###Switch to the previous directory (parent directory)
View current working directory - pwd
pwd: [root@localhost ~]# pwd /root
List display directory contents (common options can be combined with wildcards) - ls
ls -l ###The file information attributes are listed in detail. Usually, ll is used directly, so the alias is set ls -R ###Recursive display. For example, if there are files in a directory, list that file together ls -d ###View the information of the directory itself without displaying the contents under the directory ls -i ###Display inode value (node value) ls -h ###Friendly display file size ls -a ###Traverse all files and directories (ls) and start the file name or directory name with "." Are treated as hidden files and will not be listed) ls -A ###The only difference from - a is that the current directory and the previous directory are not listed wildcard -"?" Match an unknown character ls -lh /dev/sd?l -"*"Matches all non hidden characters, no matter how long or short ls -lh /etc/ns*.conf
Statistics of directory and file space occupation - du
-a # statistics of disk space use include all files, not just directories
-h # displays the statistical results in a more user-friendly way (counting in KB by default, but not in units)
-s # only counts the total size of the occupied space, not the size of each subdirectory and file
Statistics/var/log The amount of space occupied by the directory du -sh /var/log/ du -sh * #The production environment is often used in this way to count and display the size of all files in the current directory. It is often used when the disk water level is too high
Create new directory - mkdir
mkdir /opt/sj # creates a directory. Note: the parent directory must exist
-p: Creating an existing directory will report an error, and adding - P will not report an error / when the parent directory does not exist, it will be created recursively
Create a file named in the current directory public_html Subdirectories of mkdir public_html Create directory/aa,stay/aa Create subdirectories under directory bb stay /aa/bb Create subdirectories under directory cc mkdir -p/aa/bb/cc
Create an empty file touch
Time stamp for updating files
Often used to create multiple new empty files
1. File existence: modify the time attribute of the file or directory, including access time and change time
2. File does not exist: create a new file
Create two empty folders named aa and bb touch aa bb Here is touch Advanced usage of [root@localhost opt]# touch {1,2,3} [root@localhost opt]# ls 1 2 3 rh [root@localhost opt]# touch {1,2,3}.txt [root@localhost opt]# ls 1 1.txt 2 2.txt 3 3.txt rh [root@localhost opt]# touch {4..8}.txt [root@localhost opt]# ls 1 1.txt 2 2.txt 3 3.txt 4.txt 5.txt 6.txt 7.txt 8.txt -------- Copyright notice: This article is CSDN Blogger「Shang 275」Original articles, follow CC 4.0 BY-SA Copyright agreement, please attach the original source link and this statement. Original link: https://blog.csdn.net/weixin_63634809/article/details/121982365
Create linked file (soft link, hard link) - in
ln command is used to establish linked files for files or directories (similar to shortcuts in Windows system) to improve the efficiency of locating files or directories
Link file includes soft link and hard link, among which soft link is also called symbolic link. Whether accessing soft links
ln -s ###Creating a soft link is equivalent to creating a shortcut ln ###Creating a hard link is equivalent to copying a copy
When a soft link is established, the original file may not exist
If you delete the source file and re-establish the source file, the soft link can still be used
The size of the soft link file is the character length of the file name of the soft link file itself
You can make soft links to the directory to prevent the directory from being deleted
The difference between hard and soft links
1. Hard links cannot establish connections across partitions and cannot create folders
Remove the hardware connection to continue accessing the hard link
2. Soft links can cross devices and support folders
The soft link deletion source file cannot be accessed
Note: relative path and absolute path, absolute path is recommended
--------
Copyright notice: This is the original article of CSDN blogger "Shang 275", which follows the CC 4.0 BY-SA copyright agreement. Please attach the original source link and this notice for reprint.
Original link: https://blog.csdn.net/weixin_63634809/article/details/121982365
Copy files or directories cp
Rebuild a copy of the file or directory (source) to be copied and save it as a new file or directory
-p ###Copy with attributes -a ###Reserved permissions, complex soft links themselves, recursive replication -r ###Recursive replication -f ###Force replication without user interaction -i ###Reminder override
Advanced usage of cp: cp - V file Txt {,. Bak} is often used for backup
Delete file or directory rm
-i ###Remind users to confirm when deleting files or directories -r ###This option must be used when deleting a directory, which means that the entire directory tree is deleted recursively -f ###When deleting a file or directory, it is forced to delete directly without reminding
Move files or directories mv
Transfer the specified file or directory to a new location
If the target location is the same as the original location, it is equivalent to renaming
mv [options]... Source file or directory... Destination file or directory
mv mytouch mkfile mv mkfile public_html/
Find the command / file storage directory which
The search range is determined by the environment variable PATH (echo $PATH)
Which command | program or which -a command | program name
which ls which cd
Find a file or directory find
Recursively, fine search is carried out according to different attributes such as the name, type and size of the target
find {lookup range} [lookup condition expression]
Find directory location of a file or subdirectory find criteria type
Search by name - name is based on the name of the target file, and "*" and "? Are allowed wildcard
Search by file size - size searches according to the size of the target file; Generally, the "+" and "-" signs are set to exceed or be less than the specified size as the search criteria; Common capacity units include kB(k is lowercase), MB\GB
Find by file owner - user finds by whether the file belongs to the target user
Find by file type - find by file type; File types include ordinary file (f), directory (d), block device file (b), character setting file (c), etc
-a means and
-o means or (or)