LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-14-2008, 02:29 PM   #1
franciscodiaztrepat
LQ Newbie
 
Registered: Apr 2008
Posts: 3

Rep: Reputation: 0
How to check whether a file or directory is good to remane


Hi, newbie here.

I want to rename a directory myproject to myprojecttmp through an mv command. This usually will rename without move or copy being done.
But if I have a file or folder opened inside myproject folder then a cp is performed instead and my bash script takes a long time pluss i have two dirs.

Could some one help me out?

I need a way to test that a rename cannot be performed to be able to output a message saying "Hey you, please close all files before running this script!!!!"

and not mess up things.

Am I in the right track here should I test it other way?

thanks in advance,
f(t)
 
Old 04-14-2008, 02:42 PM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 356Reputation: 356Reputation: 356Reputation: 356
From the mv man page:
Code:
-t, --target-directory=DIRECTORY
              move all SOURCE arguments into DIRECTORY
Have you tried mv with the '-t myprojecttmp' option?
 
Old 04-14-2008, 03:00 PM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
I don't quite understand the problem here. Anyway, to check if directory or a file is in use, you can try the command lsof:
Code:
$ cd $HOME/test
$ lsof $HOME/test
COMMAND   PID    USER   FD   TYPE DEVICE SIZE    NODE NAME
bash    12356 colucix  cwd    DIR    8,8 4096 2342973 /home/colucix/test
lsof    20986 colucix  cwd    DIR    8,8 4096 2342973 /home/colucix/test
lsof    20987 colucix  cwd    DIR    8,8 4096 2342973 /home/colucix/test
$ cd
$ lsof $HOME/test
$
See man lsof for details and for some useful option to parse the lsof output inside your scripts.
 
Old 04-14-2008, 03:03 PM   #4
franciscodiaztrepat
LQ Newbie
 
Registered: Apr 2008
Posts: 3

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by bigrigdriver View Post
From the mv man page:
Code:
-t, --target-directory=DIRECTORY
              move all SOURCE arguments into DIRECTORY
Have you tried mv with the '-t myprojecttmp' option?
Sorry http://www.gnu.org/software/coreutil...directory.html

I cannot see how could this help. AFAIK.

f(t)
 
Old 04-14-2008, 03:09 PM   #5
franciscodiaztrepat
LQ Newbie
 
Registered: Apr 2008
Posts: 3

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by colucix View Post
I don't quite understand the problem here. Anyway, to check if directory or a file is in use, you can try the command lsof:
Code:
$ cd $HOME/test
$ lsof $HOME/test
COMMAND   PID    USER   FD   TYPE DEVICE SIZE    NODE NAME
bash    12356 colucix  cwd    DIR    8,8 4096 2342973 /home/colucix/test
lsof    20986 colucix  cwd    DIR    8,8 4096 2342973 /home/colucix/test
lsof    20987 colucix  cwd    DIR    8,8 4096 2342973 /home/colucix/test
$ cd
$ lsof $HOME/test
$
See man lsof for details and for some useful option to parse the lsof output inside your scripts.
Ok this seams more likely. I'll see if this could help be out with some pipeping.

The problem is that it does not rename a directory if an inside file/folder is open. It also does not throw an error. Instead it performs a copy (cp), by that taking too much time.

f(t)
 
  


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
How to write crontab to check file size and all file in a directory? modpriest Linux - Newbie 1 02-14-2008 06:48 AM
Lilo installation? part_nowrite check::No such file or directory phyx Linux - Newbie 1 02-14-2006 11:26 AM
Lilo installation? part_nowrite check::No such file or directory phyx Linux - General 0 02-14-2006 10:49 AM
part_nowrite check:: No such file or directory darkarcon2015 Linux - Software 2 02-12-2006 02:32 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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