Linux Common commands

Source: Internet
Author: User
Tags bz2 file permissions

Source: http://blog.csdn.net/ljianhui/article/details/11100625

People who have played Linux will know that there are really a lot of commands in Linux, but people who have played Linux have never bothered by the fact that Linux commands are so many, because we only need to master the commands we use most often. Of course you can also use to find the man, he will help you solve a lot of problems. However, everyone's purpose of playing Linux is different, so the commands they often use are very big, and I mainly use Linux for C + + and shell programs, so common commands can be different from a person who manages Linux systems. Because do not want in use is always East search, so summarize here, convenient for later view. Not much, let's talk about my most commonly used Linux commands. 1, cd command This is a very basic, is also a common need to use the command, it is used to switch the current directory, its parameters are to switch to the path of the directory, can be an absolute path, can also be a relative path. Example: [plain] View plain copy print?cd/root/docements # switch to directory/root/docements CD./path # Switch to the path directory in the current directory, "." Represents the current directory CD: /PATH # Switch to the path directory in the upper directory, "..." Represents the previous level directory 2, ls command This is a very useful view of the file and directory commands, list of the meaning, it has a lot of parameters, the following list some of my commonly used parameters, as follows: [plain] View plain copy print?-l: List Long data string, Include attributes and permission data for the file-a: Lists all the files, together with the hidden files (files that begin with.)-D: Lists only the directory itself, not the file data for the directory-H: List the file capacity in an easier-to-read manner (GB,KB, etc.) with the contents of the subdirectory List (recursively listed), equal to all files in that directory will be displayed note: These parameters can also be combined, the following two examples: [plain] View plain copy print?ls-l #以长数据串的形式列出当前目录下的数据文件和目录 LS-LR #以长 Lists all files in the current directory in the form of a data string 3, grep command This command is often used to parse a row of information, if there is information we need to display the line, the command is usually used with the pipeline command, for the output of some commands to filter processing, etc., its simple syntax is [plain] View Plain Copy Print?grep [-ACINV] [--color=auto] ' Find string ' filename its common parameters are as follows: [plain] View plain copy print?-a: Find the binary file as a text file-c: Calculate the number of occurrences of ' find string '-I: ignore the difference between the case and the big Lowercase is treated as the same-V: Reverse selection, which shows the line without a ' find string ' content # for example: # Remove the line containing MANPATH in the file/etc/man.config, and add the found keyword to the color grep--color=auto ' MANPATH '/ Etc/man.config # The output of the ls-l contains the letter file (case-insensitive) content Output Ls-l | Grep-i file 4, find command find is a very powerful search-based command, relatively speaking, its use is relatively complex, parameters are also more, so here will be to classify them listed, its basic syntax is as follows: [plain] View plain copy Print?find [PATH] [option] [action] # time-related parameter:-mtime n = = is a number, which means a file that was changed in "One Day" before n days;-mtime +n: Listed before n days (excluding n days itself) is changed     -mtime-n: Lists file names that have been changed within n days (including n days itself);-newer file: Lists a file name that is newer than file # For example: Find/root-mtime 0 # Find files that have changed within the current directory today # parameters related to user or user group name:-user Name: Lists files whose owner is name-group Name: List files that belong to the user group named name-uid N: List file owner as User ID n file-gid N:  Lists files to which the user group is a user group ID of n file # For example: Find/home/ljianhui-user Ljianhui # Find the files in the directory/home/ljianhui with the owner of the Ljianhui # Parameters related to file permissions and names: -name FileName: Find the file named filename-size [+-]size: Find larger than size (+) or small (-) file-tpye type: Find file of type file, the value of type is mainly: General file (f), device file (b, c), directory (d), connection file (L), socket (s), FIFO pipeline file (p);-perm Mode: Find file permissions just equal to the mode of the file, mode with a number, such as 0755;-perm-mode: Find file permissions must all include the mode permission of the file, mode is represented by a number-perm +mode : Find file permissions file with any mode permission, mode is represented by number # For example: Find/-name passwd # Find file named passwd files find. -perm 0755 # Find file permissions in the current directory of 0755 files found. -size +12k # Find files larger than 12KB in the current directory, note that C means byte 5, CP command is used to copy files, copy, it can also copy multiple files to a directory at once, its common parameters are as follows: [plain] View plain copy PRINT?-A: Copy the attributes of a file together with the properties of a file, rather than using the default, similar to-a, commonly used for backup-I: If the destination file already exists, the operation is queried for the action-R: Recursive continuous replication, for directory replication behavior-u: Destination file and source The file will be duplicated if it is different for example: [plain] View plain copy print?cp-a file1 file2 #连同文件的所有特性把文件file1复制成文件file2 cp file1 file2 file3 dir #把文 File1, file2, file3 Copy to directory dir 6, MV Command This command is used to move the file, directory or rename, the meaning of the move, its common parameters are as follows: [plain] View plain copy print?-f:force mandatory meaning, If the target file already exists and does not ask for a direct overwrite-I: If the destination file already exists, you will be asked to overwrite-u: If the target file already exists and is newer than the target file, the note: The command can move a file or multiple files one folder at a time, but the last target file must be " Directory ". Example: [plain] View plain copy print?mv file1 file2 file3Dir # Move the file file1, File2, file3 to the directory dir in MV file1 file2 # Rename the file file1 to file2 7, RM command This command is used to delete files or directories, and between remove, its common parameters are as follows: [Plain] Vie W Plain copy print?-f: is the meaning of force, ignore the nonexistent file, do not appear warning message-I: interactive mode, before the deletion will ask the user whether to operate-r: Recursive delete, most commonly used in directory deletion, it is a very dangerous parameter such as: [Plain] Vie W Plain copy print?rm-i file # to delete files, ask whether to do this before deleting rm-fr dir # force delete all files in dir 8, ps command This command is used to select a point in time to run the process and output, PR Ocess, its common parameters are as follows: [plain] View plain copy print?-a: All processes are displayed as-a: all processes not related to terminal-U: Related processes for active users-X: Generally used with A parameter to list more complete Information-L: Longer, more detailed PID information listed in fact, we just remember PS general use of command parameters can be, they are not many, as follows: [plain] View plain copy print?ps aux # view system All process data PS Ax # view All processes not related to Terminal Ps-la # View system All process data PS AXJF # View together with a portion of the process Tree State 9, the KILL command is used to transmit a signal to a job (%jobnumber) or to a PID (number), usually with PS and J The OBS command is used together with the following basic syntax: [plain] View plain copy print?kill-signal PID signal commonly used parameters are as follows: Note: The first number is the signal code, use can be used to replace the corresponding signal code. [Plain] View plain copy print?1:sighup, start the terminated process 2:sigint, equivalent to input CTRL + C, interrupt a program to 9:sigkill, forcing the interruption of a process 15:sigterm, Terminates process 17:sigstop with normal end-of-process mode, equivalent to input CTRL + Z, pauseA process for example: [plain] View plain copy print?# at the normal end of the process to finally the first background work, you can use the Jobs command to view the background of the first worker process kill-sigterm%1 # re-modify the process ID of the PID Process, PID can be filtered using the PS command plus the grep command to get Kill-sighup PID 10, killall command This command is used to send a signal to a command-initiated process with the following general syntax: [plain] View plain copy Print?killall [-iie] [command name] its parameters are as follows: [plain] View plain copy print?-i: interactive meaning, if you need to delete, you will be asked the user-E: to indicate the following command name to Consistent, but command name cannot exceed 15 characters-I: Command names ignore case # For example: Killall-sighup syslogd # reboot syslogd 11, File command This command is used to determine the basic data of the files that are received after the Because the type of the file under Linux is not the suffix of the future, so this command is very useful for us, its usage is very simple, the basic syntax is as follows: [plain] View plain copy print?file filename #例如: file./test 1 2. Tar command This command is used to package the file, the default is not compressed, and if the corresponding parameters are specified, it will also call the appropriate compression programs (such as Gzip and bzip) for compression and decompression. Its common parameters are as follows: [plain] View plain copy print?-c: New packaged file-T: View the contents of the packaged file contains the filename-x: Unpack or unzip the function, you can use the-C (uppercase) to specify the extracted directory, note that-c,-t,-x can not simultaneously out Now in the same command-j: Compression/Decompression with BZIP2 support-Z: Compression/decompression with GZIP Support-V: During the compression/decompression process, the file name being processed is displayed as-f filename:filename to the files to be processed-C di R: Specify a directory for compression/decompression dir The above explanation can already let you faint, but usually we just need to remember the following three commands: [Plain] View Plain COPY print? Compression: tar-jcv-f filename.tar.bz2 file or directory name to be processed query: Tar-jtv-f filename.tar.bz2 extract: Tar-jxv-f filename.tar.bz2-c To unzip the directory note: The file name does not have to be the end of the suffix tar.bz2, here is mainly to illustrate the use of the compression program for bzip213, Cat command to view the contents of a text file, followed by the file name to view, usually available pipelines with more and less to use, This allows you to view the data in one page. Example: [plain] View plain copy print?cat text | Less # View the contents of the text file # Note: This command can also use less text instead of 14, the CHGRP command is used to change the user group the file belongs to, its use is very simple, its basic usage is as follows: [plain] View plain copy print?c HGRP [-R] Dirname/filename-r: Persistent changes to all files and subdirectories for example: Chgrp users-r./dir # Recursively modify the user group for all files and subdirectories under dir directory to users 1 5, chown Command This command is used to change the owner of the file, and the CHGRP command is used the same way, just modify the file attributes are different, no longer detailed. 16, chmod command This command is used to change the permissions of the file, the general usage is as follows: [plain] View plain copy print?chmod [-r] XYZ file or directory-r: Continuous change with recursion, that is, all the files in the subdirectory are changed at the same time, Chmo D can also use the U (user), G (group), O (Other), a (all) and + (join),-(delete), = (set) with rwx to make changes to the permissions of the file. [Plain] View plain copy print?# For example: chmod 0755 File # change files permissions to-rxwr-xr-x chmod g+w File # Add user group writable permissions to files ' permissions 18, Vim command This command is primarily used for text editing, which takes one or more file names as parameters, opens if the file exists, and creates a file with the file name if it does not exist. Vim is a very useful text editor, it has a lot of very useful commands, hereSay no more. You can download a detailed description of VIM's common operations from here. 19, gcc command for a Linux development C program, this command is very important, it is used to C language source program files, compiled into an executable program, because many parameters of g++ and it very similar, so here only to introduce the parameters of GCC, its common parameters are as follows: [Plain] View plain copy Print?-o:output to specify the file name to generate an executable file-C: Used to generate the source file (. o), and to prevent the compiler from creating a complete program-I: Increase the path of the search header file at compile time-l: Increase compile-time search Path to the static connection library-s: Generate the source file assembly code file-LM: A function library named LIBM.A in the directory of the standard library-lpthread: The line libraries-std= implemented by the connection NPTL: used to specify the version of the C language to use # for example: # Put the source file test . c is compiled into an executable program in accordance with the C99 standard test gcc-o test test.c-lm-std=c99 #把源文件test. C converted to the corresponding assembler source file Test.s gcc-s test.c 20, Time command This command is used to measure a life The execution time of the order (that is, the program). It's very simple to use, just as you would normally enter a command, but add a time to the front of the command, for example: [plain] View plain copy print?time./process time PS aux after the program or command runs, at the end of the three output Time, which are: User CPU time, the user CPU time that the command executes, that is, the command executes the sum of time in the user state; system: System CPU time, the amount of time that the command executes is spent on the CPU, that is, the command executes the sum of time in the kernel mentality; Real: actual time , the elapsed time from the command line to the end of the run; note: The sum of the CPU time and the system CPU time is CPU time, that is, the total amount of time that the command consumes CPU execution. The actual time is greater than the CPU time, because Linux is a multitasking operating system, often when executing a command, the system also handles other tasks. Another problem to be aware of is that even though the same command is executed every time, the time spent is not the same, and the time spent is related to the operation of the system.

Linux Common commands

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.