Basic Linux operations (1): Basic linux operations
I am so tired that I have to write a summary. I am not willing to say anything that violates my mind, but I want to record my current status and mood. The content of my life is very rich, but it is actually quite plain. Apart from the surprises brought to me by my loved ones, I cannot smell anything new. I don't know how much value I have and how much value I have been recognized, but I can't be annoyed. After all, I am a procedural ape with connotation. So I thought, I was not comprehensive enough to be confident enough to be brave enough. If I couldn't change the environment, I could change myself. In case one day, you could see red on the blue beach. One day... I. Partition 1, partition 1.1, primary partition: up to four (512 bytes for each sector, 446 bytes for record information, and 64 bytes for Record Partition, each 16 bytes represents a partition and a maximum of 4 partitions, which is determined by the hard disk structure .) Extended partitions: up to one partition, up to four primary partitions and extended partitions. data cannot be written and can only contain logical partitions. The Partition Number must start from 5, the number of the primary partition.
1.2. Data blocks in the Table: data blocks of the same size as partitions. The size can be set (default: 4 kb ). 1.3 list of partitions in the Table: records the file ID, file storage location, modification time, permissions, and other information. 2. All files in Linux 3. mount point (equivalent to windows distribution drive letter) 3.1. Use directory as drive letter in linux (some directories must be in the same partition system as the root directory for normal use) for ease of management,/boot AND/home partitions are separately built to represent partitions. Ii. Linux installation 1. Press F2 when the disk is started, go to the Boot list item, and set the disc drive to the first Boot. After the installation is complete, set the disk to the first Boot. 2. Partition 3. Linux Command 1. Permission representation-rw-r -- first (-(file), d (directory), l (soft link file )) each of the last nine digits represents the permissions (owner, owner group, and other persons. R read, w write, x execute 2. The directory Processing Command mkdir-p recursively creates mkdir-m770 and sets the permission to touch to create the file cd-back to the last directory rm-rf (-r delete directory,-f mandatory) the name of the new file in the cp target file destination (the copy directory is added after the cp-r) mv is the same as that in the cp. There are no bin and sbin in under the root directory of the-r3 and file processing commands, both bin and sbin In the usr directory are used to save system commands. All bin permissions can be used, and sbin can only be used by the root user. The/boot directory is the boot directory/dev hardware file/etc System Default Configuration File/home common user directory/root Super User directory/lib function library/media,/mnt,/misc as external storage the drive letter/proc and/sys of the device store the memory overload point/tmp temporary directory/usr system resource storage directory/usr/bin/system command (Common User) /usr/sbin/system command (superuser) /var system documentation/root directory ── bin stores user binary files ├ ── boot stores kernel boot configuration files ├ ── dev stores Device Files ── etc stores system configuration files ── home user main directory ── lib dynamic shared library ── lost + found File System Recovery recovery file ├ media detachable storage media mount point ├ ── mnt File System temporary mount point ── opt append application package ── proing directory of proc system memory, provide kernel and process information ── root User main directory ── sbin stores system binary files ── srv stores service-related data ── sys Virtual File System mount point ── tmp stores temporary files ── usr stores user applications └ ── var stores changed files such as emails and system logs. 4. The connection command lnln-s is the hard link soft link of the original file. 5. The search command locatelocate is in the/var/lib/mlocate background. search in the database, updatedb is used to update the database. The location of the whereis ls command includes the help document-B is used only to find the executable file-m is used only to find the Help File whoami. The current user name whatis lswhich ls can see the alias echo $ PATH. it defines the path of the system operating room command to find and search to add find/-name install. what is the wildcard * arbitrary content in log search? Find/-name "*" find/root-iname install. logs are case insensitive. find/root-user the root owner is the root file. find/root-nouser does not have the owner file (junk file 1. in addition to the files generated by the kernel in sys and proc. external files) find/var/log (atime File Access time ctime change file attribute mtime Modify file content) (-10 ten days in 10 days on the day + 10 ten days ago) find. -size (-25 k 25 k + 25 k 2 M) find. -inum 262422-a and-o orfind/etc-size + 20 k-a-size-50 k-exec command (ls-lh, rm-rf ){}\; result-exec {}\; grep [Option] string file name-I ignore large Lowercase-v exclude the specified string to search for the specified string in the file. 6. The HELP command man-f passwd displays the level (equivalent to whereis, which allows you to view the configuration and level) man 5 passwdman-k passwd (equivalent to the help of apropos to find the relevant command) command --helpcdcannot execute, it indicates that the system has a shellinternal command 7、compressed and uncompressed. zip can be used on Windows and Linux with zip-r longz.zip longz () unzip longz.zip gzip-c source File> abc.gz reserve source file, compressed file to abc.gz gzip-d or gunzip decompress (directory plus-r) bzip2 cannot compress directory bzip2 source file (do not retain source file plus-k keep) bzip2-d (Extract, add-k to keep the compressed file) bunzip2 (Extract, add-k to keep the compressed file) tar-cvf (-c packaging-v display process-f specifies the file name after packaging) t Ar-cvf longz.tar longz gzip longz.tar(longz.tar.gz) tar-cvf longz.tar longz bzip longz.tar(longz.tar.bz2) tar-xvf (-x unpacked) tar-xvf longz.tar tar .tar.gz format tar extract tar-zxvf file name-C tartar into .tar.bz2 format tar unzip decompress tar-jxvf file name-C specified location tar-ztvf (t test) check the content in the compressed package. 8. Shut down and restart the shutdown switch to save and load the context, making it safer. Shutdown (-r restart-h shutdown-c cancel the previous shutdown restart command) & (& background execution) reboot restart init (add a number) runlevel query system on which level (the last level and current level are displayed)/etc /. in the inittab, set the level to enter after the boot (X generally represents the graphic interface ). Logout and log out (important) 9. mount the mount command (view the mounted devices in the System) mount-a (automatically mount according to the/etc/fstab configuration) mount [-t File System (ext4 disc: iso9660)] [-o Special options (options)] device file name mount point shell script must start #! /Bin/bash start with chmod 755 hello. sh grant the execution permission mount-o remount, noexec/home/Remount the disk. Do not mount the disk to create a mount point mkdir/mnt/cdrom/mount the disk-t iso9660/dev/sr0/mnt/cdrom/(/dev/cdrom-> sr0 soft link) mount/dev/sr0/mnt/cdrom detach a CD umount device file name or mount point (your current path cannot be under the CD directory) mount a usb flash disk (sda1 second sdb1 third sdc1 on the computer itself) to view the identified hard disk fdisk-l mounted mount-t vfat/dev/sdb1/mnt/usb/Note: linux does not support the ntfs file system. (Mobile hard disk does not allow direct mounting, through the ntfs-3g can read the mobile hard disk. Linux is usually output through the network .) View User Logon Information w who (current user) last (all logon records) lastlog (view the last Logon Time of all users) 4. shell (Shell in C shell Linux is named Bashecho) echo $ SHELL check which shell (/etc/shells) echo [Option] [Output content] (-e: supports character conversion controlled by backslash, for example) is used by the current system) echo-e "\ e [1; 31 m cute \ e [0 m" script run: grant the execution permission to run chmod 755 hello directly. sh uses Bash to call and execute the script bash hello. hBash Basic Function Command alias view alias (view all aliases) set alias ls = 'ls -- color = never '(restart failed) in order to permanently take effect, write vi ~ to the configuration file ~ /. Bashrc takes effect immediately. source ~ /. Bashrc: delete alias unalias (delete temporarily) echo $ PATH some environment variable directories separated by colons 5. history commands history [Option] [history commands save files] (-c Clear history command-w write history commands in the cache to history command to save the file ~ /. Bash_history) ls-alh to view detailed historical data, 1000 records are saved by default, and can be modified in/etc/profile. "! N "repeats the n-th historical command"!" Repeat the previous historical command "! String "Repeat the last command output with this string headers to redirect the standard output: ifconfig> cs. log (> overwrite file) (> append Write File) standard error output redirection: ifconfig 2> cs. log (2> overwrite file) (2> append Write File) ls &>/dev/null (& replace all correct errors with write) cat xdy> access. log 2> error. log (correct errors are saved separately) Input redirect wc [Option (-c counts the number of bytes-w counts the number of words-l counts the number of rows)] [file name] wc + Option +, enter the content, and press ctrl + D to calculate the number of rows, words, and characters you have entered wc [<] access. contents in log statistics file wc <ddy statistics input until ddy direct character content 6. Various characters 6.1, pipeline operators multi-command order execution pipeline operator command 1 | command 2 command 1 is correct the output is the operation object of command 2 ls-l/etc | more View ls results in more form. netstat-an: view all network links in Linux. netstat-an | grep "ESTABLISHED" | wc-l: Check the number of people connected to the server. (very common)) 6.2. Is the wildcard ls dzp * ls dzp? Ls dzp [0-9] [0-9] ls dzp [^ 0-9] * (^: logical non) 6.3. In Bash, other special symbols aa = 123 echo $ aa ($ + variable name: Get variable value) in single quotes have no special meaning and are all strings. In double quotes, "$", "", and "\" are exceptions and must be escaped. Aa = 'LS' (use the backquotes to execute ls first, and then assign the value to aa) <=> bb = $ (date) (recommended method) # comment \ escape character, it is equivalent to enclose the content in single quotes to make the special symbols meaningless.