Linux file and directory management-

Source: Internet
Author: User
Tags file copy

This series of blogs is from: http://www.92csz.com/study/linux/

Here, thank the original person to provide the introductory knowledge

The purpose of this series of blogs is to extract the more commonly used LIUNX commands from the author's articles for their own study and review.

Absolute Path : The path must be written by the root directory "/", for example/usr/local/mysql this is the absolute path.

relative path : The path is not written by the root directory "/", for example, the first user enters/then enters the home, the command is Cd/home and then the CD test at this time the user's path is/home/test. The first CD command is followed by the/home second CD command followed by test, with no slash, this test is relative to the/home directory, so called relative path

pwd This command prints out the current directory

CD entry to a directory

./refers to the current directory

.. /refers to the top-level directory of the current directory.

mkdir Create a directory whose syntax is mkdir [-MP] [directory name]

-M: This parameter is used to specify the permissions to create the directory, which is not commonly used, so I do not focus on explaining.

-P: Recursively create the directory.

RM Delete directory or file

-F Mandatory meaning, if you do not add this option, when deleting a nonexistent file will be an error.

The effect of the-I option is to prompt the user if a file is deleted when the user deletes it. (default is already)

-R When the directory is deleted, add this option, if you do not add this option will error

which the absolute path used to find a command

alias is used to set the aliases of the directives. Syntax: alias[alias]=[directive name], such as alias Rm= ' Rm-i ', that is, when we use the RM command, we are actually using rm–i, and the absolute path of the/BIN/RM will not be alias, the command will be described in detail in later chapters.

ls View a directory or a file, is the list of shorthand.

-A All files are listed, including hidden. The file names for these hidden files are prefaced with.

-l lists the file's attribute information in detail, including the size, creation date, owning group, and so on. ll this command equates to ls–l.

-D back with the directory, if not added this option lists the files under the directory, plus the only train directory itself.

The abbreviation for CP Copy, which is a copy. Format for CP [option] [source file] [destination file]

-D here involves a concept of "connection". Connections are divided into soft and hard connections. It will be explained in more detail in a later section, and now you just have to understand that the soft links here are similar to shortcuts in Windows. If you do not add this-D then copy the soft connection to the destination file copy of the soft connection, and after the addition, it is only a copy of a connection file (that is, a shortcut).

-R If you want to copy a directory, you must add the-r option, otherwise you will not copy the directory.

-I if I encounter an existing file, I will ask whether to overwrite it. (default already used)

-u This option takes effect only if the destination file is present and does not do anything if the source file is newer than the target file.

The MV movement means the shorthand for move. Format mv [options] [source file] [target file], here are a few common options.

-I, like the CP, asks if the user wants to overwrite when the target file is present. In the Redhat/centos system, the MV we use is actually mv–i

The-u option for-U and the top CP command is a function that takes effect when the target file is present and does not do anything if the source file is newer than the target file.

If the destination file does not exist, it is equivalent to renaming.

A common command for cat is to view the contents of a file and display it on the screen.

-N When viewing a file, the line number is also displayed on the screen.

-A show all things out, including special characters

The TAC is actually a cat's anti-write, and the same functionality is also reversed to print the contents of the file onto the screen.

Less is the same as more, but better than the more good can be turned upside down. The SPACEBAR can also be paged, while pressing the "J" key can be moved downward (click to move down one line) and press "K" key to move up. When you use more and less to view a file, you can click the "/" key and then enter a word carriage return so that you can find the word. If you have more than one word, you can press the "N" key to display the next. Alternatively, you can press "/" instead of "?" In the same word as word, the only difference is that "/" is searched down the current line, and "?" is to search up the current line.

The first 10 lines of the file are displayed directly after head head with the filename. If the Add –n option displays the first n rows of the file.

tail and head, followed directly with the file name, displays the last ten lines of files. If the plus-n option displays the last n rows of the file.

-F dynamically displays the last ten lines of the file, and if the file is increasing, use the-f option

"File owner and owning group"

The Linux file attribute not only specifies the owning and owning group, but also the permissions of the owning primary (user), the owning group, and other users (others) to the file. You can view these properties through Ls-l.

"Linux file Properties "

In the example above, when viewing files in the current directory with Ls–l, a total of 9 columns are displayed (columns are separated by spaces)

The 1th column contains things that have the file type and the owner, the owning group, and other users ' permissions to the file.

The 2nd column, which represents the node (inode) occupied by the connection, is usually related to how many directories are in the directory, and the link is described in more detail in a later section.

The 3rd column, which represents the owner of the file.

The 4th column, which represents the group to which the file belongs.

The 5th column, which represents the size of the file.

Columns 6th, 7th, and 8th are listed as the date the file was created or the most recent modification date, respectively, for the month date and time.

9th column, file name. If you have one in front of you. Indicates that the file is a hidden file.

" Change permissions for a file "

1) change the owning group chgrp

Syntax: CHGRP [group name] [file name]

With the Groupadd command, a user group is added.

-R is used only for the directory, the role is cascade change

2) Change the owner of the file chown

Syntax: Chown [-r] Account name file name

Chown [-r] Account name: Group name File name

Here, the-r option is used only for the directory, which is cascading changes that change not only the current directory, but the directory or file in the directory.

Useradd is used to add a user

You can change both the owner and the owning group by using the following methods

Chown–r User1:testgroup Test This changes the test together with the owner and the owning group of the test2 under the test directory.

3) Change the user's read and write execution permissions to the file chmod (important)

In Linux, in order to facilitate the change of these permissions, Linux uses numbers to replace RWX, the specific rules for R:4 w:2 x:1-:0

chmod syntax: chmod [-r] XYZ file name (xyz here, representing a number)

The-r option functions as Chown, cascading changes.

It is worth mentioning that, in the Linux system, the default permissions for a directory is 755, and the default permission for a file is 644.

Chmod also supports the use of rwx to set permissions. From the previous introduction we can find that basically nine properties are (1) User (2) group (3) others three group! Then we can represent the properties of three groups by means of u, G, O! In addition, a represents all three groups! Modify multiple permissions at the same time, separated by commas.

Linux file and directory management-

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.