Our documentation is getting an overhaul! We would like your input! Click here to take a look at the beta launch of our new documentation site! Only cPanel & WHM version 82 documentation exists on our beta at this time. 84 will be added to the new site soon! Leave your feedback here: https://go.cpanel.net/docsfeedback
cPanel API 2 Functions - Fileman::search - Developer Documentation - cPanel Documentation
Child pages
  • cPanel API 2 Functions - Fileman::search
Skip to end of metadata
Go to start of metadata


This function recursively searches for a file within a directory.


We strongly recommend that you use UAPI instead of cPanel API 2. However, no equivalent UAPI function exists.


In cPanel & WHM version 76 and later, when you disable the FileStorage role, the system disables this function. For more information, read our How to Use Server Profiles documentation.




 For more information, read our Calls from the WHM API documentation.

 LiveAPI PHP Class
$cpanel = new CPANEL(); // Connect to cPanel - only do this once.
// Search for files that begin with /home/example
$search_files = $cpanel->api2(
    'Fileman', 'search', 
		'dir' 		 	=> 'home/example'
		'attributes'	=> 'user|groupusage|size|type|mode|ctime|atime|mtime'


For more information, read our Guide to the LiveAPI System.


 LiveAPI Perl Module
my $cpliveapi = Cpanel::LiveAPI->new(); # Connect to cPanel - only do this once.
# Search for files that begin with /home/example
my $search_files = $cpliveapi->api2(
    'Fileman', 'search',
		'dir' 		 	=> 'home/example'
		'attributes'	=> 'user|groupusage|size|type|mode|ctime|atime|mtime'


For more information, read our Guide to the LiveAPI System.


 cPanel Tag System (deprecated)


  • In cPanel & WHM version 11.30 and later, cPanel tags are deprecated. We strongly recommend that you only use the LiveAPI system to call the cPanel APIs. Examples are only present in order to help developers move from the old cPanel tag system to our LiveAPI.
  • cPanel API 2 calls that use cPanel tags vary in code syntax and in their output.
  • For more information, read our Deprecated cPanel Tag Usage documentation.

 Command Line
cpapi2 --user=username Fileman search dir=home%2Fexample attributes=user%7Cgroupusage%7Csize%7Ctype%7Cmode%7Cctime%7Catime%7Cmtime


  • You must URI-encode values.
  • username represents your account-level username.
  • You must run the --user=username command.
  • For more information and additional output options, read our Guide to cPanel API 2 documentation or run the cpapi2 --help command.
  • If you run CloudLinux™, you must use the full path of the cpapi2 command:


 Output (JSON)
  "cpanelresult": {
    "apiversion": 2,
    "func": "search",
    "data": [
        "ctime": 1414597689,
        "mtime": 1414597689,
        "mode": 457,
        "file": "/home/example",
        "size": 4096,
        "mimeinfo": "homeb",
        "groupusage": 64768,
        "user": "example",
        "type": "dir",
        "atime": 1412105321
        "ctime": 1412105376,
        "mtime": 1412105376,
        "mode": 384,
        "file": "/home/example/.lastlogin",
        "size": 10,
        "mimeinfo": "text-x-generic",
        "groupusage": 64768,
        "user": "example",
        "type": "file",
        "atime": 1412105376
        "ctime": 1412233359,
        "mtime": 1412233359,
        "mode": 416,
        "file": "/home/example/cpbackup-exclude.conf",
        "size": 1,
        "mimeinfo": "text-plain",
        "groupusage": 64768,
        "user": "example",
        "type": "file",
        "atime": 1412233359
    "event": {
      "result": 1
    "module": "Fileman"


Use cPanel's API Shell interface (cPanel >> Home >> Advanced >> API Shell) to directly test cPanel API calls.


ParameterTypeDescriptionPossible valuesExample



The path to search.

This parameter defaults to the home directory.


The function also searches this directory's subdirectories if the recursive value is 1.

Any valid absolute file path./home/user

A list of attributes to return for each result.

If you do not use this parameter, the function will not return any attributes.

  • user — Search for the file's owner's name.
  • groupusage — Search for the file's group's name.
  • size — Search for the file size.
  • type — Search for the file type.
  • mode — Search for the file's permissions.
  • ctime — Search for the file's creation time.
  • atime — Search for the last time that the file was accessed.
  • mtime — Search for the last time that the file was modified.


Separate multiple attributes with the pipe character (|).


Whether to perform the search recursively.

This parameter defaults to 0.

  • 1 — Search recursively.
  • 0 — Do not search recursively.

Whether to return the mimeinfo return.

This parameter defaults to 1.

  • 1 — Return the mimeinfo return for each result.
  • 0 — Do not return the mimeinfo return for each result.

Perl Compatible Regular Expression (PCRE) that filters the results.

If you do not use this parameter, the function returns information for all of a directory's files.

A valid PCRE.user


ReturnTypeDescriptionPossible valuesExample
atimeintegerThe file's last accessed time.A Unix time stamp.1412105376
ctimeintegerThe file's creation time.

A Unix time stamp.

filestringThe file's name.A valid path and filename.
groupusageintegerThe file owner's system group ID.A positive integer.
mimeinfostringThe file's MIME type.A valid MIME type.text-plain
modeintegerThe file's permissions.A set of file permissions, in decimal notation format.
mtimeintegerThe file's last modification time.A Unix time stamp.1413830456
sizeintegerThe size of the file.A positive integer, in bytes.4096
typestringThe item type.
  • file
  • dir
  • char
  • block
  • fifo
  • link
  • socket
userstringThe file owner's user ID.Any valid user ID on the server.example

A reason for failure


This function only returns a reason value if an error occurred.

A string that describes the error.This is an error message.

Whether the function succeeded.

  • 1 — The function succeeded.
  • 0 — The function failed.