Linux Learning Notes (3) file processing commands for Linux common commands

Source: Internet
Author: User
Tags touch command

The command format for Linux is generally: command [-options] [parameters], such as ls-la/etc, you need to note:1) Individual commands are not used in this format, 2) when there are multiple options, can be written together; 3) There are simplified options (-) and full options, such as-a equals-all.

(1) LS

The function of the LS command is to display the directory file , the original is a list, where the path is/bin/ls, all users can execute. The relevant syntax is as follows:

LS option [-ald] [file or directory]

which

-A: Displays all files, including "." Hidden files at the beginning

-L: Show details in long format

-D: Intended as directory for viewing directory properties

-h:human-readable, humanized display file size

-I: View the file's I node, the system generally based on the I node search and query files

Description

The first "-" in-rw-r--r--represents the file type , and the common file types in Linux are binary (represented), directories (in D), and soft connection files (in L).

After the rw-(Permissions of the owner U), r--(the permission of the owning Group G), r--(the permission of the other person O), and three permissions R for reading, W for write, and X for execution .

(2) mkdir

The mkdir command is used to create a new directory , meaning make directories, where the path is/bin/mkdir and can be performed by all users. Its syntax is as follows:

mkdir-p [directory Name]

Where:-p indicates recursive creation, that is, the creation of a directory that does not exist, and its subdirectories can also be created . Note:mkdir can create multiple directories at the same time .

(3) CD

The CD command is used to switch directories , meaning change directory, which belongs to the Shell's built-in commands, with the following syntax:

CD [catalogue]

such as: Switch to the specified directory---cd/tmp/test; switch to the previous level directory---CD.

(4) PWD

The pwd command is used to display the current directory , originally the print working directory, where the path is/BIN/PWD

(5) RmDir

rmdir command to delete empty directory, note is empty directory ! The original intent is remove empty directories, where the path is/bin/mkdir. Its syntax is:

rmdir [directory Name]

(6) CP

The CP command is used to copy files and directories , originally copy, where the path is/BIN/CP and the syntax is:

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

which

-r: Indicates replication directory

-P: indicates reserved file attributes

The command to copy the/tmp/test directory to the/root directory is as follows:

Copy the Install.log file from the/root directory to the/root/test directory and save its file attributes:

The Linux CP command has a feature in which the copied file name can be changed during replication , such as copying/tmp/test to the/root directory and changing its name to TEST_CN

(7) MV

The MV command is used to cut the file and change the name, meaning move, where the path is/BIN/MV. The MV syntax is:MV [original file or directory] [target directory]

Note: The MV can cut one or more directories, unlike the CP, which does not require the-r option to complete the operation of the directory.

Cut the/tmp/test/test1 directory into the/root directory, and then change its name to TEST1_CN, with the following command:

(8) RM

The RM command is used to delete a file or directory , with the intent of remove, where the path is/BIN/RM, with the syntax in the following format:

RM–RF [file or directory]

which

-R: Delete Directory

-F: Forced execution

For example, delete a file or directory that was copied or cut before/boot

Note: It's a good idea to back up a copy of a file before deleting it, because there's no Recycle Bin in Windows that's deleted from the disk after it's deleted.

(9) Touch

The Touch command is used to create an empty file , where the path is/bin/touch, with the syntax in the following format:

touch [filename]

For example, create a program files file in the/tmp directory, and be careful to create quotes as shown:

(Ten) Cat

The Cat command is used to display the contents of the file, where the path is/bin/cat, in the syntax format:

Cat [file name]

If you add the-n option, you can display the text line number . The disadvantage of cat is that it is not suitable for browsing longer files .

If you view the contents of the issue file in the/etc directory:

(one) TAC

The TAC command is used to reverse-list the contents of a file , where the path is/USR/BIN/TAC, with the syntax in the following format:

TAC [File name]

() more

The more command is used for paging the contents of the file, suitable for browsing long files , where the path is/bin/more, and its syntax format is: more[filename]

While browsing the contents of the file, you can use the spacebar or the F key to page down, use the ENTER key to break down the line, and use Q or Q to exit the display .

Note that the more command has a flaw in which you cannot page up .

(+) Less

The less command is similar to more, but can page up to display the contents of the file, where the path is/usr/bin/less, with the syntax format: less[filename]

In addition to the keyboard commands in more, lesscan use the "PgUp" key to page up, or use the UP arrow to wrap up the line. At the same time, the less command can also be used to find the keyword, just enter the "/+ keyword", the search process using the N key can be looked down .

For example, display the contents of the/etc/services file, and then look for service keywords, as shown in the following:

(+) head

The Head command is used to display the first few lines of a file , where the path is/usr/bin/head, in the syntax format:

head [file name], if you add the- n option, you can specify the number of rows to display, and if this option is not specified, 10 rows are displayed by default .

For example, the first 5 lines of the/etc/services file are displayed:

(tail)

The Tail command is used to display the end of a file with a path of/usr/bin/tail, with the syntax in the following format:

Tai [filename], option-n can still specify the line number to display. The- f option is included in the tail to dynamically display the end of the file, monitor logs, and more .

(+) ln

The ln command is used to generate the linked file , the English original is link, where the path/BIN/LN, the syntax format is:ln-s [source file] [destination file], where the-s option means to create a soft connection .

Soft Connection File features are:1) Similar to the shortcut in Windows, the source file is lost, the soft connection file is inaccessible, the soft connection file permissions are always rwxrwxrwx;2) because the soft connection file is only a symbolic link to the source file, so its file size is small ; 3) The arrows in the/tmp/issue.soft->/etc/issue point to the source file .

hard-Link file creation without the-s option , the characteristics of which are:1) hard-link file creation is equivalent to cp–p operation, except that hard-link files and source files can be updated synchronously, can be used for real-time backup, and when the source file is lost, hard links can still continue to access ; 2) A hard-link file can be identified by the I node with the same file ID as the source file .

The difference between a hard link and a soft connection is that: 1) hard links cannot be created across partitions, 2) hard links cannot be used for directories .

Linux Learning Notes (3) file processing commands for Linux common commands

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.