Here’s something I can’t figure out: When using dired to manage files, let’s say I have a top level directory with a ton of subdirectories, each with a GoPro video inside (unique name/time/date for each file name). How do I move them all at once to that top level directory for easier management/renaming? I don’t want to have to go into each directory and move them one at a time with R. Let’s say all of the files are MP4 or HEVC.
find /path/to/parent/directory -type f \( -name "*.mp4" -o -name "*.hvec" \) -exec mv -t /path/to/parent/directory {} +
Explanation:
• find /path/to/parent/directory: Start the search from the specified parent directory. • -type f: Restrict the search to files (not directories). • \( -name "*.mp4" -o -name "*.hvec" \): Look for files with either a .mp4 or .hvec extension. • -exec mv -t /path/to/parent/directory {} +: Execute the mv command to move the found files to the specified parent directory.
I can think of two options:
M-x find-dired RET RET RET
(or adjust query): which will list all files recursively in dired. You probably don’t need to copy them elsewhere for renaming. UseM-x dired-toggle-read-only
(orC-x C-q
), rename in-place, and commit (toggle againC-x C-q
). https://xenodium.com/batch-renaming-with-counsel-find-dired-and-wdireddired-subtree
: enables drilling down to multipe subdirectories from the same dired buffer. Expand the subdirectories needing management, and edit like 1. (viaC-x C-q
) https://xenodium.com/drill-down-emacs-dired-with-dired-subtree
Edit: markup
I’ll give it a try. Thank you Xenodium. Everyone seems to have pointed me in this direction. I knew Dired would have something like this.
You don’t need to move files around just to bulk rename them. If you want to do it, sure, you can, but you don’t have to.
In your top level directory:
- C-u C-x d (alternatively C-u M-x dired)
You will be in minibuffer now. Be sure dired listing switches have -l and -R option; -l is probably already there among anything else you might use; just type space and add -R at the end and type Return (Enter)
Now you will have a Dired buffer with al the subdirectories and files in them listed in the same buffer.
- C-x C-q in Dired to switch to WDired mode (I have bound it in my Emacs to C-S-r for easier typing)
You are now in “writeable dired” mode where you can edit all file names as if it were an ordinary text buffer. You can also use replace-string for example to replace a part of the name in all filenames at once, regex-replace, etc. You can do it manually, or whatever else you would do in a text buffer.
- C-c C-c to save your changes when you are done; all files will be updated.