Category filter

Script to Find File path on Mac

Files can accumulate on the device after a significant period of use, making it difficult to find the correct location of a specific file or folder. On a Mac, the user can view the full location path of the target file by right-clicking on the file and clicking the Get Info option. With a large number of files to be managed, the process becomes a cumbersome task for the admins. Using Hexnode UEM, IT admins can remotely find the file location with just the file name and its extension by executing a custom script on the target endpoint device.

Scripting Language – Bash

File extension – .sh

Disclaimer:


The Sample Scripts provided below are adapted from third-party Open-Source sites.

Find file path

For example:
find / -name document.txt

Replace ‘file name with extension’ with the target file. The Terminal may take several minutes to complete this process. To see the output of the custom script, navigate to Manage > Devices > select your device > Action History and select the Show Output option corresponding to the executed action.

The terminal scans every folder path for the file and logs the search results in this file. Most entries will contain “Operation not permitted” or “Permission denied”, you can safely ignore those lines. To easily identify the target file path from the output logs, search for an entry without the “find” label at the start.

Notes:

  • In Bash, before inserting space while defining file or folder names, we use a backslash ‘\’ to separate the characters. This will prevent the shell interpreter from interpreting the space as a separator and assuming they were two different arguments. Hence, if the path is New Folder/myFile, we write it as New\ Folder/myFile or use single quotes as ‘New Folder/myfile’ instead.
  • It is recommended to manually validate the script execution on a system before executing the action in bulk.
  • Hexnode will not be responsible for any damage/loss to the system on the behavior of the script.

  • Sample Script Repository