Category filter
Script to Copy Files and Folders on Mac
To copy a file or folder to another location on a Mac, the user will first have to navigate to the location on the Finder application and use the context menu option ‘Copy’ or press command + C to copy the file. Then, they have to open the target location and use the context menu option ‘Paste’ or press command + V to paste the file/folder. This method is tedious for the device administrator when managing multiple endpoints and impractical when copying multiple files or folders or doing a batch operation. On the other hand, using a script to automate this process is easy, efficient, and effective. This doc includes a collection of shell scripts that you can run from the Terminal app to copy files or folders on a Mac.
Device admins can remotely run scripts on Macs managed with Hexnode using the Execute Custom Script action.
Scripting Language – Bash
File extension – .sh
Copy file/folder
1 2 |
#!/bin/bash cp –R ‘path to file/folder’ ‘new path’ |
Example – cp –R Desktop/1 Desktop/2
The cp
command copies the content of a source file to the target file. The -R
option allows you to copy a directory and all its subfolders. If the path given ends in /, the directory contents are copied rather than the directory itself.