-1

i have a folder system which has 2 level deep subfolders. Each folder has some .docx files and also other files.

What i need to do is that, i want to convert all these .docx files into .odt files and after that i want to delete these old .docx files to remove duplication.

i got bash command Linux Command to convert .docx to .odt , but for this command to run i have to go inside the folder in which .docx files exists through terminal.

so i am looking for 1 linux command or shell file script which does this automatically.

Thanks in advance.

Community
  • 1
  • 1

1 Answers1

0

If you're using zsh or bash version 5.0 or higher, this is trivial:

 #!/bin/zsh
 cd $1 && libreoffice --headless --convert-to odt **/*.docx

With any sh-like shell, you can also do it using the following pipe:

 #!/bin/sh
 find $1 -name '*.docx' -print | xargs libreoffice --headless --convert-to odt 
 cd $1 && find $1 -name '*.docx' -delete
hd1
  • 33,938
  • 5
  • 80
  • 91
  • `**/*.docx` is available in bash (version >= 4.x) too, when [`globstar`](http://unix.stackexchange.com/questions/49913/recursive-glob) option is set. – anishsane Apr 08 '15 at 07:10
  • I clearly don't use bash, will edit my answer to reflect, the pure /bin/sh that is found on most (non-Linux) Unix systems does not do globs at all. – hd1 Apr 08 '15 at 07:22
  • @hd1 thanx for your wonderful efforts. but when i execute your command it created .odt files inside respective folder and also outside the folder and it does not delete .docx files from inside the folder. (e.g my folder system is " uploads -> folder A -> .docx files " , so inside folder A there was 5 .docx files , so i execute command inside uploads folder , and in output it creates 5 .odt files inside uploads folder and 10 files inside A folder out of which 5 .odt and 5 .docx ) – Shashikant Sharma Apr 09 '15 at 04:51