3rd Linux Common Commands (1) _ File Processing command

Source: Internet
Author: User
Tags touch command

1. file processing commands

1.1 command format: command [-option] [arguments], such as Ls–la/etc

(1) Individual command use does not follow this format

(2) When there are multiple options, can be written together, such as the above-la

(3) simplified option with full option –a equals –all

1.2 Directory processing Commands

1.2.1 Display directory or file information: LS

(1) LS command

Command name

LS (English original list)

Command path

/bin/ls

Execute permissions

All Users

Grammar

ls [options] [file or directory]

(2) Option description

Options

Description

-A

Displays all files, including hidden files. The file name is hidden and begins with a.

-L

Detailed information display (long format)

-I.

I node index information for output files

-H

User-friendly display (human) that lists the size of the file in an easy-to-understand format, such as K, M, G, etc.

-D

Displays only the current directory properties, not the information for the files or directories under it

(3) Message description for option '-l ' Display

(4) Application examples

① Show all files (including hidden files) in/etc directory ls–lha/etc

② only displays the properties of the/etc directory itself: ls–lhd/etc

1.2.2 Create a new directory: mkdir

(1) mkdir command

Command name

mkdir (English original make directories)

Command path

/bin/mkdir

Execute permissions

All Users

Grammar

ls [-p] [directory name] //-p means recursive creation

(2) Application examples

① $mkdir –p/tmp/japan/boduo

② $mkdir/tmp/japan/longze/tmp/japan/cangjing

1.2.3 Switch directory: CD

(1) CD command

Command name

CD (original CD directory)

Command path

Shell built-in commands

Execute permissions

All Users

Grammar

CD [catalogue]

(2) Application examples

① $CD/tmp/japan/boduo Switch to the specified directory

② $CD. Go back to the top level directory ( note CD with "..." There are spaces between them)

③ $CD. Returns to the current directory, which is the directory itself, so the display does not change

1.2.4 Show current directory: PWD

(1) PWD command

Command name

PWD (English print working directory)

Command path

/bin/pwd

Execute permissions

All Users

Grammar

Pwd

(2) Application examples

The ① $pwd displays the current directory, such as/tmp/japan

1.2.4 Delete Empty Directory : RmDir

(1) rmdir command

Command name

Remdir (English remove empty directories)

Command path

/bin/rmdir

Execute permissions

All Users

Grammar

rmdir [Directory] (note that the specified directory must be an empty directory)

(2) Application examples

① $rmdir/tmp/japan/boduo Delete Boduo this directory

1.2.5 Copy files or directories: CP

(1) CP command

Command name

CP (English copy)

Command path

/bin/cp

Execute permissions

All Users

Grammar

CP-RP [Original file or directory] [target directory]

-R Copy Directory (note that you do not need to add-r when copying files)

-P Reserved File attributes

(2) Application examples

① Copy directory/tmp/japan/cangjing to directory/root, and keep directory properties

$CP –rp/tmp/japan/cangjing/root

② copy multiple files simultaneously: Copy the following two files to the/tmp directory

Cp/root/install.log/root/install.log.syslog/tmp

③ Keep File properties

CP/ROOT/INSTALL.LOG/TMP//Two file attributes (such as modified time) are different

CP–P/ROOT/INSTALL.LOG/TMP//Two file attributes are the same

④ duplicate renaming at the same time

Cp/root/install.log/tmp/setup.log

1.2.6 cut file, rename: MV

(1) MV command

Command name

MV (English move)

Command path

/bin/mv

Execute permissions

All Users

Grammar

MV [original file or directory] [target directory]

(2) Application examples

① move the/tmp/japan/cangjing directory to/root:

$MV/tmp/japan/cangjing/root

② cut multiple files or directories to a specified directory (similar to the CP command)

③ the same time as the cut directory name Nvshen

$MV/tmp/japan/longze/root/nvshen

1.2.7 Delete File: RM

(1) RM command

Command name

RM (English remove)

Command path

/bin/rm

Execute permissions

All Users

Grammar

RM-RF [file or directory]

- r Delete directory

- F Force Delete

(2) Precautions

① is generally unrecoverable after deletion.

② absolutely cannot delete root directory: that is RM–RF/

 ③ Delete all files (including directories) under the/tmp/movie directory: $rm-rf/tmp/movie/*

④ Delete directory: Rm–rf/tmp/japan

1.3 File processing Commands

1.3.1 Create an empty file: Touch

(1) Touch command

Command name

Touch (English Touch)

Command path

/bin/touch

Execute permissions

All Users

Grammar

touch [filename]

(2) Application examples

① creating story.list files in the current directory: $touch story.list

  ② creating filenames with spaces : Touch "Santa Claus.txt" (not recommended for creating filenames with spaces)

③ Create two files simultaneously $touch Santa Claus (Filenames are Santa and Claus respectively)

1.3.2 Display file contents: Cat

(1) Cat command

Command name

Cat

Command path

/bin/cat

Execute permissions

All Users

Grammar

cat-n [file name]

-N: Show line numbers

(2) Application examples

① $cat/etc/issue

② $cat –n/etc/services

(3) The TAC command, in contrast to the cat command, displays the file backwards from the last 1 lines to the 1th line.

1.3.3 page shows the contents of the file: more

(1) More commands:

Command name

More

Command path

/bin/more

Execute permissions

All Users

Grammar

more [filename]

(space) or F: page turn, but not upward

(Enter): line break

Q or Q: Exit

(2) Application example: $more/etc/services

1.3.4 page display of file contents: Less

(1) Less command:

Command name

Less

Command path

/usr/bin/less

Execute permissions

All Users

Grammar

less [filename]

(space) or F or (PgDn): Page Down

(pgup): Page Up

(Enter), DOWN ARROW: line break

Up ARROW:: Up one line

Q or Q: Exit

(2) Application examples:

$less/etc/services, you can turn pages or wrap them by pressing the buttons above. You can also enter "/What to find" to find and press N to continue looking.

1.3.4 show file before/after lines: Head/tail

(1) Head or Tail command: When the file is too long, in order to view a few lines, but also avoid flipping too many pages from behind.

Command name

Head/tail

Command path

/usr/bin/head (tail)

Execute permissions

All Users

Grammar

head/tail [filename]//default front/back 10 lines

–n Front/rear x line

(2) Application examples:

$head –n 20/etc/services

$tail –n 7/etc/services

1.4 Link Command

1.4.1 generate a linked file

(1) ln command:

Command name

ln (English original: link)

Command path

/bin/ln

Execute permissions

All Users

Grammar

Ln–s [Original file] [target file]

-S Create soft links

(2) Application examples:

① creating a soft link for/etc/issue

$LN –s/etc/issue/tmp/issue.soft

② Creating a hard link

$LN/etc/issue/tmp/issue.hard

(3) The difference between soft links and hard links

① Soft Links:

A. Use "L" before the permission, the permission is 3 "rwx", that is all people have the operation permission to the soft link .

B. A shortcut similar to Windows, which is essentially two different files (theI node differs ) from the original file. So the permissions of the soft link is not equal to the original file permissions, but the soft link this file has the operation permissions.

C. File size is small, just a symbolic link.

② Hard Links:

A. Equivalent to pressing CP–P to keep a copy of the file attributes, but at the same time maintaining simultaneous updates.

B. The surface looks like two files, but essentially they are the same file , which can be seen from the I node of these two files. only when you create a hard link, you add 1 to the count of the file.

C. When deleting the original file or hard-linked file, the file count is reduced by 1, and when the file count is 0 o'clock, the file is physically deleted from the disk .

D. hard links cannot span different partitions because they are essentially the same file. At the same time, hard links also generate links for the catalog , but both of these can be soft links .

3rd Linux Common Commands (1) _ File Processing command

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.