Linux Archives and Directory management

Source: Internet
Author: User

1. Directory and Path 1.1 absolute path and relative path

Absolute path: Must have root directory/write, for example:/usr/share/doc

Relative path: Not by root/write, for example: by/usr/share/doc to/usr/share/man, you can use the following command

Relative path means: The path to the current working directory

. Represents the current directory;. represent the parent directory

1.2 CD Transform Catalog

CDs are abbreviations for change directory and are instructions for changing the working directory.

cd– back to the first directory that was/usr/share/doc.

Cd.. Back to Parent Directory

Tips:linux default Instruction column default mode (bash Shell) with file auto-completion function, you can use the [Tab] key to achieve the integrity of your directory

1.3 pwd Displays the directory where you are currently

PWD is print working directory, showing the path where the current directory is located

#pwd –P Displays the real directory, not the linked directory, such as the/var/mail directory that points to/var/spool/mail (the link directory is equivalent to a shortcut under Windows)

1.4 mkdir Create a new directory

#mkdir Directory Name

#mkdir –p Directory 1/Directory 2/Directory 3 .... (Create a recursive directory, subdirectories, sub-subdirectories)

#mkdir –m 711 test0 (Create a directory with permissions)

1.5 rmdir Delete Empty directory

#rmdir Directory Name

#rmdir –p Directory 1/Directory 2/Directory 3 .... (Delete recursive directories, subdirectories, sub-subdirectories)

#rmdir只能删除空目录

#touch filename (New profile 123)

#rm –r non-empty directory (can be deleted unless empty directory)

1.6 $PATH (must capitalize) the path of the execution instruction

#ls is the instruction to check the properties of a file, which is located in/bin/ls (absolute path), why can we execute #ls instruction in any directory? This is caused by the environment variable path. When we execute the LS command, the system will follow the path to the directory of each path definition to search for the executable file named LS, if in the directory defined by the path contains more than one file named LS, the first search to the same name is executed!

#echo $PATH (view paths defined by path)

Each directory under path is separated by a colon: Each directory is in sequence. You can find that both root and normal user sky,path have/bin directories, so you can find/bin/ls under any path to execute the LS command.

1.7 ls file and directory view

ls most commonly used to the function or the option of-L, for this, many distribution in the default case, will be (L's lowercase) set to become Ls-l! In fact, that feature is the alias feature of the Bash shell

1.8 CP,RM,MV Copy Delete and move

#CP source file destination file

#cp – I source file target file (if the target already exists, will ask the action when overwrite)

#cp – r Source File destination file (recursive copy directory)

#cp – A source file destination file (along with the properties of the file is copied in the past)

#rm – f file or directory (forced deletion)

#rm –i file or directory (ask before deleting)

#rm –r file or directory (recursive deletion)

#mv移动档案与目录或更改名称

2. File content access

2.1 Cat starts displaying archive content from the first line

Cat is concatenate (continuous) shorthand, the main function is to print the contents of a file continuously on the screen!

2.2 TAC starts with the last line

2.3 NL display, by the time the travel number

2.4 More page shows the contents of the archive

2.5 Less is similar to more, but you can page ahead

2.6 Head only a few lines, the default display of 10 rows

You can see there are 152 lines in Man.config.

#head –n-100/ect/man.config Lists the previous 52 rows, and the next 100 lines do not display

2.7 Tail only look at the tail a few lines

#tail –n-100/etc/man.config lists everything after 100 lines, that is, 100-152 rows, and the preceding 99 rows are not displayed.

If you want to show/etc/man.config lines 11th through 20th, how do you do that?

2.8 OD reads the contents of the file in a binary way

The execution document is usually binary file binary format, if you read its contents with the above instruction, it will display garbled, this is to use the OD instruction

Example: Display the contents of the/USR/BIN/PASSWD in a 8-binary storage value and an ASCII table

3. Time parameters of file time and new archive 3.1 file
    • Modification Time (mtime)--When the contents of the archive changed
    • Status Time (CTime)--When file permissions or property changes
    • Access Time (Atime)-When the contents of the archive are taken, such as Cat

3.2 Creating a Profile

3.3 Modifying the archive time

4. Default permissions and hidden permissions for files and directories

The permissions of the file are rwx read-write execution; directory attributes are d–l directories, files, linked files, etc.

4.1 chgrp Change the group to which the archive directory belongs

#chgrp [-r] Group name file directory name//-R = recursive, subdirectory of directory, double directory

4.2 Chown Change the owner of the archive directory

#chown [-r] owner file directory

#chown [-R] Owner: Group name file directory//change owner and owning group at the same time

4.3 chmod Changing the permissions of the file directory
    • #chmod [-r] XYZ file directory//x, Y and Z represent the owner, group, and other user's permissions, such as X=7 (r+w+x), r=4,w=2,x=1
    • #chmod [-R] U=rwx,go=rx archive directory//u=user;g=group;o=other;a=all
    • #chmod [-r] a+w file directory//+ represents the increase of permissions,-on behalf of delete permissions, = Delegate permissions, a+w This means that all users are added W Write permission

      Instance:

      Create the test directory under/TPM, create a 123 text file in the test directory, we can see the files and directories created under the root user, both the owner and the owning group are root, Here we set the owner of the test directory and all the files in its directory (only 123 files) to Sky, and the owning group is set to the user group. and other users except their own sky only read and manipulate the permissions.

switch to normal user Sky and edit 123 Archives, edit content "Hello my Linux"

Switch to the normal user tyang3, you can view the file under/tmp/test, but not the right to rewrite the content inside

Switch to Sky users except for themselves, other users have only R read-only permissions on the test directory

Switch to another user Tyang3, unable to access the Sky user's Test directory and view its internal files

Changing the/tmp/test directory permission to only x for other users, we find that other users tyang3 can access the directory, but cannot view the files in the directory

Summarize:

r--: The user cannot access the directory or the files in the directory

--x: The user can enter the directory, but do not have permission to operate, such as LS,CP

R-x: The user can enter the directory, can also operate, but cannot modify the contents of the file in the directory

4.4 Umask File Preset permissions

When we create the file or directory, there will be a default permission,Umask's score refers to the default value needs to be reduced , R,w,x is 4, 2, 1 points

    • #umask//Digital configuration of the permission to set the score, the first set of numbers are special permissions, the other three groups for user rights
    • #umask –S//symbol type displays the set permissions

    • Create profile

      When creating the file, the default is no executable x permission, only RW's permission, that is,-rw-rw-rw-, so umask the maximum score is 666 points

    • Create a Directory

      When creating a directory, the default value for permissions is drwxrwxrwx, so the Umask maximum score is 777

As shown, the root admin umask default value is 0022, we only look at the latter three bits 022,

When the root administrator creates the file, the owner user does not reduce the permissions (0), the owning group groups minus the W permission (2), and the other user also lose the W permission (2), so the last file permissions created are-rw-r-r--

When the root administrator creates the directory, the owning primary user does not reduce the permissions (0), the owning group groups minus the W permission (2), and the other user also lose the W permission (2), so the last directory permission created is Drwxr-xr-x

Bingo! Bingo! Fully correct, interested colleagues can switch to regular users for testing.

How do I change the default value of Umask?

#umask Modifying values

The root administrator's umask default is 022, while the normal user umask default is 002

4.5 Hidden properties of chattr files

Usage: #chattr [+-=] [asacdistu] File or directory

Example: Create a attrtest archive and add the properties of I (cannot delete, rename, create link)

Permission to cancel file I

4.6 lsattr Show hidden properties of a file

4.7 Special Permissions for files

Linux Archives 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.