In Linux, everything is a file. All things are files, including commands, hardware, and software.
Linux does not differentiate files by extension, these conventional extensions (. gz,.rpm,.html,.sh) are just a token. Unlike Windows, the extensions in Windows are designed to recognize machines. and the extension in Linux is for people to recognize.
The corresponding file name for the hardware device in Linux is as shown in
Linux partitions must be divided into three zones
root partition /(mount point root directory, the root directory to save all other data, the root directory if there is no hard disk space, the root of a lot of data will not be stored in place) swap partition (swap partition, can be understood as virtual memory, when the real memory is low, You can use the disk space in the swap partition as memory, if the memory is less than or equal to 4GB, the recommended swap allocated memory twice times, if the memory is greater than 4GB, the proposed swap space and memory is equal, do not need mount point) Recommended partition: boot partition , recommended 200MB (mount point/ Boot directory,/boot contains the relevant data for system boot, if not separate partition, will be stored in the same storage space with the root partition, if the root partition is full will cause the system to fail to start
~] #root current logged on user localhost hostname ~ current directory (home directory) # Superuser's Prompt
ls command
LS-------Display Inode
File permissions (10-bit), first bit for file type, followed by each 3-bit set of-rw-r--r---file type (-file d directory l soft link directory) rw-u owner r--G belongs to group r--o others R Read W write X Execute
Directory Operations
Create a Directory
-p [Directory name]
Switch directories
CD [contents]: Switch directory (change directory)
CD ~: Go to the current user's home directory CD-: Go to the last catalog CD. : Go to the top level directory CD. : Enter the current directory
PWD: Query directory location (print working directory)
rmdir [directory Name] (remove empty directories) #只能删除空目录
Delete a file or directory rm-rf [file or directory] (remove) option-r: Delete directory option-F: Force RM [File name]: Prompt to delete rm-r [directory]: Delete Directory is required to add-R, the directory contains sub-files, will continue to ask whether to delete RM-RF [Directory]: Delete directory, do not ask whether to delete the pure character interface directly without the Recycle Bin. Note Suicide instructions: RM-RF/rm-rf/tmp/*: Delete contents of tmp directory rm-rf/tmp/ : Delete tmp directory recommendations: Delete files or directories used to command RM-RF [files or directories]
Copy command CP [Options] [Original file or directory] [destination directory] (copy) option-r: Copy directory option-P: File attribute copy option-D: Wakahara file is a linked file, Copy Link Property option-A: equivalent to-PDR Select all
Cut or rename the command MV [original file or directory] [target directory] (move) MV olddir//targetdir/cut directory without adding-RMV oldname newname when the original file and destination directory, in the same directory, is renamed command
Link
-s [original file] [target file]-S (soft): Create soft link
Non-s created is hard link hard link and soft link hard link: 1, have the same I (inode) node and storage block block, can be regarded as the same file, 2, can be identified by the I node, 3, can not cross the partition, 4, can not be used for the directory;
5, delete one another can still be used; (two objects reference the same memory at the same time, delete an object does not affect memory) soft Links: 1, similar to Windows shortcuts, 2, the software has its own I node and block blocks, but the data block only save the original file name and I node number, There is no actual file data; 3, LRWXRWXRWXL soft link, soft link file permissions are rwxrwxrwx;4, modify any file, the other file is changed, 5, delete the original file, soft links will not be used; 6, when creating a soft link, you must use absolute path;
Find command
Current system time Command: Date
file name Search command locate (faster than Find)
Equivalent to fuzzy query
Locate is the database that queries/var/lib/mlocate, and the database is updated daily. So the files created within today are not searchable.
UpdateDB is the command to update this database.
The configuration file for the database is/etc/updatedb.conf
prune_bind_mounts = "Yes" (open search limit)
Prunefs = (file system not searched)
Prunenames = (file type not searched)
Prunepaths = (path not searched)
Command Search Command : Whereis (can only search system commands, cannot search for the normal files created in thin air, nor search for Linux built-in commands)--m: Find help files only
File Search command: Which (not only can see the path of the command, if there is an alias, you can see the alias) ls = ' ls--color=auto ' (LS display color, set to Automatic)
WHOAMI Show current Operation user
Whatis ls Viewing the role of LS
echo $PATH View Environment variables
Find search (avoid a wide range of searches, will be very wasteful of system resources, it is not recommended to search directly in the "/" directory) format: Find "search scope" "Search criteria"; find/home-name file name; Note: The Find search default is an exact match.
"*" matches any character, for example: Find/home-name "*test*", showing all files with test name, or example: Find/home-name "*", all files under the home directory, including hidden files. “?” Matches any one of the characters, "" "matches any of the characters in parentheses, for example: Find/home-name" Test "12" ", displays Test1 and test2 files, or find/home-name" "12" * "Showing files beginning with 1 and 2.
Find by file time search Find/home-mtime +10 in the home directory, look for files modified 10 days ago Find/home-mtime 10 in the home directory, find the same day 10 days ago modified file find/home-mtime-10 in H ome directory, find files modified within 10 days Atime file access time CTime change file properties mtime modify file Contents
Find/root-iname test does not differentiate the test case format to be searched Find/root-user root Searches all files belonging to the root user in the root directory find/root-nouser files that have no owner, Liunx, each Files have the owner, if not, then generally are garbage files, but there are special cases, such as the kernel generated files, there is no owner, generally in the proc and SYS directory, as well as foreign files, that is, the file is copied into the U disk will ignore the owner.
Find directory-size File size Note: The file size is in lowercase k and uppercase M. -A indicates that and-o represents orfind/etc-size +20k-a-size-50k-exec ls-lh {} \;
-exec {} \; Fixed format, which means that the following command is processed directly to the previous search results
Find a string in a file
grep [option] String file name (string using "" Surround, result is row record)-I ignore case-V exclude specified string
Help commands
Man is the initials of the manual 1.man + command name-----most commonly used help commands, such as the function of the man LS main display command and the use of the command into the Man command operation, 1,:Q exit 2, enter:/-D search "-D" string, press N down "-D", shift+ N Search for the "-D" Man's Level: 1, see Help for the command 2, see Help for a function that can be called by the kernel 3, see Help for Functions and libraries 4, see Help for special files (mainly files in the/dev directory) 5, view Help for a configuration file 6, view game help 7, See other miscellaneous Help 8, see Help for System administrator commands available 9, view and help for kernel-related files (not necessarily present) see what level of Help the command has man-f command is equivalent to Whatis command to view single-level command help such as: Man-5 passwd View Level 5 passwd help man-4 null man-8 ifconfig If you do not hit the rank number, the man command opens the minimum level of information by default MAN-K command is equivalent to apropos command such as: Apropos passwd Search All the Help that contains the keyword "command" Help documentation
Man,--help,help,info A total of four commands to get help . 1. Command--help get options Help for example: LS--help2.help shell internal Command For example: Whereis can be used to determine whether a command is a shell internal command, LS under the/bin/has an executable file Description ls command is not shell internal command, The CD command does not have a corresponding executable file under/bin/, so it is the command that comes with the shell. The 3.info command info is very cumbersome and is a huge help document about the command, which contains instructions for each version of the command. -Enter: Enter the instructions with * sign-u: Go to the upper page-N: Go to the next Help section-P: Go to the previous Help section-Q: Exit
Compression and decompression
Common compression formats:. zip. gz. bz2 commonly used compression formats:. tar.gz. tar.bz2
. zip Compressed ZIP file name source file//Compress FilesZip-r Compressed directory name source directory//Compressed Directory. zip format uncompressed Unzip compressed file//Unzip the file. gz format compressed gzip source files//Compress files in. gz format, the source file disappearsGzip-c source files > Compressed files//compressed to. gz format, source files reservedGzip-r Directory//Compress all sub-files in the directory, but cannot compress the directory. GZ uncompressed gzip-D Compressed Files//Unzip the fileGunzip Compressed Files//Unzip the filebZIP Compressed bzip2 source file name//compressed files, source files will disappearBzip2-k source File//Preserve source files after compression*bZIP cannot compress directory bZIP extract bZIP-D Compressed Files//Unzip the bzip2 fileBunbzip Compressed Files//Compress FilesPackaging Command Tartar-CVF package file name source file//compress to tar formatTAR-ZVCF compressed package name. tar.gz Source File//compress to. tar.gz formatTAR-JVCF compressed package name. tar.bz2 Source File//compress to. tar.bz2 formatDecompression Tartar-XVF Package file name//unzip the tar format fileTAR-ZXVF compressed package name. tar.gz//unzip. tar.gz format FileTAR-JXVF compressed package name. tar.bz2//unzip. tar.bz2 format File-C: Packaging-V: Display process-F: Specify the file name after packaging-x: Unpack-Z: Compressed to. tar.gz Format-J: Compress to. tar.bz2 format Other uses tar-JXVF package file name-C absolute Path//Specify the location of the decompressionTAR-ZCVF Absolute Path (/tmp/) + package file name source file source file//extract multiple files to the specified pathTAR-ZTVF Compressed Package file name//viewing files in a compressed package
Shutdown command
shutdown [options] Time -H shutdown-R Restart-C cancel all one shutdown command shutdown-r now #立马重启halt poweroff inti can also be turned off But unsafe reboot init 6 can also restart RunLevel view RunLevel Former level current level logout exit the current user, that is, unregister the shutdown command: "Shutdown -H 05 : 30 -h now "shut down immediately" Shutdown -R 05 : 30 "set 05:30 restart" shutdown -r Now "immediately restarts" shutdown -C "Cancel the previous shutdown or restart command
Note: 1, the above timed shutdown or restart command after execution, the computer will be stuck there, the current user and other logged on users will not be able to operate until shutdown or restart. At this time, if the current user press "CTRL + C" can cancel this shutdown or restart operation, and other users press "CTRL + C", then the shutdown or restart operation will not be canceled, but can exit the interrupt, continue to do other operations. 2, if you want to shut down the command in the background, you can enter & after the command, for example: "Shutdown-h 05:30 &", so that the current user and other login users of the front desk will not be interrupted (if interrupted, click Enter); 3, at any time, Any user who enters the "shutdown-c" command can cancel the shutdown or restart operation. 4, the later time can use the "+m" format, indicating how many minutes after the execution. You can also use the "hh:mm" format, indicating that the specified time is executed, the time is 24-hour system, 5, if remote login, and finally do not execute the shutdown command, because the boot needs to the computer room to start the line. Restart also as little as possible, if necessary to run, you should shut down the running services;
Mount command
(1) query and Auto mount Mount query system mounted device mount-A according to the configuration file/etc/fstab content, auto Mount (2Mount Command format mount [-t file system] [-o Special Options] device file name mount point option:-T File system: Add File System type to specify mount type, ext3,ext4,iso9660, etc. file system-o Special Options: Additional options for mounting can be specified example: Mount-O remount,noexec/home/#重新挂载/home partition, using NOEXEC permissions (3) Mount Disc mkdir/mnt/cdrom/#建立挂载点, empty directories can be Mount-T iso9660/dev/sr0/mnt/cdrom/or Mount/dev/sr0/mnt/cdrom/#挂载光盘 (4) unmount the disc umount device file name or mount point Umount/mnt/cdrom/or umount/dev/Sr0 (5) mount the USB flash drive Fdisk-l# View Device file name Mount-T vfat/dev/sdb1/mnt/usb/#vfat指的是fat32文件系统 #linux The NTFS file system is not supported by default
W View user information (with system resources) the load average:x.xx x.xx x.xx represents the average load (CPU memory) within 15 minutes of the system within 5 minutes of 1 minutes TTY: Terminal tty1 Local terminal pts/0 The first remote terminal idle: User idle time What: User is executing command who view user information (simplified) Last query current login and past login user information (can see reboot time) is actually view /var/log/ /var/log/lastlog can not directly see is also used lastlog look
Linux Common commands