Comprehensive knowledge of Linux directory management

Source: Internet
Author: User

Path symbol
. current directory
.. Previous level Directory
- Previous Directory
~ Home folder for current account
~chai Chai the home folder of this account
Directory processing commands

PS: Using tab for file completion, is a good habit, to avoid the wrong file name.

    1. CD Switch Directory

    2. PWD Displays the directory where you are currently located
      Pwd=print working Directory

pwd #输出当前工作目录pwd#输出当前的真实路径,而非连接路径#例子:文件/var/aaa的实际路径是/home/chai/aaacd /var/aaapwd#显示/var/aaapwd -P #显示实际路径/home/chai/aaa
    1. mkdir New Directory
mkdir[-mp] 目录
-m-m744 /dir//如果没有-m这个参数,创建的目录会有默认的权限。
-p-p /dir1/dir2/dir3//递归创建目录会有风险,如果我打错了字,会把错误的目录创建出来
    1. RmDir Deleting an empty directory

Ps:rmdir can only delete empty directories.

rmdir [-p] 目录-p:将上层出现的目录全删了。但必须都得是空的。
Environment variable Path

When we execute the command: Ls-al, the system will follow the path set paths, go to these paths to find LS This file, and execute.
If there are multiple LS files in the path, then the LS file found first is executed.

//查看PATHecho$PATHPS:$后跟的是一个变量。PS:PATH由很多路径组成,每个路径之间用:隔开。PS:不同用户的PATH是不一样的。
//在PATH中添加路径/chaiPATH="$PATH":/chaiPS:当前目录.不要放在PATH中,因为当前目录不是固定的,这样会造成错误!
View directory Structure
ls [-aAdfFhilnrRSt] 目录ls [--color={never,auto,always}] 目录ls [--full-time] 目录
-A
list all files, including the. Start of hidden files
-A Lists all files, including the. Start of hidden files, but not included. With the. These two directories
-D List directories only, no files listed
-F List results directly without sorting
-H Display the file size in an easy-to-read manner
-L Lists long data strings, including attributes, and so on
-T Sort by Time
-S Sort by capacity
-R Reverse the sort result output
-/-color=never Do not give color based on file attributes
-/-color=always Show color to File
-/-color=auto Let the system decide for itself whether the file is realistic color
-/-full-time Output at full time
-/-time={atime,ctime} Output access time Atime or permission change time ctime, not modification time mtime

PS: In many distributions, you can replace ls-l with LL.

Copy CP

The CP command has not only the ability to copy, but also the creation of a connection file (shortcut), a comparison of the two files with the old and new updates, the copying of the entire directory, and so on.

cp[options] 原文件 目标文件夹cp[options] 原文件1 原文件2 原文件3 目标文件夹
-p
-a
-d Wakahara file is a connection file, copy only the properties of the connection file without copying the contents of the connection file
-f (Force strong copy) if the destination file already exists, delete it and re-copy it.
-i
-r recursive copy, Wakahara file is a directory, then this parameter will copy all the contents of the original directory past (often)
-s copy and make the destination file a connection file (shortcut)
-u Wakahara file is newer than the target file to overwrite the target file (for update)
//将文件/var/chai复制到/usr中去,并更名为shixvcp /var//使用新的文件名PS:如果目标文件加了名字,就表示将目标文件更名;若目标文件只是一个路径,就表示仍然使用原来的文件名。cp /var//仍然适用原来的文件名

By default, the permissions and attributes of the file after CP change, including: permissions, user group name, modification time, etc.
If the copied file and the original file remain exactly the same, then the attribute-A is added, and all the properties are at a high consistency.
However, after we have copied other people's data, we hope that the data are our own, we should be able to do all kinds of operations on the data, so we need to make the CP after the completion of the permission changes, and this permission must be modified by the person copied to you.

PS: Show details of two specified files
Ls-l Files 1 Files 2

PS: CP of multiple files to the specified directory
CP file 1 file 2 specified directory

Default permissions and hidden permissions for files/directories

In addition to the basic RWX permissions, the Linux ext2/ext3 file system, we can also set the system hidden properties, it can be set with chattr, lsattr to view. The most important attribute is that you can set the file/directory to be non-modifiable, which can make it impossible for the file owner to modify, which is important for security.

Default permissions for Files Umask

Umask refers to the user's default permissions when creating a new file/directory.

Ways to view Umask:

//方法一:直接输入umask,显示四个数字:0022umask0022//第一位不要管,后面三位分别对应文件主、同组用户、其他用户在默认权限的基础上被剥夺的权限。//PS:文件的默认权限是(rw-rw-rw);目录的默认权限是(rwxrwxrwx)

The default permissions above are 022, so when you create a new file, the default permissions are: (RW-RW-RW)-(--w–w-) = (rw-r–r–); When you create a new directory, the default permissions are: (rwxrwxrwx)-(--w–w-) = (rwxr-xr-x)

Comprehensive knowledge of Linux 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.