mkfile - macOS
Overview
mkfile is a macOS command used to create a new file with specified content. It’s a simple yet effective way to quickly create files with predefined text or data without relying on other text editors or scripts.
Syntax
mkfile [-h] [-d DIR] [-f] [-i] [-s SUFFIX] [-t TYPE] [-v] FILE...
Options/Flags
- -h, –help: Display usage information.
- -d, –directory DIR: Create the file in the specified directory (default: current directory).
- -f, –force: Overwrite existing file without confirmation.
- -i, –interactive: Prompt for confirmation before overwriting existing file.
- -s, –suffix SUFFIX: Specify the suffix (extension) for the new file.
- -t, –type TYPE: Set the file type (e.g., text, binary, symbolic link).
- -v, –verbose: Display more detailed output.
Examples
Create a new empty file:
mkfile myfile
Create a file with specific content:
mkfile -t text myfile <<< "Hello, world!"
Create a new file in a different directory:
mkfile -d /tmp myfile
Common Issues
- Permission Denied: Ensure you have write permissions in the specified directory.
- File Already Exists: Use the
-f
or-i
option to overwrite or prompt for confirmation.
Integration
Combine with touch
to create empty files:
touch foo; mkfile foo -t text <<< "My Content"
Create multiple files in a loop:
for i in {1..10}; do mkfile -f temp$i; done
Related Commands
- touch: Create an empty file.
- cp: Copy a file.
- mv: Move a file.