LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 01-15-2007, 06:46 AM   #1
wweiy
LQ Newbie
 
Registered: Nov 2006
Posts: 7

Rep: Reputation: 0
how to remove a busy file?


hi all,

when i type ls -la, it shows the files for current directory:
drwxr-x--- 2 wooi4 eng 4096 2007-01-15 20:35 .
drwxr-x--- 3 wooi4 eng 4096 2007-01-15 19:07 ..
-rwxrwxrwx 1 wooi4 eng 39359193 2007-01-11 15:02 .nfs0173b13600000024

when i want to delete the file,i type "rm .nfs0173b13600000024" (or with an option), it shows the following error message:
rm: cannot remove `.nfs0173b13600000024': Device or resource busy

how can i remove the file ".nfs0173b13600000024"?

thanks for any help
 
Old 01-15-2007, 06:51 AM   #2
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 270Reputation: 270Reputation: 270
Find out what application is using it with lsof and kill the process accessing it.
 
Old 01-15-2007, 08:07 PM   #3
mblames
Member
 
Registered: Apr 2006
Location: Place for all OpenSource
Distribution: OpenBSD 4.1, FC5
Posts: 50

Rep: Reputation: 15
#lsof |grep -i <any_file>
to find out the process
#kill -9 <pid>
to terminate the program
 
Old 01-15-2007, 09:29 PM   #4
wweiy
LQ Newbie
 
Registered: Nov 2006
Posts: 7

Original Poster
Rep: Reputation: 0
thanks a lot, it really solved my problem..
 
Old 07-20-2018, 07:08 AM   #5
ggevorg
LQ Newbie
 
Registered: Jul 2018
Posts: 1

Rep: Reputation: Disabled
Remove busy file

Hi folks
For removed all busy files I have write Bash script
Code:
# #!/usr/local/bin/bash
clear

echo "#################################"
echo "##########START SCRIPT###########"
echo "#################################"

cd
nfs_file_path=()

while IFS=  read -r -d $'\0'; do
    nfs_file_path+=("$REPLY")
done < <(find . -name ".nfs*" -print0)
for line in "${nfs_file_path[@]}"; do
  nfs_id=()
#   echo "$line"
  nfs_ip="$(lsof | grep -i "$line")"
  IFS="      " read -r -a nfs_id <<< $nfs_ip
  echo "${nfs_id[1]}"
  kill_result="$(kill -9 ${nfs_id[1]})"
  if [$kill_result != ""]
  then
      (rm -rf $line)
  fi
done


echo "#################################"
echo "###########END SCRIPT############"
echo "#################################"

Last edited by onebuck; 07-20-2018 at 08:23 AM. Reason: clean up post, please use code tags, do not resurrect necro threads
 
Old 07-22-2018, 02:21 AM   #6
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,819

Rep: Reputation: 1211Reputation: 1211Reputation: 1211Reputation: 1211Reputation: 1211Reputation: 1211Reputation: 1211Reputation: 1211Reputation: 1211
Traditional shells do not have arrays because
THERE IS HARDLY NO GOOD USE OF ARRAYS IN SHELLS.
Code:
while IFS=  read -r -d $'\0'; do
    nfs_file_path+=("$REPLY")
done < <(find . -name ".nfs*" -print0)
for line in "${nfs_file_path[@]}"; do
    ...
done
Can be simplified
Code:
while IFS=  read -r -d $'\0' line; do
    ...
done < <(find . -name ".nfs*" -print0)
Further, an fgrep (or grep -F) is more precise, because the dot is a literal dot, not a wildcard.
Code:
    nfs_ip=$(lsof | fgrep "$line")
Finally, consider the following "oldie":
Code:
    fuser -k "$line"
    sleep 1
    rm -f "$line"

Last edited by MadeInGermany; 07-22-2018 at 02:23 AM.
 
Old 01-29-2024, 09:05 PM   #7
indukriti
LQ Newbie
 
Registered: Jan 2024
Posts: 1

Rep: Reputation: 0
Lightbulb For deleting busy file how to know PID to kill the process

How can i get the PID info to delete the file/dir
have checked busy file using this

lsof | grep -i <filename>

dgcom_exe 32164 32296 username 1025uw REG 0,85 200 1534107745 dirpath/filename/.nfs000000005b70a06100000962 (website name:/TCASE)

let me know which one is pid here
to kill process using
kill -9 pid

thanks in advance
 
Old 01-30-2024, 09:01 AM   #8
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,246

Rep: Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323
The “fuser” command also works, if you don’t like lsof.
 
Old 01-30-2024, 02:29 PM   #9
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,998

Rep: Reputation: 7338Reputation: 7338Reputation: 7338Reputation: 7338Reputation: 7338Reputation: 7338Reputation: 7338Reputation: 7338Reputation: 7338Reputation: 7338Reputation: 7338
the suggestion is not really good (post #3), but anyway you can use fuser to find which pid is currently using the given file. You can decide if you really want to exit that app (not kill) or use it.
.nfs stands for remote access, so you may need to consider that as well.
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
scp text file busy error seran Linux - General 4 08-12-2021 03:36 PM
LXer: This week at LWN: Busy busy busybox LXer Syndicated Linux News 1 10-05-2006 08:09 PM
Backup/file busy question Yig Linux - General 2 01-23-2006 10:22 AM
/etc/rc.sysinit: /bin/awk: Text file busy teeno Linux - Software 5 02-23-2005 02:19 AM
which process uses a busy file/directory dwof Linux - Software 8 08-13-2003 05:59 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 02:51 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