Linux20 a common command __linux

Source: Internet
Author: User
Tags bz2 chmod file permissions

People who have played Linux will know that there are many commands in Linux, but people who have played Linux never bother because Linux commands are so much, because we only need to master the commands we use most often. Of course, you can also use to find a man, he will help you solve a lot of problems. However, everyone is playing Linux for different purposes, so they often use the command is very big difference, and I mainly use Linux for C/s + + and Shell program written, so the command can be used to be different from a person who manages the Linux system. Because do not want to use is always East search west, so in this summary, to facilitate the future view. Not much, let's talk about my most popular Linux commands.



1. CD command

This is a very basic, but also often need to use the command, it is used to switch the current directory, its parameters are to switch to the directory path, can be absolute path, can also be a relative path. Such as:

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 of a directory


2, ls command

This is a very useful view of the file and directory of the command, the list of meaning, it has a lot of parameters, the following list some of my commonly used parameters, as follows:

-L: Lists Long data strings containing file attributes and permission data-a
: Lists all of the files, together with the hidden file (the file at the beginning of.)-
D: Lists only the directory itself, not the file data for the directory-
H : The file capacity is listed in a more readable manner (GB,KB, etc.)-
R: Listed (recursively listed) along with the contents of the subdirectory, equal to all the files in the directory will be displayed

Note: These parameters can also be used in combination, and here are two examples:

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


3. grep command

This command is often used to parse a line of information, if it has the information we need, to display the line, which is usually used with the pipe command, to filter the output of some commands, and so on, its simple syntax is

grep [-ACINV] [--color=auto] ' Find string ' filename

Its common parameters are as follows:

-A: To find the binary file as a text file-
c: Calculate the number of times to find the ' find string '----I
: Ignore case difference, that is, the case is the same as-
V: Reverse selection, that is, show no ' find string ' content of the line
# For example:
# Remove the Manpath line from the file/etc/man.config and add color to the Found keyword
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 command based on lookup, which is relatively complex and has a lot of parameters, so here's a list of them, and its basic syntax is as follows:

Find [PATH] [option] [action]

# Parameters related to time:
-mtime n:n is a number, meaning a file that has been changed in "One Day" before n days;
-mtime +n: Lists the file names that were changed before n days (excluding n days themselves);
-mtime-n: Lists file names that have been changed within n days (including n days themselves);
-newer file: Lists file names that are newer than file
# For example: Find
/ Root-mtime 0 # Find changed files in current directory

# parameters related to user or user group name:
-user Name: List file with file owner name
-group Name: List file owning user group is name File
-uid N: Lists files where the owner of the file is a user ID n-gid N: List files to which the user group is a user
group ID N for
example:
find/home/ljianhui-user Ljianhui # in the directory/home/ljianhui find the owner-Ljianhui file

# Parameters related to file permissions and names:
-name filename: Find the file named filename
- Size [+-]size: Find a file that is larger (+) or smaller (-) than size]
-tpye type: A file that finds the type of a file, the value of type is mainly: General file (f), device file (b, c),
             Table of contents (d), Connection file (l), socket (s), FIFO pipe file (p);
-perm mode: Find files that have permissions just equal to mode, mode is represented by numbers, such as 0755
-perm-mode : The Find file permissions must all include the mode permission file, mode is represented by a number
-perm +mode: A file that finds file permissions that contain the permissions of either mode, mode is represented by numbers
# for example: Find
/-name passwd # Find a file with a file name of passwd found
.-perm 0755 # Find.-size +12k # finds files in the current directory that are more
than 12KB, note that C indicates byte

5, CP command

This command is used to copy files, copy, and it can copy multiple files to a directory at once, and its common parameters are as follows:

-A: Copying the attributes of a file, together with the
attributes of a file, instead of using the default method, similar to-a, is commonly used for backup-I
: If the target file already exists, it will ask for the action when it is overwritten-
R: Recursive continuous Replication for directory replication behavior
-u: The destination file is copied when it differs from the source file

For example:

Cp-a file1 file2 #连同文件的所有特性把文件file1复制成文件file2
cp file1 file2 file3 dir #把文件file1, File2, file3 replicate to directory dir


6, MV Command

This command is used to move a file, directory, or name change, and its common parameters are as follows:

-f:force the meaning of coercion, if the target file already exists, will not be queried and directly overwrite-
I: If the target file already exists, you will be asked whether to overwrite-
u: If the target file already exists and is newer than the target file, it will be updated

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:

MV File1 file2 file3 dir # moves files file1, file2, file3 to directory dir
mv file1 file2 # Rename file file1 to File2


7. RM command

This command is used to delete files or directories, and the common parameters of the Remove are as follows:

-F: That's what force means, ignoring files that don't exist, no warning messages.-I
: interactive mode, before the deletion will ask the user whether to operate-
R: Recursive deletion, most commonly used in directory deletion, it is a very dangerous parameter


For example:

Rm-i file # Deletes files and asks for the action 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 running at a point in time, and its common parameters are as follows:

-A: All processes are displayed.-A
: All processes not related to terminal-
u: Related processes for valid users-
x: Typically used with A parameter to list more complete information-
L: Long, more detailed list of PID information

In fact, we just remember that PS commonly used in the command parameters to match, 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 along with part of the process tree state


9. Kill command

This command is used to send a signal to a work (%jobnumber) or to a PID (number), which is usually used in conjunction with the PS and Jobs commands, and its basic syntax is as follows:

Kill-signal PID

The common parameters of signal are as follows:

Note: The first number is the signal code, the use of the code can be used to replace the corresponding signal.

1:sighup, start the terminated process
2:sigint, equivalent to input CTRL + C, interrupt the 9:sigkill of a program
, force the interruption of a process
15:sigterm, terminate the process in the normal way to end the process
17:sigstop, equivalent to input ctrl+z, suspend a process

For example:

# in 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-change process ID PID process, PID can be filtered using the PS command via pipeline command plus grep command to obtain
kill-sighup PID


10, Killall command

The command is used to send a signal to a process that is started by a command, and its general syntax is as follows:

Killall [-iie] [command name]


Its parameters are as follows:

-I: interactive meaning, if you need to delete, ask the user-
e: Indicates that the command name to be followed is consistent, but command names can not exceed 15 characters-I
: the command title ignores case
# for example:
killall -sighup syslogd # reboot SYSLOGD


11. File command

This command is used to determine the basic data for files that are connected to the file command, because the type of file under Linux is not a suffix later, so this command is useful for us, its usage is very simple, the basic syntax is as follows:

File filename
#例如:
file./test


12. Tar command

This command is used to package files, the default is not compressed, and if the appropriate parameters are specified, it also invokes the corresponding compression program (such as Gzip and bzip, etc.) for compression and reconciliation. Its common parameters are as follows:

-C: New package file
-T: View the contents of the packaged file contains which filename-
x: Unpack or decompress, you can specify the extracted directory with-C (uppercase), note that-c,-t,-x cannot appear in the same command simultaneously
-J : Compression/Decompression via BZIP2 support-
Z: Compression/decompression via gzip-
V: In the compression/decompression process, the file name being processed is displayed------
F Filename:filename -
C dir: Specifies the compressed/uncompressed directory Dir


The above explanation can already make you faint, but usually we just need to remember the following three commands:

Compression: Tar-jcv-f filename.tar.bz2 to be processed file or directory name
query: tar-jtv-f filename.tar.bz2
decompression: Tar-jxv-f to solve Compressed Table of Contents

Note: The filename is not set to end with the suffix tar.bz2, this is mainly to illustrate the use of the compression program for BZIP2



13, Cat command

This command is used to view the contents of a text file, followed by the name of the file you want to view, and is usually used in conjunction with more and less, allowing you to view the data page by page. For example:

Cat text | Less # View the contents of the text file
# Note: This command can also use less text instead


14, Chgrp command

This command is used to change the group of users to which the file belongs, and its use is simple, and its basic usage is as follows:

CHGRP [-R] Dirname/filename-
R: Persistent and recursive changes to all files and subdirectories
# 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, the same way as the CHGRP command, except that the modified file attributes are different and are no longer detailed.



16, chmod command

This command is used to change the permissions of a file, generally as follows:

chmod [-r] XYZ file or directory-
R: Persistent, recursive changes, that is, all files under the subdirectory will change

At the same time, chmod can make changes to the permissions of a file using U (user), G (group), O (Other), a (all), and + (join),-(delete), = (set) with rwx.

# For example:
chmod 0755 File # to change filename permissions to-rxwr-xr-x
chmod g+w File # To add user group writable permissions to files permissions


18, Vim command

This command is used primarily for text editing, with one or more file names as arguments, and if the file exists, create a file with that file name if it does not exist. Vim is a very useful text editor, it has a lot of very useful commands, there is no more to say here. You can download the detailed instructions for VIM's common operations here.



19. GCC command

For a person using Linux to develop C programs, this command is very important, it is used to the C language source program files, compiled into an executable program, because many of the parameters of g++ is very similar to it, so here only the parameters of GCC, its common parameters are as follows:

-o:output, used to specify the filename to generate an executable file-
c: Used to generate the source file (. o) and prevent the compiler from creating a complete program-I
: increase the path to the compile-time search header file-
l : Increase the path of the compile-time search static connection library-
s: Generate the source file assembly code file
-LM: Represents a library of libraries in the directory named LIBM.A function libraries
-lpthread: Connection NPTL Implementation of the line threading
-std= : Used to specify the version of the C language used

# for example:
# to compile the source file test.c according to the C99 standard to executable program test
gcc-o Test test.c-lm-std=c99
# Convert the source file test.c to the corresponding assembler source file Test.s
gcc-s test.c


20. Time command

This command is used to measure the execution time of a command (that is, a program). It's very simple to use, just like the input command, but add a time before the command, for example:

Time./process time
PS aux

After the program or command is run, the final output is three time, respectively:

User: CPU time, the user CPU time for the execution of the command, that is, the total execution time of the command in the user state;

System: CPU time, command execution to complete the cost of the system CPU time, that is, the command in the nuclear mentality of the total execution time;

Real: Actual time, from the command line to start execution to the end of the elapsed time;



Note: The sum of the user's CPU time and system CPU time is CPU time, that is, the total time that the command consumes CPU execution. The actual time is greater than the CPU time, because Linux is a multitasking operating system, and often the system handles other tasks while executing a command. Another issue to note is that even though the same command is executed each time, the time spent is different, and the time spent is related to system operation.

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.