Linux Common Comment in practices

Source: Internet
Author: User

There are really a lot of commands in Linux, but we just need to master the commands we use the most. Of course you can also use to find the man, he will help you solve a lot of problems. However, everyone plays Linux differently, so the commands they use often vary greatly. 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. Such as:

cd /root/Docements # 切换到目录/root/Docements  cd ./path          # 切换到当前目录下的path目录中,“.”表示当前目录    cd ../path         
    1. ls command

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

-l :列出长数据串,包含文件的属性与权限数据等  -a :列出全部的文件,连同隐藏文件(开头为.的文件)一起列出来(常用)  -d :仅列出目录本身,而不是列出目录的文件数据  -h :将文件容量以较易读的方式(GB,kB等)列出来  -R :连同子目录的内容一起列出(递归列出),等于该目录下的所有文件都会显示出来  

Note: These parameters can also be used in combination, the following two examples:

ls -l #以长数据串的形式列出当前目录下的数据文件和目录  ls -lR #以长数据串的形式列出当前目录下的所有文件  
    1. grep command
      This command is often used to parse a row of information, if there is information we need, the row is displayed, the command is usually used with the pipeline command, for the output of some commands to filter processing, etc., its simple syntax is
      grep [-acinv] [--color=auto] ‘查找字符串‘ filename

Its common parameters are as follows:

-a :将binary文件以text文件的方式查找数据  -c :计算找到‘查找字符串’的次数  -i :忽略大小写的区别,即把大小写视为相同  -v :反向选择,即显示出没有‘查找字符串’内容的那一行  

For example:
Remove the line containing Manpath in 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 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:
find [PATH] [option] [action]

Time-related parameters

-mtime n : n为数字,意思为在n天之前的“一天内”被更改过的文件;  -mtime +n : 列出在n天之前(不含n天本身)被更改过的文件名;  -mtime -n : 列出在n天之内(含n天本身)被更改过的文件名;  -newer file : 列出比file还要新的文件名  

For example:
find /root -mtime 0 # 在当前目录下查找今天之内有改动的文件

Parameters related to user or user group name

-user name : 列出文件所有者为name的文件  -group name : 列出文件所属用户组为name的文件  -uid n : 列出文件所有者为用户ID为n的文件  -gid n : 列出文件所属用户组为用户组ID为n的文件  

For example:
find /home/charles -user charles #Find the file owner Ljianhui in the directory/home/ljianhui

parameters related to file permissions and names :

-name filename :找出文件名为filename的文件  -size [+-]SIZE :找出比SIZE还要大(+)或小(-)的文件  -tpye TYPE :查找文件的类型为TYPE的文件,TYPE的值主要有:一般文件(f)、设备文件(b、c)、               目录(d)、连接文件(l)、socket(s)、FIFO管道文件(p);  -perm mode :查找文件权限刚好等于mode的文件,mode用数字表示,如0755;  -perm -mode :查找文件权限必须要全部包括mode权限的文件,mode用数字表示  -perm +mode :查找文件权限包含任一mode的权限的文件,mode用数字表示  

For example:

find / -name passwd # 查找文件名为passwd的文件  find . -perm 0755 # 查找当前目录中文件权限的0755的文件  find . -size +12k # 查找当前目录中大于12KB的文件,注意c表示byte  

5. CP command

This command is used to copy the file, copy the meaning, it can also be a single copy of multiple files in a directory, its
Common parameters are as follows:

-a :将文件的特性一起复制  -p :连同文件的属性一起复制,而非使用默认方式,与-a相似,常用于备份  -i :若目标文件已经存在时,在覆盖时会先询问操作的进行  -r :递归持续复制,用于目录的复制行为  -u :目标文件与源文件有差异时才会复制  

For example:

cp -a file1 file2 #连同文件的所有特性把文件file1复制成文件file2  cp file1 file2 file3 dir #把文件file1、file2、file3复制到目录dir中
    1. MV Command

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

-f :force强制的意思,如果目标文件已经存在,不会询问而直接覆盖  -i :若目标文件已经存在,就会询问是否覆盖  -u :若目标文件已经存在,且比目标文件新,才会更新  

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 # 把文件file1、file2、file3移动到目录dir中  mv file1 file2 # 把文件file1重命名为file2  
    1. RM command

This command is used to delete files or directories, between remove, and its common parameters are as follows:

-f :就是force的意思,忽略不存在的文件,不会出现警告消息  -i :互动模式,在删除前会询问用户是否操作  -r :递归删除,最常用于目录删除,它是一个非常危险的参数  

For example:

rm -i file # 删除文件file,在删除之前会询问是否进行该操作  rm -fr dir # 强制删除目录dir中的所有文件

8. PS command

This command is used to select and output the process run at a point in time, and its common parameters are as follows:

-A :所有的进程均显示出来  -a :不与terminal有关的所有进程  -u :有效用户的相关进程  -x :一般与a参数一起使用,可列出较完整的信息  -l :较长,较详细地将PID的信息列出  

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 # 查看系统所有的进程数据  ps ax # 查看不与terminal有关的所有进程  ps -lA # 查看系统所有的进程数据  ps axjf # 查看连同一部分进程树状态  
    1. Kill command
      This command is used to send a signal to a job (%jobnumber) or to a PID (number), which is typically used with the PS and jobs commands, with the following basic syntax:

Kill-signal PID
The common parameters of signal are as follows:
Note: The first number is the signal code, use can be used to replace the corresponding signal code.

1:SIGHUP,启动被终止的进程  2:SIGINT,相当于输入ctrl+c,中断一个程序的进行  9:SIGKILL,强制中断一个进程的进行  15:SIGTERM,以正常的结束进程方式来终止进程  17:SIGSTOP,相当于输入ctrl+z,暂停一个进程的进行  

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
To re-modify the process ID of the PID process, PID can be obtained by using the PS command to filter by the command plus grep command
Kill-sighup PID

    1. Killall command
      This command is used to send a signal to a process initiated by a command whose general syntax is as follows:

killall [-iIe] [command name]
It has the following parameters:

-i :交互式的意思,若需要删除时,会询问用户  -e :表示后面接的command name要一致,但command name不能超过15个字符  -I :命令名称忽略大小写  

For example:
killall -SIGHUP syslogd# Restart SYSLOGD

    1. File command
      This command is used to determine the basic data of files after the file command, 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:

File filename
For example:
File./test

    1. Tar command

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

-c :新建打包文件  -t :查看打包文件的内容含有哪些文件名  -x :解打包或解压缩的功能,可以搭配-C(大写)指定解压的目录,注意-c,-t,-x不能同时出现在同一条命令中  -j :通过bzip2的支持进行压缩/解压缩  -z :通过gzip的支持进行压缩/解压缩  -v :在压缩/解压缩过程中,将正在处理的文件名显示出来  -f filename :filename为要处理的文件  -C dir :指定压缩/解压缩的目录dir  

The above commentary may have knocked you out of the way, but usually we just need to remember the following three commands:

压缩:tar -jcv -f filename.tar.bz2 要被处理的文件或目录名称  查询:tar -jtv -f filename.tar.bz2  解压:tar -jxv -f filename.tar.bz2 -C 欲解压缩的目录  

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

    1. Cat command
      This command is used to view the contents of a text file, followed by the name of the file to be viewed, and is typically used in conjunction with more and less to allow you to view the data one page at a time. For example:

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

    2. CHGRP command
      This command is used to change the user group to which the file belongs, it is very simple to use, its basic usage is as follows:

chgrp [-R] dirname/filename
-R: Recursive persistent 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
Chown command
The command is used to change the owner of the file, using the same method as the CHGRP command, except that the modified file attributes are different and are no longer detailed.

    1. chmod command
      This command is used to change the permissions of a file, as follows:
      chmod [-R] xyz 文件或目录
      -R:进行递归的持续更改,即连同子目录下的所有文件都会更改
      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 # 把file的文件权限改变为-rxwr-xr-x  
    1. 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, here no longer say. You can download a detailed description of VIM's common operations from here.

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

      -o:output, used to specify the file name to generate an executable file
      -C: Used to generate a target file (. o) from the source file and 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 search static connection library at compile time
      -S: Generate assembly code files for source files
      -LM: A library of libraries named LIBM.A in the directory that represents the standard library
      -lpthread: Connecting NPTL-Implemented lines libraries
      -std=: Used to specify the version of the C language to use

For example:
Compile the source file test.c into executable program test according to C99 standard
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 time 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 program or command has finished running, it outputs three times at the end, respectively:
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, the system CPU time that the command executes, that is, the command executes the sum of time in the kernel mentality;
Real: The actual time, from the command line to start execution to the end of the elapsed time;

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.

System Information
    1. Uname
      Usage:uname [OPTION] ...
      Print certain system information. With no OPTION, same as-s.

Linux Common Comment in practices

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.