Linux Learning: Linux basic Command Set (2)

Source: Internet
Author: User

This record reads the following commands such as mkdir, rmdir, tree, Dirname,basename, Cat, TAC, more, less, tail, head, touch, file, CP, MV, RM, WC, cut, sort, u Niq use formats, common options, and what they have to use.

    • Directory Management Related commands

1. mkdir Create new Directory command

Create new Directory command format: mkdir [OPTION] ... /path/to/somewhere

OPTION:

-p Recursive Create destination directory contains upper directory

[email protected] ~]# mkdir-p/test/test1

-V Show creation process

[email protected] ~]# MKDIR-PV/LAB/LAB1

mkdir:created directory '/lab '

mkdir:created directory '/LAB/LAB1 '

2. rmdir Delete Directory command

The directory needs to be deleted one layer at a time, and there must be no other directories or files in the deleted directory, that is, the specified directory must be empty.

Delete Directory command format: rmdir [OPTION] ... /path/to/somewhere

OPTION:

-P Recursive Delete destination directory contains upper directory

[Email protected] ~]# rmdir-p/test/test1

3. Tree- like directory display command

Displays the directory structure in a tree-shaped manner.

Tree-like display command format: Tree [OPTION] ... [DIR]

OPTION:

-D Displays the current directory name instead of the content

[Email protected] ~]# tree-d

.

'--Desktop

1 directory

-L level Displays the first few levels of directory names and files

[Email protected] var]# Tree–l 1

.

|--Account

|--Cache

|--crash

|--CVS

|--DB

|--Empty

|--Games

|--GDM

|--Lib

|--Local

|--Lock

|--Log

|--Mail-Spool/mail

|--NIS

|--opt

|--Preserve

|--Racoon

|--Run

|--Spool

|--tmp

'--YP

Directories, 0 files

4. dirname intercept a directory Part command for a given path

Removes the file name (not the directory part) from the given file name that contains the absolute path, and then returns the remaining path (the directory part).

Intercepts the directory portion of a given path command format: DirName FILENAME

[email protected] ~]# Dirname/etc/fstab

/etc

5. basename The basic name command for displaying a directory or file

The directory and suffix used to remove the file name.

Basic name for displaying a directory or File command format: basename FILENAME

[Email protected] ~]# Basename/etc/fstab

Fstab

    • Text File View related commands

6. cat is viewing the file Contents command

This command can only view files with the contents of the file as plain text.

Forward View file Content command format: Cat [OPTION] ... [FILE] ... OPTION:

-N Displays line numbers, along with blank lines

[Email protected] ~]# cat–n/etc/issue

1 CentOS Release 6.6 (Final)

2 Kernel \ r on an \m

3

-B Displays line numbers, only for non-blank lines

[Email protected] ~]# cat–b/etc/issue

1 CentOS Release 6.6 (Final)

2 Kernel \ r on an \m

-A lists all content (including special characters) such as the break character $, ^i, etc.

[Email protected] ~]# cat–a/etc/issue

CentOS Release 6.6 (Final) $

Kernel \ r on an \m$

$

7. TAC reverse View file Contents command

This command can also only view files with normal text content.

[Email protected] ~]# tac/etc/issue

Kernel \ r on an \m

CentOS Release 6.6 (Final)

8. More Flip screen view command

This command turns to the tail and cannot be flipped forward.

Flip screen to view command format: More [OPTION] ... [FILE] ...

OPTION:

-D Display page with action tip information

[Email protected] ~]# more-d/etc/man.config

Manpath/usr/man

Manpath/usr/share/man

Manpath/usr/local/man

Manpath/usr/local/share/man

--more--(32%) [Press space to continue, ' Q ' to quit.]

Common keys:

SPACEBAR: Represents a PAGE Down

Enter: represents scrolling down one line

B: The representative page back

Q: The delegate immediately leaves more

9. Less Flip screen view command

Flip screen to view command format: Less [OPTION] ... [FILE] ...

OPTION:

-e When the file display is finished, automatically leave

-m shows a percentage similar to the more command

[Email protected] ~]# less-m/etc/man.config

Manpath/usr/man

Manpath/usr/share/man

Manpath/usr/local/man

Manpath/usr/local/share/man

/etc/man.config 32%

-N Displays the line number of each line

[Email protected] ~]# less-n/etc/man.config

1 #

2 # Generated automatically from man.conf.in by the

3 # Configure script.

4 #

5 # man.conf from man-1.6f

6 #

Common keys:

SPACEBAR: Represents a PAGE Down

Enter: represents scrolling down one line

B: The representative page back

Q: The delegate immediately leaves more

[PageDown]: Flip one PAGE Down

[PageUp]: Flip one page Up

Text Search:

/keyword: Forward Search

? KEYWORD: Reverse Search

N: Next with the same direction as the command

N: The previous one in the opposite direction of the command

head Data Selection command

This command is a few lines before the contents of the file are fetched. Only 10 rows are displayed by default.

Data Selection command format: Head [OPTION] ... [FILE] ...

OPTION:

-N # number, representing the meaning of several lines displayed

[Email protected] ~]# head-n 3/etc/man.config

#

# Generated automatically from man.conf.in by the

# Configure script.

Tail Data Selection command

This command is a few lines after the contents of the file are fetched. Only 10 rows are displayed by default.

Data Selection command format: tail [OPTION] ... [FILE] ...

OPTION:

-N # number, representing the meaning of several lines displayed

[Email protected] ~]# tail-n 3/etc/man.config

# Otherwise The database would be updated.

#

#MAKEWHATISDBUPDATES N

-F Tracks new append information without exiting

[Email protected] How is abc]# echo? >> TT

[Email protected] abc]# tail-f TT

Pwd=print Working Directory

Mkdir=

Cat=concatenat

Dddddde

How is old is you?

Touch Timestamp management or create new File command

Updates the timestamp to the current time. Each file has three timestamps:

Atime: The last time the file was visited;

Mtime: The last time the file was "modified";

CTime: The time the file was last "changed";

File data is divided into file metadata (attribute data) and data. When the file status changes, such as file name change, change permissions, and so on, then CTime time will change, and Atime and mtime time unchanged.

When the file content data is edited, the mtime time changes, and then CTime changes

When the file is accessed, the atime time changes, the same ctime also changes

CTime time changes when the properties of a file change, but Atime and mtime may not change

Timestamp management or create new File command format: Touch [OPTION] ... FILE ...

OPTION:

-A only update atime

File: ' TT '

Access:2015-08-26 13:31:05.638901911 +0800

Modify:2015-08-26 13:30:51.537900897 +0800

Change:2015-08-26 13:30:51.537900897 +0800

[Email protected] ~]# touch-a TT

Access:2015-08-28 07:50:11.000800946 +0800

Modify:2015-08-26 13:30:51.537900897 +0800

Change:2015-08-28 07:50:11.000800946 +0800

-M update Mtime only

File: ' TT '

Access:2015-08-28 07:50:11.000800946 +0800

Modify:2015-08-26 13:30:51.537900897 +0800

Change:2015-08-28 07:50:11.000800946 +0800

[Email protected] ~]# touch-m TT

Access:2015-08-28 07:50:11.000800946 +0800

Modify:2015-08-28 08:49:51.725799067 +0800

Change:2015-08-28 08:49:51.725799067 +0800

-C do not create an empty file

In general, if file does not exist, an empty file is created by default.

files View file type command

If you want to know the basic data of a file, such as ASCII or data files, or binary, etc.

[[Email protected] ~]# file Install.log

Install.log:utf-8 Unicode Text

    • File Management related commands

. cp Copy command

Used to copy a file or directory operation.

Copy command format:

CP [OPTION] ... [-T] SOURCE DEST

CP [OPTION] ... SOURCE ... DIRECTORY

OPTION:

-R Recursive replication

-V shows the running process

[Email protected] ~]# cp-rv/345/tmp

'/345 ', '/tmp/345 '

'/345/123 ', '/tmp/345/123 '

'/345/678 ', '/tmp/345/678 '

'/345/678/789 ', '/tmp/345/678/789 '

'/345/678/789/tt ', '/tmp/345/678/789/tt '

-P is copied along with the properties of the file

[Email protected] ~]# CP-PV install.log/tmp/345

[email protected] ~]# ll Install.log;ll/tmp/345/install.log

-rw-r--r--. 1 root root 63202 4 15:54 install.log

-rw-r--r--. 1 root root 63202 4 15:54/tmp/345/install.log

-F enforces overrides, but this parameter is invalid if there is the-I parameter

[Email protected] ~]# \cp-f TT/ABC

[email protected] ~]# ll TT/ABC/TT

-rwxr-xr-x. 1 Allen Allen 108 11:16/abc/tt

-rwxr-xr-x. 1 Allen Allen 108 17:31 TT

-A recursive replication and preserves file time, permissions, owner properties

[Email protected] ~]#\cp-av TT/ABC/TT

[email protected] ~]# ll TT/ABC/TT

-rwxr-xr-x. 1 Allen Allen 108 17:31/abc/tt

-rwxr-xr-x. 1 Allen Allen 108 17:31 TT

-s copy into a symbolic link file (symbolic link), or "shortcut"

[Email protected] abc]# CP-SV TT SLINK-TT

' TT ', ' Slink-tt '

[email protected] abc]# LL

Total 4

lrwxrwxrwx. 1 root root 2 13:27 slink-tt, TT

-rwxr-xr-x. 1 Allen Allen 108 17:31 TT

-D Copy the properties of the connection file instead of the connection file itself

[Email protected] abc]# CP-DV slink-tt alink-tt

' Slink-tt ', ' Alink-tt '

[email protected] abc]# LL

Total 4

lrwxrwxrwx. 1 root root 2 13:41 alink-tt, TT

lrwxrwxrwx. 1 root root 2 13:27 slink-tt, TT

-rwxr-xr-x. 1 Allen Allen 108 17:31 TT

-rwxr-xr-x. 1 Allen Allen 108 17:31 TT

rm Remove a file or directory command

Remove file or Directory command format: RM [OPTION] ... [FILE] ...

OPTION:

-F Force Execution

[Email protected] 789]# rm-f TT

-R recursively deletes the specified directory and file

[Email protected] ~]# rm-rf/345

moving files and directories or renaming commands in . MV

To remove a file from a directory or rename a command format:

MV [OPTION] ... [FILE] ...

MV [OPTION] ... SOURCE ... DIRECTORY

OPTION:

-F Force Execution

[Email protected] abc]# mv–f Tt/lab

[Email protected] abc]# LL/LAB/TT

-rwxr-xr-x. 1 Allen Allen 108 17:31/lab/tt

Change file name

[[Email protected] lab]# MV TT 1t

[email protected] lab]# ll 1t

-rwxr-xr-x. 1 Allen Allen 108 17:31 1t

Move multiple files

[Email protected] tmp]# MV Fstab.out Functions/lab

. WC file content Statistics command

Counts the number of bytes, words, and lines of a given file, and displays the output of the statistic results. If the file name is not given, it is read from the standard input.

File content Statistics command format: WC [OPTION] ... FILE ...

OPTION:

-L count rows

-W count words. A word is defined as a string separated by a blank, a jump, or a newline character.

-M counts the number of characters. This flag cannot be used with the-C flag

-C Statistics byte number

[email protected] lab]# Cat TT

I am OK

Abc

[[email protected] lab]# WC tt

2 4 tt ' 2 is the number of rows,4 is the number of words, andthe number of bytes

[Email protected] lab]# wc-l TT

2 TT '

[Email protected] lab]# wc-w TT

4 TT

[Email protected] lab]# wc-c TT

tt

[Email protected] lab]# wc-m TT

tt

. cut Select File Contents command

Extracts a text column from a text file or text stream. The selection of information is usually for "line" to analyze, not the entire information analysis.

Cut bytes, characters, and fields from each line of the file and write those bytes, characters, and fields to standard output. If you do not specify a file name, it reads standard input.

Choose File Content Command format: Cut [OPTION] ... FILE ...

OPTION:

-d Specifies the delimiter, which defaults to tab

-f Specifies which area to display

The range-n representation is from the 1~n field, the range n represents from n fields to the end of the line, and N-m represents the N~m field from the first.

[Email protected] lab]# echo $PATH

/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

[Email protected] lab]# echo $PATH | Cut–d:-f4,5

/sbin:/bin

[email protected] lab]# who

Root Tty2 2015-08-17 10:10

Root pts/0 2015-08-29 11:08 (172.16.10.100)

Root PTS/1 2015-08-29 14:06 (172.16.10.100)

[email protected] lab]# who | Cut–d ' –f6

Tty2

pts/0

Pts/1

-C is delimited as a character unit

The range-n is represented from the 1~n character, the range n is represented from n characters to the last character, and N-m represents the n~m character from the first.

[email protected] lab]# cat Labtest.txt

111 222 333 444 555 666

111 222 333 444 555 666

AAA BBB CCC DDD Eee FFF

AAA BBB CCC DDD Eee FFF

-----------------------

[email protected] lab]# cat Labtest.txt |cut-c3,23

16

16

Af

Af

--

-S prints only the lines that contain delimiters, and if not, prints lines that do not contain separators

[email protected] lab]# cat labtest.txt |cut–s–d ' –f6-10

666

666

Fff

Fff

. Sort file content ordering command

Sorts the rows in the specified file and outputs the result standard. If there are multiple files, it will concatenate the files and sort them as a file.

File content Sort command format: sort [OPTION] ... FILE ...

OPTION:

-R Sort by reverse order

[email protected] lab]# cat Labtest.txt

111 222 333 444 555 666

111 222 333 444 555 666

AAA BBB CCC DDD Eee FFF

AAA BBB CCC DDD Eee FFF

-----------------------

[Email protected] lab]# sort-r labtest.txt

AAA BBB CCC DDD Eee FFF

AAA BBB CCC DDD Eee FFF

111 222 333 444 555 666

111 222 333 444 555 666

-----------------------

-U repeats only once

[email protected] lab]# cat Labtest.txt |sort-u

-----------------------

111 222 333 444 555 666

AAA BBB CCC DDD Eee FFF

-T Specify delimiter

-K is sorted by that interval (field)

[email protected] lab]# cat List.txt

Tom winstrom:94201:1

Janet dempsey:94111:20

Alice Macleod:94114:12

David mack:94114:23

Toni Barnett:95020:8

Jack cooper:94072:0

Richard Macdonald:95510:3

[email protected] lab]# cat list.txt|sort-t:-K 2

Jack cooper:94072:0

Janet dempsey:94111:20

Alice Macleod:94114:12

David mack:94114:23

Tom winstrom:94201:1

Toni Barnett:95020:8

Richard Macdonald:95510:3

-N means sort by numeric size

[email protected] lab]# cat list.txt|sort-t:-K 3-n

Jack cooper:94072:0

Tom winstrom:94201:1

Richard Macdonald:95510:3

Toni Barnett:95020:8

Alice Macleod:94114:12

Janet dempsey:94111:20

David mack:94114:23

[email protected] lab]# cat list.txt|sort-t:-K 3-n|cut-d:-F3

0

1

3

8

12

20

23

uniq . Display file content unique line command

Removes consecutive repeating rows from a sorted file, leaving only one row, so uniq is often used in combination with sort.

File content Sort command format: uniq [OPTION] ... FILE ...

OPTION:

-C shows the number of repetitions per line

[Email protected] lab]# sort Labtest.txt |uniq-c

1-----------------------

2 111 222 333 444 555 666

2 AAA BBB CCC DDD Eee FFF

-D displays only the rows that have been repeated

[Email protected] lab]# sort Labtest.txt |uniq-d

111 222 333 444 555 666

AAA BBB CCC DDD Eee FFF

-U displays only rows that have not been repeatedly repeated

[Email protected] lab]# sort Labtest.txt |uniq-u

-----------------------

This article is from the "Craft Life" blog, so be sure to keep this source http://allenh.blog.51cto.com/481430/1689622

Linux Learning: Linux basic Command Set (2)

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.