Linux Basic Operations Command summary

Source: Internet
Author: User
Tags unzip bz2

1. Command basic formatroot User: [[email protected] ~] # or Normal User: [[email protected] ~] $ user @ host name directory [#|$] Administrator typeRoot User home directory:/rootCommon user home directory (e.g. Hadoop):/home/hadooppwd shows where you're currently locatedGeneral Command format: command [options] [parameter] parameters can be either complete or simplified, such as:-A and--all View directory information: LS ls-l ls-l dir size Unit B, if you want to display easier to identify size: Ls-lh,ls-i list The ID number of the file, the system is to identify the file by ID file permissions:-rwxr-xr--, the first is the file type:-Represents the file D for the directory L represents a soft link7 Types of Linux files: normal files, directory files, linked files, block device files, character device files, socket files, pipe files  2. directory file processingBuild directory: mkdir For example: mkdir ABCRecursive build directory: Mkdir-p For example: Mkdir-p abc/abcswitch The current directory: CD For example: CD/HOME/ABC, go to home directory: CD ~ or CD into the previous level directory: CD. Or on the upper deck CD. /.. /go to the last directory CD-Tab key Auto-completePrint current directory: PWDDelete files: RM filename such as RM ABCDelete file avoid prompt: rm-f ABCrecursively delete the entire directory: RM-RF dir such as rm-rf/tmp/* delete all files (including directories) in the TMP directory if you do not add * means to delete the TMP directory directlyDelete Empty directory: RmDir dirnamecopy file and rename: CP Abc/tmp/abcs not renamed: CP abc/tmp/copy Entire directory: Cp-r backto maintain consistent use of all properties, such as file modification time: Cp-a Source directory destination directory is equivalent to CP-PDR source directory r recursive p file attribute D if it is a linked file, copy the linked file propertyLs-l and LL equatemove files: MV source file or directory destination file or directory copy directory and file all the same without adding parameter source files and target files in the same directory directly with the MV implementation of the rename/bin/sbin/usr/bin/usr/sbin are all saved commands where/sbin and/usr/sbin can only be manipulated by the root user/ Dev Hardware device, mounting using/ etc configuration commonly used/Home and/root are user homes/lib System Library/media and/mnt and/misc are used to mount external storage devices, basically by creating a new directory under/mnt/proc and/sys are real-time data stored in memory, do not operate casually/ tmp temporary data storage directory/ usr Software installation directory such as/usr/java under the corresponding package, etc./var software installation corresponding configuration or documentation, etc.link command: lnhard link-Occupy hard disk block: and source files in the file index table data storage space exactly, inode consistent, are access to the same storage space, just two different locations, essentially the same file, if you delete a file, storage space will not be freed, another file can still be accessed normally, are removed, equivalent to a pointer or front and back door, hard links cannot be created across partitions because the same storage space cannot be accessed across partitions, only ordinary files under the same partition, not directories. The use of hard links can cause multiple ingress confusion and a large limit, so it is recommended to use soft linksHard Link creation: ln source file destination Path (destination path file name must be written in full)soft links, similar to Windows shortcuts, soft links have their own inode and storage space, just save the target file property information, including Inode node, location, etc., modify the soft link is actually modify the original file, delete the source file soft link invalidation, Deleting a soft link source file is also deletedSoft Link Creation (note that absolute paths must be used, otherwise saving relative directories results in an error): ls-s [Source file (directory)]/HOME/HADOOPTEST/APP/ABCD [target soft link]/tmp/test.soft  3. File Search
Search file Name: Locate file name principle: Search from Database index, support fuzzy query/var/lib/mlocate is the locate database.Update Locate Database (default one day update to avoid searching for new files): UpdateDBLocate Search configuration file/etc/updatedb.conf Configuration search filter Rules Search command: Whereis command nameFor example: Whereis LS can list the command corresponding program location, help document location; +-B View only the source program location,-M view only the Help document locationSearch command: Whatis command name, what roleFor example: Whatis ls lists what ls command does.Search command: Which command name such as which LS can be listed in what location, and list some of the highlighted parameter options such as LS--colr=auto and so on, and if the command does not show the location of these options, no other, cd command no location, The CD command is the shell environment comes with, or is the core command that kernel comes withcommands that are self-developed or defined in a command system environment (/bin,/sbin,/usr/bin,/usr/sbin These system default execution environments) or cannot be found under environment variables the most powerful search command: The Find commandSearch by file name: Find/-name Test.log It is best not to specify the root directory, otherwise it will be very slow, search by file name is an exact match, you can use wildcard characters, commonly used *? [], such as Find/tmp-name "*.log" best quotes Match string ExpressionsSearch for no user-owned files: Find/-nouser includes junk files, foreign files, kernel-generated filessearch files by owning User: Find/home-user rootSearch by Time: Find/var/log-mtime +10 find 10 days ago File content modified file,-atime file access time,-ctime file attributes were modified, 10 for 10 days in response to the action of the file, 10 for the 10th day before the date of the modified file Search by file size: find/home/hadooptest/-size 25k Search size 25k file -25k is less than 25k +25k is greater than 25k here K must be lowercase, by M search must be uppercase, by byte size is B must lowercase, usually add a single bit, if no unit represents the number of hard disk block blocks instead of B is more difficult to calculateSearch by file inode node: find/home-inum 26262logic and query use-a such as Find/home-size +20k-a-size-50k to find files larger than 20k and less than 50klogic or query is used with-oFind and show more information: Find/home-size +20k-a-size-50k-exec ls-lh {} \;-exec is the call command, {} \; is a fixed format, and the second command, which means that the output of the preceding command is given to the following command to continue execution, such as: Find/tmp-nouser-exec RM-RF {} \; Find and delete string Search: grepsearches the file for the line that contains the specified keyword, such as grep "size" abc.cfg the line in the Abc.cfg file that includes the "size" keyword and listsThe parameter-V is the exclusion keyword, and-I is ignoring case such as grep-v "define" Config.h find can be used together with grep find is a file name match, an exact match (you can use a wildcard match); grep is a text content search that contains matches (using regular expression matching)  4. Command Help
View command help, such as: Man LS can be through the page, the upper and lower keys, enter down the cycle of scrolling, press the Q key to exitto see a parameter on the help page input/Then input parameters such as-Q Enter, and then you can find the use of the-q parameter, press N to jump in order of multiple optionsman is divided into 9 levelsMan ls is to view the default levelman-f ls View ls exists several levels equal to Whatis LSview specified level of help with man 1 lsman-k passwd or apropos passwd view and passwd all related commands, if not very clear can be foundadditional help, such as: LS--help current shell terminal support Chinese helpget internal commands to help the CD, first use the Whereis CD to see if it is an internal command, and then use the help internal command to get assistance, internal commands can not be used--help or man to helpInfo ls View more detailed documentation, more detailed than man, and will show detailed documentation for multiple versionsThe Info Display page uses U to go to the previous level, N goes to the next section, p goes to the previous section, Q Exits  5. File Compression Archive Operationcommonly used compression formats:. zip. gz bz2. tgz tar.gz. tar.bz. tar.bz2 etc.compress files into zip:zip abc.zip abc.txtcompress directory into Zip:zip-r abc.zip./abc/Decompression Zip:unzip Abc.zip compress the file into Gz:gzip abc.txt without compressing the file name, automatically assigning the source file name after adding. GZ, after compression the source files are deletedcustom compression and do not delete source files: gzip-c source files > Compressed files (it is not recommended to use the-C is the output compression encoding, with the technique of redirection, not dedicated)Compressed directory: Gzip-r Directory This does not package, but the directory of each file is recursively compressed onceUnzip the file: gzip-d abc.gz or Gunzip abc.gz can be decompressed, after decompression will also delete the original package bz2 format compression: bzip2 source files do not retain source filesKeep source files after bzip2-k source file compressionbzip2 cannot compress directoryUnzip bz2 format: bzip2-d compressed package or BUNZIP2 compressed package two directories are not persisted by default the compression package plus-K can be preserved  Tar Pack: TAR-CVF package file name source file or directory-C Package-V Show Details-----Specify the file name after packagingFor example: TAR-CVF abc.tar./abc/can be compressed using BZIP2 or gzip after packagingtar unpacking: TAR-XVF Abc.tar- x is the release archive . tar.gz complete (. tgz general):Package: TAR-ZCVF abc.tar.gz abc/unpacking: TAR-ZXVF abc.tar.gzSpecify directory: TAR-ZXVF abc.tar.gz-c/home/appView uncompressed only: TAR-ZTVF abc.tar.gz . tar.bz2 Complete together:Package: TAR-JCVF abc.tar.bz2 abc/unpacking: TAR-JXVF abc.tar.bz2Specify directory by: TAR-JXVF abc.tar.bz2-c/tmp/View uncompressed only: TAR-JTVF abc.tar.bz2   6. Shutdown and restart commands (shutdown Restart is automatic graceful end service, compare recommendations) Restart after 10 minutes: Shutdown-rshutdown after 10 minutes: Shutdown-htimed restart: shutdown-r 05:30 &timed shutdown: shutdown-h 05:30 &Cancel timed command: Shutdown-cImmediate restart: shutdown-r now or Shutdown-r 0immediate shutdown: shutdown-h now or shutdown-h 0server because it is remote control, it is recommended to only reboot, not shutdownserver running process, it is necessary to properly shut down the service, save the corresponding data, orderly restart, after the start, orderly operation of various servicesOther shutdown commands: Poweroff, Halt, Init 0 are not recommended, will cause an abnormal end,Other restart commands: Reboot (relatively safe), Init 6 (not recommended)the init runlevel is divided into 7 calls to the appropriate level for the correspondingInit 0 Shutdowninit 1 Single user (equivalent to Windows Safe Mode, pure command line Interface minimum service)Init 2 is not fully multiuser and does not include NFS Services (command line)Init 3 Full multi-user (generally used way)Init 4 Not assignedinit 5 Graphical interfaceInit 6 restart runlevel View current system RunLevelsystem default RunLevel is present:/etc/inittab The last line specifies the default boot level exit the currently logged on user (Linux generally allows simultaneous logons of 256, Windows XP allows only 1 users, and later allow 2-8): Logoutremote SSH Shell management must correctly exit the user, otherwise the direct close window will occupy concurrency, the user does not exit, affecting server performanceLogout User: Logoutexit Shell:exit, usually return the user after the status code 0, it is recommended to use logout logoff  7. Mount Command mount to view the corresponding device currently mountedMount-a automatically mounts based on the contents of the profile/etc/fstabtry not to automatically mount the CD or USB flash drive, if you forget to insert the device, the system will not boot, it is recommended to mount only the system partition Mount Device: Mount [-t file system] [-o Special Options] device file name mount pointLinux Default support ext3, Ext4 file system, disc file system for iso9660 re-mount the partition with special options, such as: Mount-o remount,noexec/home/means to re-mount the home partition, and does not allow executable file executionafter the test must be changed back as soon as possible, to avoid prompting the lack of access to the abnormal illusion: Mount-o remount,exec/home/ To mount the disc process:1, set up mount point: Mkdir/mnt/cdrom2. Execute mount command: Mount-t iso9660/dev/sr0/mnt/cdrom where the-t option can be omitted because the system recognizes the disc file system by default, the error condition is normal because the default option is RW read-write, but the disc is read-only, so it can be ignoredunmount disc: Umount/mnt/cdrom or umount/dev/sr0 note that when uninstalling, the working directory must be outside the Mount directory to be uninstalled properly, so first exit the CD mount point and then specify uninstall (the uninstall command must be executed!). Otherwise the subsequent file will be faulted) Mount USB Drive process (FTA32 file system):1, u disk and HDD belong to the same system, so do not know the hardware files, so first use fdisk-l to view USB stick device files2, set up mount point: Mkdir/mnt/usb3. Mount: Mount-t VFAT/DEV/SDB/MNT/USB because the default Linux supports FAT, you can remove the-t:mount/dev/sdb/mnt/usbUninstalling USB drive: Umount/mnt/usb or Umount/dev/sdb device methods for mounting NTFS systems:1. Recompile the Linux kernel2, using ntfs-3g components mount, Mount-t Ntfs-3g/dev/sdb/mnt/usb (method simple, recommended)If you use an NTFS device under Windows, it is generally not necessary to mount it, it is recommended to form the habit of using the network to transmit dataLinux,unix Series (MACOSX) generally does not recognize the NTFS file system by default   8. User Login View W View current system run time and logged in user information, including terminal, login source IP, time and other informationWho and W are similar, but also display all the information of the logged-in user, content less than W, more streamlinedLast View login log information for all users of the server, including system restart time, can detect abnormal loginlast command corresponding file exists in/var/log/wtmp, wtmp is a binary file, not a text file, so can not be modified with the editor, is to prevent log tampering, if the last command is found to be abnormal, the server may invadeLastlog View All users last login information, determine whether to log in, is also stored in/var/log/wtmp

Linux Basic Operations Command summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.