Title: WP_Filesystem_Base::gethchmod
Published: April 25, 2014
Last modified: August 20, 2026

---

# WP_Filesystem_Base::gethchmod( string $file ): string

## In this article

 * [Description](https://developer.wordpress.org/reference/classes/wp_filesystem_base/gethchmod/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/classes/wp_filesystem_base/gethchmod/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/wp_filesystem_base/gethchmod/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_filesystem_base/gethchmod/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_filesystem_base/gethchmod/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_filesystem_base/gethchmod/?output_format=md#changelog)

Returns the *nix-style file permissions for a file.

## 󠀁[Description](https://developer.wordpress.org/reference/classes/wp_filesystem_base/gethchmod/?output_format=md#description)󠁿

From the PHP documentation page for fileperms().

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wp_filesystem_base/gethchmod/?output_format=md#parameters)󠁿

 `$file`stringrequired

String filename.

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wp_filesystem_base/gethchmod/?output_format=md#return)󠁿

 string The *nix-style representation of permissions.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_filesystem_base/gethchmod/?output_format=md#source)󠁿

    ```php
    public function gethchmod( $file ) {
    	$perms = intval( $this->getchmod( $file ), 8 );

    	if ( ( $perms & 0xC000 ) === 0xC000 ) { // Socket.
    		$info = 's';
    	} elseif ( ( $perms & 0xA000 ) === 0xA000 ) { // Symbolic Link.
    		$info = 'l';
    	} elseif ( ( $perms & 0x8000 ) === 0x8000 ) { // Regular.
    		$info = '-';
    	} elseif ( ( $perms & 0x6000 ) === 0x6000 ) { // Block special.
    		$info = 'b';
    	} elseif ( ( $perms & 0x4000 ) === 0x4000 ) { // Directory.
    		$info = 'd';
    	} elseif ( ( $perms & 0x2000 ) === 0x2000 ) { // Character special.
    		$info = 'c';
    	} elseif ( ( $perms & 0x1000 ) === 0x1000 ) { // FIFO pipe.
    		$info = 'p';
    	} else { // Unknown.
    		$info = 'u';
    	}

    	// Owner.
    	$info .= ( ( $perms & 0x0100 ) ? 'r' : '-' );
    	$info .= ( ( $perms & 0x0080 ) ? 'w' : '-' );
    	$info .= ( ( $perms & 0x0040 ) ?
    				( ( $perms & 0x0800 ) ? 's' : 'x' ) :
    				( ( $perms & 0x0800 ) ? 'S' : '-' ) );

    	// Group.
    	$info .= ( ( $perms & 0x0020 ) ? 'r' : '-' );
    	$info .= ( ( $perms & 0x0010 ) ? 'w' : '-' );
    	$info .= ( ( $perms & 0x0008 ) ?
    				( ( $perms & 0x0400 ) ? 's' : 'x' ) :
    				( ( $perms & 0x0400 ) ? 'S' : '-' ) );

    	// World.
    	$info .= ( ( $perms & 0x0004 ) ? 'r' : '-' );
    	$info .= ( ( $perms & 0x0002 ) ? 'w' : '-' );
    	$info .= ( ( $perms & 0x0001 ) ?
    				( ( $perms & 0x0200 ) ? 't' : 'x' ) :
    				( ( $perms & 0x0200 ) ? 'T' : '-' ) );

    	return $info;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-base.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-admin/includes/class-wp-filesystem-base.php#L373)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-admin/includes/class-wp-filesystem-base.php#L373-L416)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_filesystem_base/gethchmod/?output_format=md#related)󠁿

| Uses | Description | 
| [WP_Filesystem_Base::getchmod()](https://developer.wordpress.org/reference/classes/wp_filesystem_base/getchmod/)`wp-admin/includes/class-wp-filesystem-base.php` |

Gets the permissions of the specified file or filepath in their octal format.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_filesystem_base/gethchmod/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_filesystem_base%2Fgethchmod%2F)
before being able to contribute a note or feedback.