Basic Attributes of Linux Files
The Linux system is a typical multi-user system where different users have different roles and permissions. To protect the security of the system, Linux has different regulations for user access to the same file (including directory files).
In Linux, we can use the ll or ls -l command to display the attributes of a file as well as the user and group to which the file belongs.
[root@www /]# ls -ltotal 64dr-xr-xr-x 2 root root 4096 Dec 14 2012 bindr-xr-xr-x 4 root root 4096 Apr 19 2012 boot……[tom@redhat ~]$ file /bin/bin: symbolic link to `usr/bin'[tom@redhat ~]$ file //: directory
In the example, the first attribute of the bin file is represented by “d”. In Linux, “d” indicates that the file is a directory.
The first character in Linux indicates whether the file is a directory, file, or link, etc.
If it is [ d ], it is a directory.
If it is [ – ], it is a file (type or binary);
If it is [ l ], it indicates a link file;
If it is [ b ], it indicates a block device file (random access device); (/dev/null)
If it is [ c ], it indicates a character device file, such as a keyboard or mouse (sequential access device).
Linux Directory File Management
1. cp command
-a: Equivalent to -pdr.
-d: If the source file is a link file, copy the link file attributes instead of the file itself;
-f: Force, if the target file already exists and cannot be opened, remove it and try again;
-i: If the target file already exists, prompt before overwriting (commonly used).
-l: Create a hard link instead of copying the file itself;
-p: Copy the file attributes along with the file, instead of using default attributes (commonly used for backups);
-r: Recursively copy, used for copying directories; (commonly used)
-s: Copy as a symbolic link, i.e., a “shortcut” file;
-u: Upgrade the destination only if it is older than the source!
$> cp file1 file2 file3 file$> cp -p dir dir2 //same as --preserve=mode,ownership,timestamps
2. cat
-A : Equivalent to -vET, lists some special characters instead of just whitespace;
-b : Lists line numbers, only for non-blank lines; blank lines are not numbered!
-E : Displays the end-of-line byte $;
-n : Prints line numbers, including blank lines; different from the -b option;
-T : Displays [tab] key as ^I;
-v : Lists some invisible special characters.
stat – display file or file system status
//inode: records file attributes, one file occupies one inode, and also records the block where this file's data is located.#> stat /etc/fstab File: ‘/etc/fstab’ Size: 465 Blocks: 8 IO Block: 4096 regular fileDevice: fd00h/64768d Inode: 67108930 Links: 1Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)Context: system_u:object_r:etc_t:s0Access: 2019-05-05 20:31:01.167606670 +0800Modify: 2019-02-18 21:04:12.908225490 +0800Change: 2019-02-18 21:21:18.722401048 +0800 Birth: -
3. wc – print newline, word, and byte counts for each file
-c, –bytes
print the byte counts
-l, –lines
print the newline counts
-w, –words
print the word counts
-m, –chars
print the character counts
4. mkdir – make directories
$> mkdir -p dir1/dir2/dir3$> mkdir dir1 dir2 dir3
5. ln – make links between files
//symbolic - similar to a shortcut in Windows, if the original file is deleted, it becomes unusable$> ln -s /etc/issue /tmp/issue.soft$> ll /tmp/issue.softlrwxrwxrwx. 1 tom tom 10 May 10 05:19 /tmp/issue.soft -> /etc/issue
//hard - similar to cp -p, but the difference is that it updates synchronously, if the original file is deleted, it is still usable$> ln /etc/issue /tmp/issue.hard$> ll /tmp/issue.hard-rw-r--r--. 2 root root 23 Jun 28 2017 /tmp/issue.hard
Difference
//The inode of the hard link is the same as the original file, and it can be updated synchronously$> ls -i /etc/issue$> ls -i /tmp/issue.soft

Graphical Interface – Nautilus
The operation is the same as in Windows.

Setting attributes

Set as needed
This article is a summary based on my self-learning experience. If you have any suggestions or opinions, please leave a comment at the end of the article. Thank you.