Linux Common commands

Source: Internet
Author: User
Tags bz2 file permissions rsync

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. Such as:
/root/docements # Switch to directory /root/docements  CD. / Path          # switches to the path directory under the current directory, "." Represents the current directory    CD : /Path         # switch to the path directory in the upper directory, "..." Represents a previous level of 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 usual parameters, as follows:
- L: Lists Long data strings, including file attributes and permission data, etc.   - A: List all the files, together with the hidden files (files that begin with.) (common)   - D: List only the directory itself, not the file data  that lists the directory - h: List  The file capacity in a more readable manner (GB,KB, etc.) - R: Listed along with the contents of the subdirectory (recursively listed), equal to all files in that directory are displayed  

- l #以长数据串的形式列出当前目录下的数据文件和目录   -LR #以长数据串的形式列出当前目录下的所有文件  

3, grep command This command is often used to analyze a row of information, if there is information we need, the line is displayed, the command is usually used with the pipeline command, for the output of some commands to filter processing, etc., its simple syntax for
[-acinv] [--color=auto] ' Find String ' filename  

Its common parameters are as follows:
- A: Find data  in a binary file as a text file - C: Count the number  of ' find string ' found - I: Ignoring case differences, that is, case is considered the same   - V: Reverse selection, which shows the line without the ' Find string ' content  # for example:  # Take out Files /etc/  Man.config contains MANPATH lines and adds color  to the keywords found - -color=auto ' MANPATH '/etc/man.config   -The output of L contains the letter file (case-insensitive) content output   -| - 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, its basic syntax is as follows:
1Find[PATH] [option] [Action]  2   3 # time-related parameters:4 -mtime N: = n is a number, meaning a file that has been changed in "One Day" before the nth day;5 -Mtime+N: Lists the file names that were changed before n days (excluding the N-day itself);6 -Mtime-N: Lists filenames that have been changed within n days (including n days themselves);7 -Newerfile: List file names that are newer than file8 # for example:9Find/Root-Mtime0# Find files in the current directory that have changed within todayTen    One # Parameters related to user or user group name: A -UserName: Lists files with the file owner as name - -GroupName: List files that belong to the user group named name - -uid N: List file owner as User ID n the -gid N: Lists files that belong to the user group whose user group ID is n - # for example: -Find/Home/Ljianhui-UserLjianhui # in the Catalog/Home/Find the file owner is Ljianhui in Ljianhui -    + # Parameters related to file permissions and names: - -name filename: Find the file named filename + -Size[+-]Size: Find larger than size (+) or small (-) file A -Tpye Type: Find file of type of file, the value of type is mainly: General file (f), device file (b, c), at directory (d), connection file (L), socket (s), FIFO pipeline file (p); - -Permmode: Find file permissions just equal to the mode file, mode is represented by numbers, 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 that contains the permissions of either mode, mode is represented by a number - # for example: -Find/ -name passwd # Find files with file name passwd inFind.-Perm 0755# 0755 files to find file permissions in the current directory -Find.-Size+12k # Find files larger than 12KB in the current directory, note that C means byte

5, CP Command This command is used to copy files, copy of the meaning, it can also be a single copy of multiple files to a directory, its common parameters are as follows:
1 - A: Copy  the attributes of the file together 2 -P: copied along with the attributes of the file, not by default, similar to -A, commonly used for  backup 3-I: If the target file already exists,  The action is queried first when overwriting 4-R: Recursive continuous replication, replication behavior  for the directory 5-u : The destination file does not replicate when it differs from the source file  

For example:
1 - a file1 file2 #连同文件的所有特性把文件file1复制成文件file2   2 cp file1 file2 file3 dir #把文件file1, file2, file3 copy to directory dir  

6. MV Command This command is used to move files, directories, or rename, move the meaning, its common parameters are as follows:
- F:force Mandatory Meaning, if the target file already exists, will not ask and directly  overwrite - I: If the target file already exists, you will be asked  to overwrite -u: Update if the target file already exists and is newer than the target file  

Note: This command can move a file or multiple files one folder at a time, but the last target file must be "directory". For example: 1 mv file1 file2 file3 dir # move the file file1, File2, file3 to the directory dir 2 mv file1 file2 # Rename the file file1 to File27, RM command This command is used to delete files or directories, between remove, its common parameters are as follows:
-F: Force means, ignoring nonexistent files, no 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  

  

For example:
Rm-i File # To delete files, ask if you want to do this before deleting  rm-fr dir # forces all files in directory dir to be deleted  

  

8. PS Command This command is used to select and output the process operation at a certain point in time, and its common parameters are as follows:
-A: All processes are displayed as-  A: All processes not related to terminal-  u: Related processes for active users-  x: Typically used with A parameter to list more complete information-  L: Longer, more detailed list of PID information  

In fact, we just need to remember the general use of PS command parameter collocation can be, they are not many, as follows:

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 part of the process tree status  

  

9. Kill command This command is used to transmit a signal to a job (%jobnumber) or to a PID (number), which is usually used with the PS and jobs commands, with the following basic syntax:
Kill-signal PID  

  

The commonly used parameters of signal are as follows: Note: The first number is the signal code, the use of the code can be replaced by the corresponding signal.
1:sighup, start the terminated process  2:sigint, equivalent to input CTRL + C, interrupt the 9:sigkill of a program  , force a process to break the  15:sigterm, the normal end process to terminate the process  17:sigstop, which is equivalent to input CTRL + Z, pauses a process  

  

For example:
# at the end of the normal 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-change process ID PID process, PID can be filtered with the PS command via the pipe command plus grep command to get  kill-sighup pid  

  

10, killall Command This command is used to send a signal to a command-initiated process, and its general syntax is as follows:
Killall [-iie] [command name]  

  

It has the following parameters:
-I: interactive meaning, if need to delete, will ask the user-  e: To indicate that the command name is consistent, but command name cannot exceed 15 characters-i  : command name ignores case  # for example:  killall -sighup syslogd # reboot SYSLOGD  

  

11. The file command is used to determine the basic data of files that are connected to the document after the file command, because the type of the files under Linux is not a suffix, so this command is very useful for us, it is very simple to use, the basic syntax is as follows:
File filename  #例如:  file./test  

  

12. 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:
-C: New packaging file  -T: View the contents of the packaged file contains which file name-  x: Unpack or unzip the function, you can specify the extracted directory with-C (uppercase), note that-c,-t,-x cannot appear in the same command at the same time  -j : Compression/Decompression via bzip2-  z: Compression/decompression with GZIP support-  V: During the compression/decompression process, the file name being processed is displayed  as-f filename:filename for the files to be processed  -C dir: Specify a directory for compression/decompression dir  

  

The above commentary may have knocked you out of the way, but usually we just need to remember the following three commands:
- - F filename.tar.bz2 The name  of the file or directory to be processed - - F filename.tar.bz2   - - - C directories to extract  

Note: The file name is not determined to end the suffix tar.bz2, here is mainly to illustrate the use of the compression program for BZIP2 13, the 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, so that you can view the data page. For example:
Cat text | Less # view content in text file  # Note: This command can also use less text instead of  

  

14, chgrp Command This command to change the file belongs to the user group, its use is very simple, its basic usage is as follows:
CHGRP [-R] Dirname/filename  -r: Persistent changes to all files and subdirectories for recursion  # for example:  chgrp users-r./dir # Recursively modify the user group for all files and subdirectories under the Dir directory to users  

  

15, 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 to change the permissions of the file, the general usage is as follows:
chmod [-r] XYZ file or directory  

  

At the same time, chmod can also use the U (user), G (group), O (Other), a (all) and + (join),-(delete), = (set) with the rwx to make changes to the permissions of the file.
# For example:  chmod 0755 File # To change files permissions to-rxwr-xr-x  chmod g+w File # To 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 and 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, here no longer say. 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 the C language source program files, compiled into 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:
-o:output, used 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 the path of the compile-time search for a static connection library-  s: Generate the source file assembly code file  -LM: A library named LIBM.A in the catalog that represents the standard library  -lpthread: line libraries-std= to connect NPTL implementation  : Used to specify the version of the C language to    be used # for example:  # to compile the source file test.c according to C99 standard into executable program test  gcc-o Test test.c-lm-std=c99  # Convert the source file test.c to the appropriate assembler source file Test.s  gcc-s test.c  

  

20. Time command This command is used to measure the execution times of a command (that is, a program). It's very simple to use, just like you would normally enter a command, but add a time to the front of the command, for example:
Time./process time  PS aux  

  

After the execution of the program or command, at the last three time, they 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: CPU time, System CPU time of the command execution, That is, the execution time sum of the command in the nuclear mentality; Real: The actual time, from the command line start execution to the elapsed time of the end of the run; note: The sum of CPU time and system CPU time is CPU time, that is, the total amount of time 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. Character substitution in 21.vim:%s/vivian/sky/g (equivalent to: g/vivian/s//sky/g) replaces all the Vivian in each row for a string in sky 22.vim look for:/target character output of rsync option src de St Rsync-avz/home/map/hadoop/hadoop-2.7.3/etc/hadoop [email protected]_dcloud08.docker.iwm.name:/home/map/hadoop/ Hadoop-2.7.3/etc

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.