When working in cross-platform environments between macOS and Linux, you'll often encounter mysterious ._filename files. These are resource fork files created by macOS to store additional file metadata (like custom icons or Finder info) when files are transferred to non-HFS filesystems.
The most efficient way to remove all these files in a directory is:
find . -type f -name "._*" -delete
This command:
- Scans the current directory (.) recursively
- Targets only files (-type f)
- Matches the ._ prefix pattern (-name "._*")
- Deletes them immediately (-delete)
For verification before deletion:
# First list all matching files
find . -type f -name "._*"
# Then delete after confirmation
find . -type f -name "._*" -exec rm -v {} \;
For files with spaces or special characters:
find . -type f -name "._*" -print0 | xargs -0 rm -f
When transferring files from macOS:
# Using rsync
rsync --exclude='._*' -avz source/ destination/
# Using tar on macOS before transfer
COPYFILE_DISABLE=1 tar -cf archive.tar files/
For regular maintenance, create a cleanup script:
#!/bin/bash
TARGET_DIR=${1:-.}
echo "Cleaning ._ files in $TARGET_DIR"
find "$TARGET_DIR" -type f -name "._*" -delete
echo "Cleanup complete"
The simple rm ._* approach has limitations:
- Only works in current directory
- Fails if no matches exist
- Doesn't handle subdirectories
- May miss hidden ._ files
The find solution addresses all these issues.
Those pesky ._filename files you're seeing are resource forks created by macOS. When you transfer files between macOS and Linux systems, these hidden metadata files often tag along. They typically start with ._ followed by the original filename.
Here's the most efficient way to remove all ._ files in the current directory:
find . -type f -name "._*" -exec rm -f {} \;
Breaking down what this does:
find .- searches in current directory and subdirectories-type f- only targets regular files-name "._*"- matches files starting with ._-exec rm -f {} \;- force removes each matching file
If you want to preview files before deleting:
find . -type f -name "._*" -ls
For a more interactive approach (prompts before each deletion):
find . -type f -name "._*" -exec rm -i {} \;
If you frequently exchange files with macOS users, consider mounting shares with the nounix option or using dot_clean on the macOS side before transferring files.
This command removes both ._ files and .DS_Store files (another macOS artifact):
find . $-name "._*" -o -name ".DS_Store"$ -exec rm -f {} \;
For a more thorough cleanup script you could save as clean_macos_artifacts.sh:
#!/bin/bash
echo "Cleaning macOS artifacts..."
find "$1" -type f $-name "._*" -o -name ".DS_Store"$ -exec rm -f {} \;
echo "Directory $1 cleaned!"