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
Find file path
1 |
find / -name ‘file name with extension’ -print 2>/dev/null |
For example:
find / -name document.txt -print 2>/dev/null
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. Even if some scripts are marked as Failed, you can still see the file location by selecting the Show Output option.
List files with specific file extension
1 |
find / -name "*.<extension>" -print 2>/dev/null | head -n <count> |
For example: find / -name "*.txt" -print 2>/dev/null | head -n 10
This example finds all files with the .txt extension and lists the file paths for the first 10 files only. Replace <extension>
with the appropriate file extension and <count>
with the desired number of outputs according to your requirement.