Linux Learning Note II: File processing commands for Linux

Source: Internet
Author: User

1. File processing command: LS

Role: Display directory files

Syntax: LS [options] [file or directory]

[option]:-a Show all files, including hidden files

-L Show more information

-D View Directory properties

[File or directory]: defaults to the current path as an argument when omitted

Instance:

· LS Displays information about all files (not including hidden files) under the current folder

· Ls-l Show details of all files (excluding hidden files) under the current folder

· Ls-ld Show details of the current folder

Tip: To view the information for a folder, you must add the-d parameter; To view detailed parameters, you must add the-l parameter.

2. Properties of the file

When you use the Ls-l hello.txt command, you will see details about the Hello.txt file in the current directory. As follows:

Drwxr-xr-x   2  root  root  4096 12-01 20:52 bin

This string of information from left to right means the following:

Type [Owner's permissions] [Permissions of the owning group] [Other people's rights] [Number of hard links] Owner [Owning group] [File Size] [Last modification time or creation time] Name

[Type]:d indicates that the bin is a directory.] D means directory-represents a binary file L represents a soft link file link

[Owner's permission]:rwx indicates that the owner has permission to read, write, and execute the directory.]

[The permission of the owning group is]:r-x, which indicates that the owning group has read and execute permissions on the directory.]

[Other people's permissions are]:r-x, indicating that the owner, someone outside the owning group, has permission to read and execute the directory.]

[Hard link number]:2. Indicates that there are two hard links

[Owner]: Owner is root. Note that the owner is not necessarily the creator, because ownership of the file or directory can be transferred.

[Owning group]: the directory belongs to the root user group

Note that for files and folders, the corresponding meanings of rwx are different. They have the following meanings:

R Read permission (file) to view the contents of a file (a folder) to list content in a directory

W Write permission (file) can modify the file contents (folder) can be created in the directory, delete files

X Execute permissions (files) can execute files (folders) can enter directory

3. Switch directory: CD

Syntax: CD [catalog]

Cd.. Switch to the previous level directory

CD/switch to the root directory (the left slash in Linux indicates the root directory)

Cd/home/chanshuyi/desktop switch to the Desktop directory

4. Display working directory: PWD

Syntax: pwd

Function: Displays the current path

5. Create a file Touch

Syntax: touch [filename]

Action: Create an empty file

Example: Creating a Hello.txt file $touch hello.txt (default current path)

6. Create Directory MkDir

Syntax: mkdir [directory name]

Role: Create a new directory

Example: Creating a Newdir folder $mkdir Newdir

7. copy files or directories CP

Syntax: CP [Options] [source file or directory] [destination directory]

[Option]:-r Assignment directory (need to be added when copying directories)

Function: Assign a file or directory

Example: CP hello.txt./hello.txt copy Hello.txt to the parent directory

Cp-r newdir./newdir Copy the Newdir folder to the parent directory

8. Moving files, renaming MV

Syntax: MV [source file or source directory] [destination directory]

Action: Move file, rename. In fact, the name of the change or file movement, when you move a file to the original folder is renamed.

Example: MV hello.txt~ hello.txt renaming hello.txt~ file to Hello.txt

9. Delete file rm

Syntax: RM [Options] [file or directory]

[option]-R Remove Directory-F Force Delete no reminder

Action: Delete a file or directory

Example: RM hello.txt Delete hello.txt file

rm-r Hello Delete Hello folder

10. display file Contents cat

Syntax: cat [filename]

Function: Display file contents

Example: $cat hello.txt Display the contents of a Hello.txt file

11, paging to view the contents of the file more

Syntax: more [filename]

Role: For paging through long-content files

Operation Key: (space) or F display next page

(Enter) to display the next line

Q or Q exit

12. View the first few lines of the file head

Syntax: head [options] [filename]

[option]-n indicates the first n rows are displayed

Example: $head -20/etc/services display the first 20 lines of a file

13. View the end of the file in a few lines tail

Syntax: tail [options] [file name]

[option]-n Specifies that the end n rows are displayed

-F Dynamic Display of file contents (i.e. Page view)

14. Generate Link File ln

Syntax: ln [options] [source file] [target file]

[option]-s to create a soft link (default is to create a hard link)

Note: A soft link is equivalent to a shortcut, whereas a hard link is equivalent to a copy + sync update.

Example: $LN-S/etc/issue/issue.soft create a soft link for the issue file

$LN/etc/issue/issue.hard Create a hard link for the issue file

Note: Hard links cannot be generated across file systems, and soft links can. (Cross-file systems refer to files that cross partitions, such as/test partitions, that cannot be created under a hard link to/(root directory).) Here the/test is a partition, not the test directory under the root directory Oh.

Next: Linux Learning Note II: Linux Permissions processing command

Linux Learning Note II: File processing commands for Linux

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.