File Resolution Check Condition

I am studying shell scriptnig if there is a way that I can test the operation, for example, checking file permission on file .. how ... I know some ways. search for a file using the find command using permission, or in "ls ... | grep" r - r - r 'smthg .. any permission u wan't

I have a file, how do I check if the file has the required resolution or not.? \

Thanks in advance.

+3
source share
4 answers

You can do something like:

Test to run:

if [ -x "$file" ]; then
  #do_something
fi

Test for writing:

if [ -w "$file" ]; then
  #do_something
fi

Test for reading:

if [ -r "$file" ]; then
  #do_something
fi
+4
source
stat FILENAME --print=%A

. man stat - // ..

+2

You can use test

Parameters -r -x -w test to read, execute, and write. In a shell script, a test command is usually entered as [

0
source

Check the search help page. in the EXAMPLES section. You can see how to find files with the required resolution.

0
source

Source: https://habr.com/ru/post/1757283/


All Articles