Linux Interview Problems __linux

Source: Internet
Author: User
Tags chmod readable file permissions myvm

Usually used not much or indeed itself a little vague, thank the interviewer's explanation, here Record:
The meaning of file permission 4755 = s/s in file permissions.

chmod is a command for setting file permissions under Linux, followed by a number that represents the permissions of different users or groups of users.

Typically three digits:

The first number represents the permissions of the owner of the file

The second number represents the permissions of other users who belong to the same user group as the file owner

The third number represents permissions for other user groups

Permissions are divided into three types: Read (r=4), write (w=2), execute (x=1). It also combines readable executable (rx=5=4+1), readable writable (rw=6=4+2), readable writable executable (rwx=7=4+2+1).

Therefore, chmod 755 sets the user's permissions to:

1. File owner readable writable executable

2. Other user-readable executable with one user group belonging to the file owner

3. Other user groups can read executable

The difference between chmod 4755 and chmod 755 is that there is a bit more at the beginning, and this 4 means that other users have the same permissions as the owner when they execute the file.

Article Linux in the file special permissions through the example well explained here 4 meaning:

Take a look at an example to see your/usr/bin/passwd and/etc/passwd file permissions

[Root@mylinux ~]# ls-l/usr/bin/passwd/etc/passwd

-rw-r--r--1 root root 154908-1913:54/etc/passwd

-rwsr-xr-x 1 root root 229842007-01-07/usr/bin/passwd

As we all know,/etc/passwd files stored in each user's account and password information,/USR/BIN/PASSWD is the implementation of changes and view the file of the program, but from the permissions,/etc/passwd only have root rights write (W) right, But why each user can directly call/usr/bin/passwd to write/etc/passwd so as to modify their own password it. Note that here S replaces the X (-rwsr-xr-x 1 root root 229842007-01-07/usr/bin/passwd), where s enables other users to perform/usr/bin/passwd with the same permissions as owner root.

Here the 4 or S is a special file permission, in fact S can be used in user or group, and there is another special permission T:

Look at an example and see your/tmp directory permissions

[Root@mylinux ~]# Ls-dl/tmp
DRWXRWXRWT 6 root root 4096 08-22 11:37/tmp
The TMP directory is a temporary folder that is common to all users. All users have read and write permissions, this will inevitably have a problem, a user in/tmp created a file a.file, at this time, B users see the bad, in/tmp to delete it (because have read and write permission), that certainly is not.

Files or directories in directories with T privileges can be deleted and modified only by owner and Root, and others cannot be deleted even if they have write permissions.

How to set the above special permissions:
Setuid:chmod u+s XXX
Setgid:chmod g+s XXX
Stick Bit:chmod o+t xxx

Alternatively, using the Octal method, a number is added to the previous number, and the number of numbers represented by the three permissions is similar to the general permissions, as follows:

Suid GUID Stick bit
1 1 1

So:
Suid binary string is: 100, conversion decimal is: 4
The binary string for the GUID is: 010, conversion decimal: 2
Stick bit binary string: 001, Conversion decimal: 1

So you can also set this:
Setuid:chmod 4755 xxx
Setgid:chmod 2755 XXX
Stick bit:chmod 1755 xxx

Finally, after some files have special permissions set, the letters are not lowercase s or T, but uppercase s and T, and the special permissions for this file do not take effect because you have not given it a corresponding user's X permission.

The size of hard links and soft connections.

Through the test below, the hard link is the same inode node as the source file, pointing to the same file, which is certainly the same size; the soft connection can be understood as the file content contains the address or path of the source file, so it has its own size. [AAA@MYVM ~]$ mkdir mytest
[AAA@MYVM ~]$ CD MyTest
[Aaa@myvm mytest]$ echo "AAAAAAAAAAAAAAAAA" >hello
[aaa@myvm mytest]$ ln Hello Hello2
[AAA@MYVM mytest]$ ln-s Hello Hello3
[AAA@MYVM mytest]$ Ls-lia
Total 16
5764989 drwxrwxr-x 2 aaa 4096 11-25 16:03.
5566272 drwx------AAA 4096 11-25 16:02.
5765068-rw-rw-r--2 AAA AAA 11-25 16:03 Hello
5765068-rw-rw-r--2 AAA AAA 11-25 16:03 Hello2
5765116 lrwxrwxrwx 1 AAA AAA 5 11-25 16:03 Hello3-> Hello
[Aaa@myvm mytest]$ echo "BBBBBBBBBBB" >>hello
[AAA@MYVM mytest]$ Ls-lia
Total 16
5764989 drwxrwxr-x 2 aaa 4096 11-25 16:03.
5566272 drwx------AAA 4096 11-25 16:02.
5765068-rw-rw-r--2 aaa 11-25 16:04 Hello
5765068-rw-rw-r--2 AAA 11-25 16:04 Hello2
5765116 lrwxrwxrwx 1 AAA AAA 5 11-25 16:03 Hello3-> Hello

How to set the default permissions for the current user to create a new file or directory.

Umask is used to define default permissions for new files or directories, the permissions for the new directory are the values set by 777-umask, and the new file's permissions are the values set by 666-umask. To permanently modify the value of a umask, you can write it in/etc/profile or ~/.profile or ~/.bash_profile.

[AAA@MYVM mytest]$ Umask
0002
[AAA@MYVM mytest]$ Umask-s
U=rwx,g=rwx,o=rx
[AAA@MYVM mytest]$ mkdir AA
[Aaa@myvm mytest]$ Touch BB
[AAA@MYVM mytest]$ Ls-la
Total 12
Drwxrwxr-x 3 aaa 4096 11-25 16:20.
DRWX------AAA 4096 11-25 16:20.
Drwxrwxr-x 2 AAA AAA 4096 11-25 16:20 AA
-rw-rw-r--1 AAA AAA 0 11-25 16:20 BB
[AAA@MYVM mytest]$ umask 022
[AAA@MYVM mytest]$ mkdir Aa2
[Aaa@myvm mytest]$ Touch Bb2
[AAA@MYVM mytest]$ Ls-la
Total 16
Drwxrwxr-x 4 aaa 4096 11-25 16:29.
DRWX------AAA 4096 11-25 16:20.
Drwxrwxr-x 2 AAA AAA 4096 11-25 16:20 AA
Drwxr-xr-x 2 aaa 4096 11-25 16:29 AA2
-rw-rw-r--1 AAA AAA 0 11-25 16:20 BB
-rw-r--r--1 AAA AAA 0 11-25 16:29 BB2

Find. -name "filename" in the filename why must be quoted. But it is not required in LS.

Find [-h] [l] [P] [path ...] [Expression] ls [OPTION] ... [FILE] ...

Because the "filename" here is actually a pattern in the expression, you must add "" to organize the shell's parsing. For example Find. -name "aa*"-exec rm {}.

How to quickly copy all files in a shared directory on a remote machine to local for read-only use.

If not copied, simply mount to the local directory. But here is the requirement to copy to the local, so here you can use Softlink to change the copy time of the file to a fixed value. The-s parameter of the CP can be used specifically.

The file road strength in Linux can be used in spaces.

You can use double quotes in Windows, and Linux uses the empty cells.

mkdir my\ \ folder (2 spaces in the middle)

CD my\ \ folder/


Kill-9-9 What does that mean.

Forcibly kill.


Finish.

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.