Rename all .pdf files in subdirectories - terminal

I have some directory containing several subdirectories. Each subdirectory contains one .pdf file with some random name. I want to rename all these files with my_new_name.pdf. What is the best way to do it using command prompt?

Related

LibreOffice: recursively convert documents in folders and subfolders

I have stored many files in the doc format which I can only open with libreoffice on my mac.
The command:
./soffice --headless --convert-to docx --outdir /home/user ~/Downloads/*.doc
does exactly what it should: it converts all the *.doc files to libreoffice *.docx file.
My problem is that I have folders and subfolders with these files.
Is there any way to search through all the folders from a starting directory and to let "soffice" do its job in each of these folders, storing the new versions (*.docx) exactly where the original (*.doc) was found.
Unfortunately, I am not well-versed in apple script or in terminal to make this work. Yet there are 8000 doc files in hundreds and hundreds of folders that require the update to docx.
Thanks for your help.
Is there any way to search through all the folders from a starting directory and to let "soffice" do its job in each of these folders, storing the new versions (.docx) exactly where the original (.doc) was found.
This can actually be done in Terminal using a find command:
find '/path/to/directory' -type f -iname '*.doc' -execdir /Applications/LibreOffice.app/Contents/MacOS/soffice --headless --convert-to docx '{}' \;
In the example command above, change '/path/to/directory' to the actual pathname of the target directory that contains the subdirectories containing the .doc files.
What this find command does, in brief, is it finds all .doc files within the hierarchical directory structure of the '/path/to/directory' and executes the command in each subdirectory within containing the .doc files and converts each one in place in its subdirectory.
Notes:
Always insure you have proper backups before running commands in Terminal and the commands as typed will produce the wanted behavior!
This command assumes no .docx files already exist of the same name as the .doc files in the subdirectories, as it automatically overwrites any existing .docx files of the same name as the .doc files. As far as I can tell, the soffice command does not provide an option not to overwrite existing files. If this is going to be an issue, then a different solution will be necessary.

Batch re-name files in multiple directories on MacOS

I have around 500 JSON files sitting in their own directories that I need to re-name.
Every JSON file has the name, "list.json".
So what I need is a batch file operation for MacOS of some sort that will look in all the directories for files matching "list.json" and change the name to match name of the directory the file is sitting in. What kind of script do I need to do this?

How to move all files within subfolders into a new folder using bash?

I have a folder that I downloaded all my fonts to. When I opened the folder i noticed they were saved out into subfolders.
Is there a bash-shell script to grab all the files within the subfolders and move them to the parent folder?
You can move files with same extensions recursively using the wildcards. e.g. if you want to move all log files in nested folders under log/ directory into backup/ directory, you can use the following command:
mv log/**/*.log backup/

Rename batch files in bulk using spaces?

You can rename files in batch in bulk using, for example:
rename *.docx *.pdf
However, when my docx files have spaces in them, this renames them to new files which only have the first word in their file name. How do I preserve the entire file name?
EDIT: Apparently this is only the case when the file name as a dot in it (but the file has no extension still), for example:
2017. abcdef

rename multiple files bash in a subdir

I am trying to use rename but I have several subdirs. The expression I am trying to use is this:
rename 's/ZAUQ-F24MS-SC12-F01-5C\/R44.wav/wav\/2012.wav/' *.wav
I want to rename the file ZAUQ-F24MS-SC12-F01-5C/R44.wav to wav/2012.wav and all files are *.wav files.
I am able to do this from inside the directory but I have multiple directories and a mapped to and from list. Can rename do this or should I be using something else?
Apparently you are moving a file from one directory (ZAUQ-F24MS-SC12-F01-5C) to another (wav). Why not mv then:
mv ZAUQ-F24MS-SC12-F01-5C/R44.wav wav/2012.wav

Resources