Summary of common commands in Linux

 
Chapter 1: Introduction to Linux
Section 1: History of Linux Development
linux kernel version
Linux kernel official website: www.kernel.org
Anyone can download and use it.
 
Linux distribution version (the same kernel version is different)
redhat   centos  suse  ubuntu  turbolinux fedora   linux(红旗)  mandriva debian
 
Section 2: Introduction to Open Source Software (Open Source)
Open source software:
nginx mysql apache
 
 
 
 
 
Chapter 2: Linux Common Commands
Linux can recognize command completion and directory completion
 
Section 1: Basic command format
Command format: command [options] [parameters]
 
Query the contents of the directory: ls
ls [options] [file or directory]
The original meaning of the command in English: list
OPTIONS -a show all files, including hidden files
   -l show detailed information (long) (ls -l is equivalent to ll)
   -d View directory attributes (directory)
   -h Humanize display file size (human)
   -i show inodes
 
Section 2: File Handling Commands (Directories, Files, Links)
Create a directory: mkdir -p [directory name]
-p recursively create (parents)
The original meaning of the command in English: make directories
 
Change directory: cd
The original meaning of the command in English: change directory
cd ~ to enter the home directory of the current directory
cd into the home directory of the current directory
cd - go to the last directory
cd .. to enter the previous directory
cd . into the current directory (ie unchanged)
 
Relative path: refer to the current directory to search
Absolute path: Specify from the root directory, and search recursively one level at a time. In any directory, you can enter the specified location.
 
The location of the directory where the query is located: pwd
The original meaning of the command in English: print working directory
 
Remove empty directories: rmdir 
rmdir [directory name]
The original meaning of the command in English: remove empty directories
 
Delete a file or directory: rm
The original meaning of the command in English: remove
Options:
  -i prompt before every removal
  -r delete directory (recursive)
 -f force (force)
 -v show the command execution process (verbose)
rm -rf / is equivalent to linux suicide
 
Copy command: cp
cp [options] [source file or directory] [target directory]
The original meaning of the command in English: copy
Options:
   -s Copy as a symbolic link file, that is, a shortcut (symbolic)
   -r copy directory (recursive)
   -p Copy with file attributes (preserve)
   -d If the source file is a linked file, copy the link attribute (no-dereference)
   -a is equivalent to -pdr
   -f force force
 
Cut or rename command: mv
mv [original file or directory] [target directory]
The original meaning of the command in English: mv
 
 
The role of common directories in Linux
bin can be executed by any user
sbin superuser can execute
Bin and sbin in the root directory, bin and sbin in the usr directory, these four directories are used to save system commands.
boot start command
dev hardware file
etc default configuration file
Where to save the lib function library
home The home directory of ordinary users
The home directory of the root superuser
media mnt misc empty directory, mount.
tmp temporary directory
The proc/sys directory cannot be directly manipulated. It saves the overload point of the memory and writes it directly to the memory.
var system related document content (variable document directory)
 
You can put content in the home directory root (administrator) or home (ordinary user), as well as in the tmp directory.
 
Link command: ln (generate link file)
ln -s [source file] [target file]
The original meaning of the command in English: link
Options
  -s create soft link
 
 
Hard Link Features:
1. With the same i-node and storage block, it can be regarded as the same file
2, can be identified by i-node
3, can not cross partitions
4, cannot be used for directories
 
 
Soft link features: (recommended)
1, similar to windows shortcut
2. The soft link has its own i-node and block block, but only the file name and i-node number of the original file are stored in the data block, and there is no actual file data.
3, lrwxrwxrwx l soft link (soft link file permissions are 777)
4. Modify any file and change the other one
5. Delete the original file, the soft link cannot be used
 
 
Section 3: File Search Commands
file search command locate
locate filename
Search by filename in backend database for faster search
/var/lib/mlocate (backend database searched by the locate command)
updatedb (update database)
 
Open the /etc/updatedb.conf configuration file
PRUNE_BIND_MOUNTS="yes" //The filter rule takes effect
PRUNEFS //Do not search the file system
PRUNENAMES=".git .hg .svn" // do not search for file types
PRUNEPATHS="/afs /media /net /sfs /tmp /udev /var/cache /var/spool/cups /var/spool/squid /var/tmp" //paths not searched
 
 
command search command whereis and which
whereis command name
The path where the search command is located and the location of the help documentation
Options:
  -b only look for executables (binaries)
  -m Find only help files (manual)
 
linux is interesting:
   whoami //Display current user
   whatis command name //Display the function of the command 
 
which command name
Search for the alias of the command and the path where the command is located
(which cd or whereis cd cannot be found, because cd is a function that comes with the shell)
 
file search command find
find 【Search range】【Search conditions】
 
find   /   -name    install.log
#Avoid large-scale search, which will consume a lot of system resources
#find is to search the system for matching file names. If you need to match, use wildcard matching, wildcard is an exact match
 
? any character
* characters of any length
[]Any character in brackets
 
 
find   /root   -iname  install.log
#not case sensitive
find   /root   -user    root
#Search by owner
find   /root   -nouer
#find files without owner
Those without owners are junk files (special conditions of Linux: ① those generated by the kernel (proc/sys), ② foreign files (U disks) should not be deleted at will), and can be deleted. .
 
find / var / log / -mtime +10
#Find files modified 10 days ago
-10 files modified within 10 days
10 10 Days Modified files on the day
+10 files modified 10 days ago
 
atime file access time (access)
ctime changes file attributes (change)
mtime Modify file content (modify)
 
 
find   .      -size     25k
.represents the current directory
size indicates the file size
 
-25k,25k,+25k (Kilobytes should be lowercase)
-25M, 25M, +25M (megabytes should be capitalized)
The unit must be written, the default unit is block. It uses the block of the sector in the hard disk, not the block of the partition
 
find. -inum 262422
#Find the file whose i node is 262422
 
 
Complementary use
ls -i // Know the file name to find the i node
find //Know the i node to find the file name
 
 
find   /etc   -size  +20k  -a   -size   -50k
#Find files in the /etc/ directory that are larger than 20kb and smaller than 50kb
-a and logical AND, both conditions are met
-o or logical or, two adjustments can satisfy one
 
 
find /etc -size +20k -a -size -50k -exec ls -lh {} \; standard format
#Find files larger than 20kb and smaller than 50kb in the /etc/ directory, and display detailed information
#-exec/ -ok command{}\; perform action on search results
The command after exec processes the previous result, so not all commands can be placed here.
 
 
 
String search command grep (with matches)
grep [options] string filename
#Match matching strings in the file
Options:
   -i ignore case
   -v exclude the specified string (invert-match)
 
Difference between find command and grep command
find command: Search the system for qualified file names. If matching is required, use wildcards to match, and wildcards are exact matches.
grep command: Search for strings that meet the conditions in the file. If you need to match, use regular expressions to match, and regular expressions include matching.
 
 
 
Section 4: Help Commands
Help command: man 
man command
#Get help for the specified command
 
level of man
1. View the help of the command
2. View help for functions that can be called by the kernel
3. View the help of functions and function libraries
4. View the help of special files (mainly files in the /dev directory)
5. View the help of the configuration file
6. View the help of the game
7. View other miscellaneous help
8. View help for commands available to system administrators
9. View the help of kernel-related files
 
See which level of help a command has
man -f command
equivalent to
whatis command
 
First use whatis to see which levels of help the command has, and then call the corresponding man level.
Example:
man -5 passwd
man -4 null
man -8 ifconfig
 
View all help related to commands
man -k command
equivalent to
apropos Command
 
 
option help: help
command --help
 
shell internal command help
help shell internal command
 
To determine whether it is a command inside the shell, use whereis
whereis ls can find the path where the command is located, indicating that it is not a shell internal command
whereis cd cannot view the path where the command is located, indicating that it is an internal shell command
Example: help cd
 
Detailed command help: info
info command
 
 
Section 5 Compression and Decompression Commands
Compression format: .zip .gz .bz2  
Commonly used: .tar.gz .tar.bz2
 
.zip format decompression
zip compressed filename source file
#Compressed file
zip -r zip filename source directory
#zip directory
 
decompress
unzip compressed files
 
 
.gz format decompression
gzip source files
#Compressed to a compressed file in .gz format, the source file will disappear
 gzip -c source file > compress file
#Compressed to .gz format, the source file is retained
gzip -r directory (gzip will not pack)
#Compress all subfiles in the directory, but cannot compress the directory
 
decompress
gzip -d compresses files
gunzip compressed files
 
 
 
Unzip in .bz2 format (can't unzip directory)
bzip2 source file
#Compressed as a compressed file in .bz2 format, the source file will disappear
bzip2 -k source file
#Compressed to .bz2 format, the source file is retained
 
decompress
bzip2 -d compresses files
bunzip2 compressed file
-k keep compressed files
 
 
Packaging command: tar
tar -cvf package filename source file
Options:
   -c pack
   -v show process
   -f specifies the packaged file name
 
unpack command
tar -xvf package filename
Options
   -x unpack
 
 
.tar.gz compression format
In fact, the .tar.gz format is first packaged into .tar format, and then compressed into .gz format
tar -zcvf archive name source file
Options:
   -z compress to .tar.gz format
 
decompress
tar -zxvf archive name
 
 
.tar.bz2 compression format
tar -jcvf archive name.tar.bz2 source file
Options:
   -z compress to .tar.bz2 format
 
decompress
tar -jxvf archive name.tar.bz2
 
Unzip to the specified location
tar jxvf compressed package name.tar.bz2 -C specified directory
 
Compress multiple files to a specified location
tar -zcvf absolute path/compression package name.tar.gz multiple files (separated by spaces)
 
Just look at the file, not unzip it.
tar -ztvf archive name.tar.gz
 
 
Section 6: Shutdown and Restart Commands
shutdown command
shutdown [options] time
  Options:
    -c cancels the previous shutdown command
    -h shutdown
    -r restart
 
Halt/poweroff/init 0 can be shut down, but it is not safe, just know
reboot/init 6 can be restarted, reboot is better
 
system run level
0 shutdown
1 Single user (similar to Windows Safe Mode, start the minimum program, mainly do system repair)
2 Incomplete multi-user, no NFS service (NFS service is a linux file sharing service)
3 Fully multi-user (that is, the character interface we are using now)
4 Unassigned
5 Graphical interface
6 Reboot
 
 runlevel can see which level you are currently in
 
logout logout
When using a remote management tool to manage Linux, it is not a big problem without logging out, because Linux can log in up to 256 users at the same time, but if you manage Windows remotely, it will cause users to get stuck, and there are fewer logged-in users at the same time, so you can only restart the server. . Restarting the server brings a poor user experience to the client. Try to develop the habit of logout, don't close it directly.
 
 
 
Section 7: Other Common Commands
Mount command (equivalent to the Windows allocation drive letter)
 
mount Query the mounted devices in the system
mount -a automatically mounts /etc/fstab  
//U disk and CD-ROM drive are not recommended to be automatically mounted, because Linux is very honest. If you forget to put the CD-ROM drive, and the CD-ROM file is not found when Linux is automatically mounted, it will cause the system to fail.
 
mount [-t file system] [-o special options] device file name mount point
Options:
-t file system: add the file system type to specify the type of mount, which can be ext3, ext4, iso9660 and other file systems
-o special options: additional options to mount can be specified
 
Mount the CD (sr0):
① Put the disc
②Create a mount point mkdir /mnt/cdrom
③ Mount command mount -t iso9660 /dev/sr0 /mnt/cdrom/   
#The device file name can also be /dev/cdrom, which is a soft link, but it is recommended to write sr0
#-t iso9660 can also be omitted
④Read data cd /mnt/cdrom
 
Uninstall command (be sure to remember to uninstall)
umount device filename/mountpoint   
#If the device is busy, it may be because you occupy the directory, you should cd to exit
 
Mount the U disk (usually sdb1)
①View the U disk file device name fdisk -l
②Create a mount point mkdir /mnt/usb
③ Mount command mount -t vfat /dev/sdb1 /mnt/usb
 
Note: Linux does not support NTFS file system by default
 
 
User login viewing and user interaction commands
 
w View login user information, more displayed
who View login user information
last Query the user information of current login and past login, read /var/log/wtmp by default
#If you use vi /var/log/wtmp, it will read garbled characters, so as to avoid artificially modifying the log file. After all, last can view the user's login information and determine whether other people have logged in.
lastlog View the last login time of all users by default reads /var/log/lastlog
 
 
 
 
Chapter 3: Shell Basics
 
 
 
.
 
 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325104956&siteId=291194637