LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 02-15-2013, 09:46 PM   #1
jorx
LQ Newbie
 
Registered: Apr 2009
Posts: 7

Rep: Reputation: 0
can't overwrite a file because it's being used?


Hi everyone,
I'm installing a license server for our server, but it's a bit of a tricky affair. The instructions indicate that I should modify a text file, but I can't, because the file is still in use!

How would you troubleshoot what programs or services are still accessing the files, and how would you stop them?
cheers,
Jorx

** SOLVED **
by using this command which killed processes with this file open

fuser folder/myfile.ext -k

Last edited by jorx; 02-17-2013 at 10:05 PM. Reason: solved
 
Old 02-15-2013, 09:53 PM   #2
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 16,778
Blog Entries: 27

Rep: Reputation: 5091Reputation: 5091Reputation: 5091Reputation: 5091Reputation: 5091Reputation: 5091Reputation: 5091Reputation: 5091Reputation: 5091Reputation: 5091Reputation: 5091
I think one of these links might help. I think the second one is a better candidate.

http://www.cyberciti.biz/faq/howto-l...of-open-files/

http://superuser.com/questions/97844...-open-in-linux

Last edited by frankbell; 02-15-2013 at 09:58 PM.
 
Old 02-15-2013, 10:11 PM   #3
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 9,078
Blog Entries: 4

Rep: Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182
Programs often open files in such a way that certain operations are prohibited ... specifically including: "I don't care who else wants to read this at the same time I do, but I do not want anyone to be able to write to it while I'm reading it." If a program has done that, as a great many of them do, then you have to shut down the other program(s).
 
Old 02-17-2013, 09:57 PM   #4
jorx
LQ Newbie
 
Registered: Apr 2009
Posts: 7

Original Poster
Rep: Reputation: 0
frankbell, Thanks for the links! They don't help in this scenario- the second link is how to figure out what files are open by process X, but I need to know what process is locking this file!

sundialsvcs, that's exactly my problem, because I don't know what process is locking this file.

I need to edit this file, it's locked. Surely there must be a way to hack this?

I once touched Red Hat over a decade ago... I remember linux had different stages/levels of activity, with Xwindows being the highest.

Is there a way I could boot or shut everything down so only the terminal and minimal processes are running? Then I could run cp /path/to/file and use the terminal that way. If I could somehow shutdown all non essential processes?
 
Old 02-17-2013, 10:04 PM   #5
jorx
LQ Newbie
 
Registered: Apr 2009
Posts: 7

Original Poster
Rep: Reputation: 0
Solved!

It turns out "fuser" was the answer, and it was quite simple. After looking up fuser examples, here's what I did.


# fuser file.ext
returned 1363e. 1363 was the PID and "e" indicated it was executable.

# fuser file.ext -k -v

-v means verbose. I ran -k for "Kill all processes with this file open".

That did the trick. Now I was able to overwrite the file.
Sweet!
thanks heaps for pointing me in the right direction.
 
Old 02-17-2013, 10:52 PM   #6
jorx
LQ Newbie
 
Registered: Apr 2009
Posts: 7

Original Poster
Rep: Reputation: 0
Well, SORT of solved. Now I can't start the process which is supposed to be using that file. It's a permissions thing. I did use super user to overwrite the fie, and now the service is complaining. Eek! time to figure out how this works...

Solved: I found that my file has improper permissions with
ls -al

and was able to add them back in with chmod.

As always.. if one wants to use Linux, one has to use the terminal alot!

Last edited by jorx; 02-17-2013 at 11:44 PM. Reason: solved
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
to overwrite a file in root sajjadpu Linux - Newbie 10 05-06-2012 11:28 PM
File Overwrite Recovery Fracker Linux - Newbie 7 03-15-2011 08:47 PM
How do you overwrite the contents of a file without changing the file size? lothario Linux - Software 3 07-13-2010 09:43 AM
using sed to insert line into file and overwrite the current file jadeddog Programming 3 06-11-2009 08:14 PM
how to overwrite a particular line of a file kkpal Linux - Newbie 1 05-16-2008 03:35 AM

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

All times are GMT -5. The time now is 04:20 PM.

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