LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-25-2024, 08:20 PM   #1
coal-fired-linux
LQ Newbie
 
Registered: Apr 2024
Posts: 1

Rep: Reputation: 0
How To Recover TXT File that Will Not Open or Copy, Input/Output Error


Hello.

I have a few TXT files which no longer open. This problem has occurred from time to time on one TXT file while the other TXT files that I had been using still work. Perhaps there was an error when saving but I am not sure. Perhaps there is a problem finding or recognizing EOF or some similar issue.

I tried the "cp" command and one file copied the beginning of the file (many lines) but not the rest, while another file did not copy at all.

I have seen references to using "dd" but I have not seen any explanation of how to locate the file's physical location, so that I might do some kind of quick copy.

The TXT files might be large for a TXT file, sometimes maybe more than 1MB, but tiny compared to a multi-GB storage drive.

My past experience includes using the command line, using a hex editor, and compiling programs--but I am rusty.

Thank you.

Last edited by coal-fired-linux; 04-25-2024 at 08:22 PM.
 
Old 04-25-2024, 08:43 PM   #2
RandomTroll
Senior Member
 
Registered: Mar 2010
Distribution: Slackware
Posts: 1,970

Rep: Reputation: 271Reputation: 271Reputation: 271
What happens if you run:
Code:
cat file.txt > newfile.txt
(assuming newfile.txt is not already a file)

Have you tried repairing the disk with fsck?

dd works on files. Have you tried
Code:
dd if=file.txt of=newfile.txt
?
 
Old 04-25-2024, 09:44 PM   #3
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,993

Rep: Reputation: 3628Reputation: 3628Reputation: 3628Reputation: 3628Reputation: 3628Reputation: 3628Reputation: 3628Reputation: 3628Reputation: 3628Reputation: 3628Reputation: 3628
Try a binary editor? (hex)

Command line I think might work to see if the file is correct format. https://linux.die.net/man/1/file

Could be some botched locations or some file that needs to be checked.
 
Old 04-26-2024, 02:29 AM   #4
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,131

Rep: Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121
So you have a history of broken files, but it wasn't worth your time to create backups. But it's worth faffing around trying to recover them.
Interesting attitude.

What do the log files say ?. Are these files on removable media (USB say) ?.
 
Old 04-26-2024, 01:59 PM   #5
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,141
Blog Entries: 6

Rep: Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828
Example:
Code:
#!/usr/bin/bash

read -p "Enter/Paste file for hex view: " hv

od -A x -t x1z -v "$hv" | less
 
1 members found this post helpful.
Old 04-27-2024, 02:02 PM   #6
RandomTroll
Senior Member
 
Registered: Mar 2010
Distribution: Slackware
Posts: 1,970

Rep: Reputation: 271Reputation: 271Reputation: 271
Quote:
Originally Posted by syg00 View Post
So you have a history of broken files, but it wasn't worth your time to create backups.
I had a file that I rarely consulted so that when it got corrupted the corrupted version propagated through all my backups.

If this is a text file, corruption may be non-text. 'strings' will extract text from mixed.
 
Old 04-27-2024, 02:40 PM   #7
jmccue
Member
 
Registered: Nov 2008
Location: US
Distribution: slackware
Posts: 693
Blog Entries: 1

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
What does this show ?

Code:
ls -l FILENAME
maybe you lack read access, see man(1) ls and man chmod(1)
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
cat file.txt > file.txt (resulted in blank file) axolinx Linux - Newbie 4 11-04-2022 07:20 PM
[SOLVED] input txt into some txt boxes siickboii Linux - Newbie 3 10-10-2012 05:28 PM
Copy the contents of a txt file to other txt files (with similar names) by cp command Aquarius_Girl Linux - Newbie 7 07-03-2010 12:54 AM
cat onelinefile.txt >> newfile.txt; cat twofile.txt >> newfile.txt keep newline? tmcguinness Programming 4 02-12-2009 06:38 AM
How can read from file.txt C++ where can save this file(file.txt) to start reading sam_22 Programming 1 01-11-2007 05:11 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:02 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration