Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to determine the permissions of a specified user to a specified directory in linux

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article shows you how to determine the permissions of a specified user on a specified directory in linux. The content is concise and easy to understand, which will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

Power.sh

#! / bin/sh

Username3=$1

Dir_name2=$2

# get existing directory

File_path=$dir_name2

While true

Do

If [- d $file_path]; then

Break

Fi

File_path=$ {file_path%/*}

Done

Dir_name2=$file_path

# Judge whether the user exists

Grep "^ $username3:" / etc/passwd > / dev/null

If [$?-ne 0]; then

Echo "This user\" $username3\ "does not exist."

Exit 4

Fi

# echo "username: $username3"

Group4= `grep "^ $username3:" / etc/passwd | awk-F: {'print $4'} | xargs-I grep {} / etc/group | cut-d ":"-f1`

# echo "group: $group4"

Su-l $username3-c "test-r $dir_name2"

Is_read=$?

Su-l $username3-c "test-x $dir_name2"

Is_exe=$?

Su-l $username3-c "test-w $dir_name2"

Is_write=$?

$is_read_str

$is_exe_str

$is_write_str

If [$is_read-eq 0]; then

Is_read_str= "r"

Else

Is_read_str= "-"

Fi

If [$is_exe-eq 0]; then

Is_exe_str= "x"

Else

Is_exe_str= "-"

Fi

If [$is_write-eq 0]; then

Is_write_str= "w"

Else

Is_write_str= "-"

Fi

Echo "${is_read_str} ${is_write_str} ${is_exe_str}"

Note: the script must be executed as root.

The script power.sh requires two parameters, the first for the specified user and the second for the specified directory

Test:

[root@ppc40 study] # sh power.sh whuanga4 / tmp/abc/dd

This user "whuanga4" does not exist.

[root@ppc40 study] # sh power.sh whuang4 / tmp/abc/dd

Rw-

(description: indicates that user whuang4 has read and write permissions to the directory / tmp/abc/dd and does not have execute permissions).

The above is how to determine the permissions of a specified user on a specified directory in linux. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report