in all subfolders and folders of the current directtory convert pdfs to txts filesin…
- User
in all subfolders and folders of the current directtory convert pdfs to txts filesin ubuntu
- Assistant
To convert all PDF files in the current directory and its subdirectories to text (
.txt) files on Ubuntu, you can use thepdftotextutility, which is part of thepoppler-utilspackage. Below are the step-by-step instructions to achieve this:1. Install
pdftotextFirst, ensure that
pdftotextis installed on your system. Open your terminal and run:bashsudo apt update sudo apt install poppler-utils2. Navigate to the Target Directory
Change to the directory where you want to start the PDF to TXT conversion. For example, if your PDFs are in
~/Documents, execute:bashcd ~/Documents3. Use the
findCommand to Convert PDFs RecursivelyExecute the following command to find all PDF files in the current directory and its subdirectories and convert them to TXT files:
bashfind . -type f -iname "*.pdf" -exec pdftotext "{}" \;Explanation of the Command:
find .: Starts searching in the current directory (.) and all its subdirectories.-type f: Looks for files only.-iname "*.pdf": Searches for files with the.pdfextension, case-insensitive (.PDF,.Pdf, etc.).-exec pdftotext "{}" \;: For each found PDF file, executes thepdftotextcommand to convert it to a.txtfile. The{}is a placeholder for the current file, and\;signifies the end of the-execcommand.
Note: This command will create a
.txtfile with the same base name as the original PDF in the same directory. For example,document.pdfwill becomedocument.txt.4. Handling Filenames with Spaces
If your PDF filenames contain spaces or special characters, the above command will handle them correctly because of the quotes around
"{}".5. Optional: Verifying the Conversion
After the conversion process completes, you can verify that the
.txtfiles have been created by listing them: