Linux command logging

Source: Internet
Author: User
Tags create directory file copy grep regular expression parent directory

Disk Management Command LS command: Train directory contents

-A or-all will list all files and directories, note hidden files, special directories

-l Query verbose format list

-t sort by the change time of the file or directory

-R Reverse Sort

Ls-l shorthand for ll

Ll-h Friendly Show

D: Directory,-normal file, L link

Requirements: Show content in a directory

Location:/root

Want to see the contents of the/etc directory

Command: ll-h/etc

CD Switch Directory

Cd.. /, up one level

cd/directory name, any directory switch to the specified directory

CD ~, Current user Directory

CD/, root directory

CD-, Last Directory

Cd.. , Top level Directory

Absolute path: cd/etc/x1 first switch to/directory (root directory), then to/directory to find subdirectories etc, in etc in the sub-directory x1, in any directory can be arbitrary switch.

Relative path: CD x1/x2 in the current directory looking for subdirectories x1, looking for subdirectories x2 in X1. You must determine the directory X1 in the current directory.

PWD (Print work directory): Show working directory mkdir command: Create directory

mkdir the folder name to create the directory t1.

1, create directory T1

Command: mkdir t1

2, create the T2 in the/ROOT/T1 directory:

Command: Relative path: mkdir t1/t2 absolute path: mkdir/root/t1/t2

3, you need to create T4 under/root/t3, but neither T3 nor T4 exist.

-P Parent Directory does not exist in the case of Mr. Cheng parent Directory

Command: Mkdir-p t3/t4

4,-V displays detailed information during the execution of the command.

Command: MKDIR-PV t3/t4

rmdir command: Delete empty directory

File Browse command

Browse: Log files, xml,properties file

Cat file Name: Quick view of current file contents

Cat is suitable for viewing a small amount of information files and cannot view large files

More Features: page display of the contents of the file, but also support direct jump

Syntax: more file

Action: Enter down n rows,

SPACEBAR: Scroll down one screen or ctrl+f.

B: Return to the previous layer or ctr+b

Q: Quit more.

LESS-MN File Name: page displays the contents of the files, labels each line number, operation more detailed

Syntax: less [parameter] file

-m shows a percentage similar to the more command

-N Displays line numbers per line.

Action: Enter down n rows,

SPACEBAR: Scroll down one screen or ctrl+f.

B: Return to the previous layer or ctr+b

Q: Quit more.

Suitable for viewing large numbers of files.

Tail-Digital file name: Quick View Files Available after X lineThe content.

For example: taill-10 file name. View the following 10 lines of the file.

File Operations Command File copy: (copy)---CP: Copy files or copy directories. To copy a file:

The location where the CP needs to copy the files that need to be copied

Requirements: Copy the/root/demo1.java to the/ROOT/T1 directory

Location:/root

Command: CP Demo1.java T1 (relative path)

CP/ROOT/DEMO1.JAVA/ROOT/T1 (absolute path)

Requirements: Copy the/root/demo1.java to the/ROOT/T1 directory, renamed: Ddd.java

Location:/root

Command: CP Demo1.java T1/ddd.java (relative path)

Cp/root/demo1.java/root/t1/ddd.java (absolute path)

To copy a directory:

Cp-r where the copied files are to be copied to

-R or-recursive recursive processing, the files under the specified directory and subdirectories are processed together.

Requirements: Copy the/ROOT/T5 directory to the/ROOT/T3

Location:/root

Command: Cp-r T5 T3

Cp-r/ROOT/T5/ROOT/T3

MV Command: Move or rename an existing file or directory

File/directory Move:

Where the MV needs to move the moved files

Parameters:-F or Force if the destination file or directory is duplicated with an existing file or directory, overwrite the existing file or directory

Requirement: Move the/ROOT/T5 to the/ROOT/T3

Location:/root

Command: MV T5 T3

Requirements: Move/root/t5 to/ROOT/T3 under the/ROOT/T3 there is already a T5 directory, in the mobile fit, do not ask, direct coverage

Location:/root

Command: MV- F T5 T3

File/directory rename operation:

Requirement: Renaming/root/demo1.java to: Hehe.java

Location:/root

MV Demo.java Hehe.java (equivalent to moving the file to the current directory and renaming Hehe.java)

File Delete: RM (remove) Feature: Delete files or directories

To delete a file:

RM file name (relative path or absolute path)

Parameter:-F or-force Force Delete file or directory

-R or-R or-recursive recursive processing, delete all files and subdirectories in the specified directory .

Command: Rm-f Demo.java

To delete a directory:

RM-RF Directory Name

Requirement: Delete/root/t5 directory

Location:/root

Known: The T5 directory has subdirectories or files

Command: RM-RF T5.

Attention:

rm-rf* Delete all content in the current directory

rm-rf/* Delete all content from the root of the Linux system ( cannot be executed casually ).

File lookup: Find command

Find features: Finding files or directories

Syntax: Find directory name-name ' string to look for '

-NAME specifies a string as a template style for finding a file or directory.

* Represents 0 or more arbitrary characters

Instance:

Requirements: Find all files or directories in the/root directory that begin with test

Command: find/root/-name ' test* '

Text editing commands

Notepad features:

VIM: Command

    • Enter "Vim file name" into general mode
    • Press "I" to enter insert mode from general mode
    • Sequence "ESC" exits from insert mode to normal mode
    • In general mode, enter "Wq" to exit the edit

General mode: Can be used to browse the contents of the file, can be used for text shortcuts, single copy, multi-line replication, one-line deletion, multi-line deletion.

Insert mode: Can edit text content,

Bottom-line mode:

The exit operation ( not saved ) can be q!,

You can save and exit the operation Wq.

grep and piping

Pipeline command: Available links to multiple Linux commands: | (Shift \)

The grep regular expression string searches for work, conforms to the rules, and returns rows that conform to the rule.

Parameter:-I (ignore) ignores case: Grep-i class Demo1.java.

Format: grep needs to search for a string of files to be searched

For example, the following command:grep class Demo1.java, searching for class from the Demo1.java file,

Returns the line containing the class.

Requirement: Queries the current directory for all row data with the INS keyword.

Location:/root

Thinking: Querying the contents of the current directory:ll

Query string that returns the string where the row grep

Command: LL | grep ins

Indicates: From the result of the LL command, query ' ins ' to return the row.

Compress, unzip the command "important"

Linux compression, decompression commands.

Linux Compressed package: *.tar Packaging, size is not compressed.

*.TAR.GZ package and compress the size of the file.

Parameters:

-C Create a parameter directive for a compressed file: (create)-compression

-X unlocks a compressed file parameter directive (extract)-Unzip

-Z is compressed with gzip

-V file display during compression (verbose)

-F Use file name, immediately after F to receive the file name (file)

Common decompression parameter combination: ZXVF

Common compression parameter combination: ZCVF

Compression command (parameter order cannot be changed):

TAR-ZCVF compressed package name. tar.gz What needs to be compressed

For example: TAR-ZCVF hehe.tar.gz *: Package The contents of the current directory compressed, file name hehe.tar.gz.

Decompression command (parameter order cannot be changed):

TAR-ZXVF the name of the compressed package to extract (unzip to the current directory)

  TAR-ZXVF need to unzip the name of the compressed package-c Specifies the compressed path (extracted into the specified directory)

Example: TAR-ZXVF hehe.tar.gz (unzip the current directory)

Requirements: The/root/t5/hehe.tar.gz compressed package needs to be extracted to the specified directory. Specify directory:/ROOT/T5/T5

Location:/ROOT/T5

Command: TAR-ZXVF hehe.tar.gz-c/root/t5/t5 (or relative path: T5)

System commands: Viewing system processes: PS (process status)

Parameters:-E The effect of this parameter is the same as specifying the "A" parameter, showing all programs

-F Display uid,ppip,c and Stime fields

UID: The process belongs to which user opened the

PID: Process ID. Used to kill the process

CMD: Indicates the program that the process corresponds to, or the location of the program.

Requirements: View processes, and vim-related processes

Command: PS-EF | Grep-i vim

Kill process: Kill

Force kill a process: kill-9 PID number

Requirements: Review the process, what the VIM-related processes are, and kill the vim process.

Command: PS-EF | Grep-i vim

Kill-9 24554

ifconfig command: Show Network device ping: test and target connectivity

The ping continues to be tested until CTRL + C.

Rebot: Restart command halt: Shut down now

Other commands

Network setup: Setup

We recommend using CRT to run the command, there will be Chinese interface

Linux command logging

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.