Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check file permissions

How can I check file permissions, without having to run operating system specific command via passthru() or exec()?

like image 639
UnkwnTech Avatar asked Aug 21 '08 08:08

UnkwnTech


People also ask

How do I check permissions on a file?

Step 2 – Right-click the folder or file and click “Properties” in the context menu. Step 3 – Switch to “Security” tab and click “Advanced”. Step 4 – In the “Permissions” tab, you can see the permissions held by users over a particular file or folder. Step 5 – Click “Effective Access” tab.

Which command is used to check permissions?

Check Permissions in Command-Line with Ls Command If you prefer using the command line, you can easily find a file's permission settings with the ls command, used to list information about files/directories. You can also add the –l option to the command to see the information in the long list format.


2 Answers

Use fileperms() function

clearstatcache();
echo substr(sprintf('%o', fileperms('/etc/passwd')), -4);
like image 67
Željko Živković Avatar answered Oct 07 '22 20:10

Željko Živković


You can use the is_readable(), is_executable() etc.. commands.

like image 29
Huppie Avatar answered Oct 07 '22 18:10

Huppie