Linux common commands (ii)

Source: Internet
Author: User

The Linux directory structure and common file processing commands are mainly introduced in the Linux common Commands (a) . Commonly used file processing commands include: CD, LS, PWD, mkdir, CP, MV, RM and other commands. In addition to the file processing commands described in the Linux common Commands (a) , there are some common commands.

1 Help commands1.1Mans

English: Manual command path:/usr/bin/man Execute permissions: All users

role: Get help for a command or configuration file

syntax: Man [command/config file]

Eg:man ls man services

(The absolute path of the configuration file is not required when viewing the configuration file, only the file name is required)

Call the more command to browse the Help document, press the space to turn the next page, press ENTER to turn the next line, press Q to exit.

use/Add key parameters to locate search directly, n Find Next, shift+n find previous

eg:/-l directly view-L introduction

extension: Man level (type of Help document, Understanding 1 5)

Man man-pages view the meaning of each type represents the type of the man document (1~9)

1 is the command, 5 is the profile man first display command, you can specify the Help type

Eg:man 5 passwd (5 for profile level)

    Man's Level:

1. Commands or executables that users can manipulate in a shell environment

2. Functions and tools that the system kernel can invoke

3. Some common functions and function libraries (library), most of which are C-language library functions (LIBC)

4. Description of the device file, usually a file in/dev

5. configuration files or the format of some files

6. Games (game)

7. Conventions and protocols, such as Linux file system, network protocol, ASCII code and other instructions

8. Administrative commands available to system administrators

9. Documents related to Kernel

1.2Help

help view the shell's built-in commands

eg:help CD

built-in commands that cannot be viewed with Whereis,which,man

type command to view internal or external commands

command name--help

command name--help lists common options for this command

EG:CP--help

2 File Search command2.1Find

Command path:/bin/find Execute permissions: All Users

function: Find a file or directory

syntax: Find [Search path] [match condition]

If no search path is specified, the default is to find from the current directory

Find command Options

-name Find exact search by name

eg:find/etc-name "Init" to find file init in directory/etc

-iname Search by name

Match the characters in the Find lookup:

*: Match all

? : Matches a single character

Eg:find/etc-name "Init???" In the directory/etc, look for files that begin with Init and have three bits behind them

for fuzzy matching conditions, it is recommended to enclose them in single or double quotation marks. If * is escaped, use single double quotes to enclose the query condition, or use \*.

eg: # find –name *g

-size Search by file size

in block, a block is 512B, 1k=2block + greater than-less than write is equal to

eg:find/etc-size-204800 in the ETC directory to find files larger than 100MB

100mb=102400kb=204800block

-type Find by file type

F binary file L Soft connect file d directory C character file

Eg:find/dev-type C

The basic principles of Find lookup :

Minimal system resources, which is the smallest query range and the most accurate query conditions

eg: if you know exactly which directory the file is located in, you can find it directly on the specified directory, without looking for the root directory/

2.2grep command

Command path:/bin/grep Execute permissions: All Users

Function: Searches the file for string matching lines and outputs

  syntax: grep [-CINV] ' search string ' filename

Options and Parameters:

    - C: Output matches the number of rows (in the unit of behavior, not in occurrences)

-I: case is ignored, so case is considered the same

- N: Display matching lines and line numbers

- V: Invert selection to display all lines that do not contain matching text.

Eg:grep ftp/etc/services

eg: #grep-v ^#/etc/inittab Remove the # from the beginning of the file

eg:# grep-n "Init"/etc/inittab displayed in Inittab file, init matches line and line number

eg:# grep-c "Init"/etc/inittab displayed in the Inittab file, how many times did init match

2.3which

command path:/usr/bin/which Execute permissions: All users

function: Displays the directory where the system command is located (absolute path and alias)

The purpose of the which command is to search for the location of a system command in the path specified by the path variable, and return the first search result. That is, using the which command, you can see whether a system command exists, and which command is executed at which location.

# which LS

alias ls= ' ls--color=auto '

/bin/ls

# which ZS

/usr/bin/which:no Zs in (/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/ch/bin)

2.4Whereis

Command path:/usr/bin/whereis Execute permissions: All Users

Function: Search the directory where the command is located and the Help document path

Eg:which passwd and Whereis passwd

eg: Check the/etc/passwd configuration file for help with man 5 passwd

3 Compression Decompression Command3.1Gzip

English: GNU zip command path:/bin/gzip Execute permissions: All users

function: Compress (unzip) file, zip file suffix to. gz

gzip can only compress files, cannot compress directories, do not keep original files

Syntax: gzip files

-D Unzip the compressed file (decompress)  

unzip using gzip–d or Gunzip

3.2Bzip2

command path:/USR/BIN/BZIP2 Execute permissions: All users

function: compress (extract) file, zip file suffix to. bz2

syntax: bzip2 [-K] [file]

-K: Retain the original file (compression ratio) after generating the compressed file

- D Decompression parameters (decompress)

unzip using bzip2–d or BUNZIP2

3.3Zip

Command path:/usr/bin/zip Execute permissions: All Users

function: compress (unzip) file, zip file suffix

Syntax: Zip option [-r] [file name after compression] [file or directory]

- r Compression Directory

eg:zip services.zip/etc/services compressed files;

zip-r test.zip/test Compression directory

If you do not add the-r option, the compressed file has no data.

decompression using unzip

3.4Tar

command path:/bin/tar Execute permissions: All users

Role: File, directory Dozen (solution) package

syntax: tar [-ZCF] Compressed file name file or directory

- c Create a parameter directive (create) for a compressed file, with a suffix of. Tar

-X unlocks a compressed file parameter directive (extract)

- Z Compressed/uncompressed with gzip command

-j Compression/decompression with bzip2 command

- v compression in the process of displaying files (verbose)

-F file Specifies file name, required option

1, separate package, unpacking TAR–CF tar–xf

2, after packaging, compress gzip bzip2

3, one step TAR–ZCVF tar-zxvf

tar-cf-xf individual Compression decompression

Tar-z Package the directory with gzip and compress the file format. tar.gz (. tgz)

Tar-j Package The directory with bzip2 and compress the file format. tar.bz2

EG:TAR-ZCVF dir1.tar.gz dir1 use gzip to compress directory Dir1 into one package and compress files dir1.tar.gz

TAR-ZXVF dir1.tar.gz-c (uppercase)/root extract to the specified/root directory

EG:TAR-CVF Bak.tar. Package the files of the current directory as Bak.tar

EG:TAR-XVF Bak.tar Decompression

EG:TAR-ZCVF bak.tar.gz Bak.tar or gzip Bak.tar use gzip to compress packaged files Bak.tar to bak.tar.gz

EG:TAR-JCVF bak.tar.bz2 Bak.tar or bzip2 Bak.tar use bzip2 to compress packaged files Bak.tar to bak.tar.bz2

eg:tar-rvf bak.tar/etc/password/etc/password append file to Bak.tar (r)

EG:TAR-CJVF test.tar.bz2 test generates TEST.TAR.BZ2 compressed files

EG:TAR-XJF test.tar.bz2 Decompression

most commonly used: Tar + gzip

TAR–ZCVF Compression

TAR–ZXVF Decompression

Add:

1, file path, compressed package with file path

2, the source file is reserved and will not be deleted

4 System shutdown Command

shutdown [Options] Time

option:-C: Cancels the previous shutdown command

- h: Shutdown

- R: restart

eg:

shutdown-h now shutdown shutdown-h 20:30 timed shutdown

other shutdown commands halt poweroff init 0

Other Restart commands

reboot Restart system reboot-h now restart

Init 6

Note: In a production environment, shutdown commands and restart commands are performed with caution.

Linux common commands (ii)

Related Article

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.