1. File permissions
1.1 The user has a special permission called Setuid (S), which appears in the execution permission (x) location, and the Setuid permission allows the user to execute the executable file with the owner's permission, even if the executable file is
Run by other users.
The permission sequence for a file with setuid permissions is as follows:
-RWS------
The use of setuid is not unlimited, and it can only be used on Linux ELF binary files for security purposes and not for script files.
The 1.2 directory has a special permission called the sticky bit (sticky bit). If the directory has sticky bits set, only the user who created the directory can delete the files in the directory, even if the user group and other users have write permissions. Sticky bits appear in the execution permission bits (x) of other user rights, expressed using T or T. If you do not set the Execute permission, but set the sticky bit, you use T, if you set both Execute permission and sticky bit, is using T.
For example:
d------RWT
d------RwT
A typical example of setting a directory sticky bit is/tmp
L For example:
DRWXRWXRWT root root 12288 December 18:40 tmp
1.3 Setting non-modifiable files
Chattr +i Filname
1.4 Print out the compliance link in the current directory
Ls-l | grep "^l" Explanation: ^ is the starting tag of the string
Readlink print out the target path that matches the link
For example:
[Email protected]:/etc/rc.d# readlink S11sysctl
.. /init.d/sysctl
1.5 Printing file types
File filename
For example:
[Email protected]:~/tarfiles$ file qsdk-qca-shortcut-fe-2.7.029.tar.bz2
QSDK-QCA-SHORTCUT-FE-2.7.029.TAR.BZ2:BZIP2 compressed data, block size = 900k
[Email protected]:~/dl$ file B.txt
B.txt:ascii text
[Email protected]:~/dl$ file base.sh
Base.sh:bourne-again shell script, UTF-8 Unicode text executable
[Email protected]:~/dl$ file *
111:setgid, Directory
Aaa:symbolic Link to A.txt
Add.sh:bourne-again shell script, ASCII text executable
Apple.sh:bourne-again shell script, ASCII text executable
Array.sh:bourne-again shell script, ASCII text executable
A.txt:ascii text
Base.sh:bourne-again shell script, UTF-8 Unicode text executable
Bc.sh:POSIX shell script, ASCII text executable
B.txt:ascii text
Cecho.sh:ASCII text
Checkword.sh:ASCII text
C.txt:ascii text
Duplicate_files:empty
Duplicate_samples:empty
Filestat.sh:utf-8 Unicode Text
Getoopt.c:c Source, ASCII text
Interactive.sh:utf-8 Unicode Text
Isroot.sh:POSIX shell script, ASCII text executable
Junk.data:data
Log.sh:bourne-again shell script, ASCII text executable
Makemore.sh:ASCII text
Printf.sh:POSIX shell script, UTF-8 Unicode text executable
Remove_dup.sh:ASCII text
Rename.sh:utf-8 Unicode Text
Rmmore.sh:ASCII text
Sleep.sh:bourne-again shell script, ASCII text executable
Test:directory
Test.sh:ASCII text
1.6 Finding and Patching file differences
Command: diff
The diff output in non-integrated (nonunified) Form (The-u option is not available) is as follows:
[Email protected]:~/dl$ diff version1.txt Version2.txt
2,3c2
< line2
< Line3
---
> lin2
5a5
> GNU is not UNIX
The output of the integrated form is as follows:
[Email protected]:~/dl$ diff-u version1.txt version2.txt
---version1.txt 2015-12-28 19:16:28.866869790 +0800
+ + + version2.txt 2015-12-28 19:17:12.078872041 +0800
@@ -1,5 +1,5 @@
This is the original text
-line2
-line3
+lin2
Line4
Happy hacking!
+gnu is not UNIX
You can redirect to generate a patch file:
[Email protected]:~/dl$ diff-u version1.txt version2.txt > Version.patch
[Email protected]:~/dl$ cat Version.patch
---version1.txt 2015-12-28 19:16:28.866869790 +0800
+ + + version2.txt 2015-12-28 19:17:12.078872041 +0800
@@ -1,5 +1,5 @@
This is the original text
-line2
-line3
+lin2
Line4
Happy hacking!
+gnu is not UNIX
Use the following command to Patch:
[Email protected]:~/dl$ patch-p1 Version1.txt < Version.patch
Patching file Version1.txt
[Email protected]:~/dl$ cat Version1.txt
This is the original text
Lin2
Line4
Happy hacking!
GNU is not UNIX
[Email protected]:~/dl$
[Email protected]:~/dl$ diff-u version1.txt version2.txt
[Email protected]:~/dl$
Re-enter this command again PATCH-P1 Version1.txt < Version.patch, you can remove the patch file
Shell Scripting Learning (iv)