Zhaohuaxi pick up Linux practice 6 file directory permissions

linux exercise 6 file directory permissions

Welcome to follow the WeChat public account "Ambition and Home" to get the latest resources

Preface

The ls -ld command is the same as ll -d (only display the specific information of the current folder)

Difference between xxx and xxx/ and xxxt/*

xxx can represent a file or a directory, xxx/ can only be a directory, xxx/* means all files in this directory

Can be used with ll -d

"./" means the current directory, "/" means the root directory

Project 1. Set file permissions

  • Create user1 user and set a password, log in as user1 user.

    Create a directory test in the home directory of user user1, and enter the test directory to create an empty file file1. And display the file information in a long format, pay attention to the permissions of the file and the users and groups it belongs to

# mkdir test
# cd test
# ls
# touch flie
# ll
rw- r-- r--. 1 root root xxxxxxxxxx file1
  • Set permissions on the file file1 so that other users can write to this file. And view the setting result
test] # chmod o+w file1
test] # ll
rw- r-- rw-. 1  root root xxxxxxxxxx file1
  • Cancel the read permission of this file for users in the same group. View the setting result
test] # chmod g-r file1
test] # ll
rw- --- rw-. 1  root root xxxxxxxxxx file1
  • Set permissions for file1 in digital form, which is readable, writable, and executable by the owner; other users and group users have only read and execute permissions. Check the setting result after setting
test] # chmod 755 file1
test] # ll
rwx r-x r-x. 1 root root xxxxxxxxxx file1
  • Change the permission of file1 in digital form so that the owner can only read this file, and no other users have permission. View the setting result
test] # chmod 400 file1
test] # ll
r-- --- --- rw-. 1  root root xxxxxxxxxx file1
  • Add write permission for other users. View the setting result
test] # chmod o+w file1
test] # ll
r-- --- rw-. 1  root root xxxxxxxxxx file1
  • Go back to the upper directory and check the permissions of test
# ll -d test
drwx r-x r-x. 2  root root xxxxxxxx test
  • Add write permission to this directory for other users
# chmod o+w test
# ll -d test
drwx r-x rwx. 2  root root xxxxxxxx test

Item 2. Change the owner of the file

  • View the users and groups belonging to the directory test and the files in it
# ll -d test/

# ll -r test/
  • Change the owner of the directory test and all files under it to bin, and the group to daemon. View the setting result
chown -R bin:daemon test/
ll -d test/
drwxr-xrwx. 2 bin daemon xxxxxxxxx test
ll -r test/
r-- --- rw-. 1  root root xxxxxxxxxx file1
  • Delete the directory test and the files under it
rm -rf test

Guess you like

Origin blog.csdn.net/m0_46653702/article/details/110408050