Do mv and cp commands lock files in different ways


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Do mv and cp commands lock files in different ways
# 1  
Old 05-14-2010
Do mv and cp commands lock files in different ways

We have two processes, one which copies a control file into a folder and another which is polling this folder and reading the control files.

Sometimes they clash and the reader fails because the copy is still happening.

We have been told that we should change the copy to a move because the move command will lock the file in a "different" way so that clash won't happen. I have so far found no evidence that this is true.

Can anyone tell me if changing to a move will really fix the issue.

Thanks,
S
# 2  
Old 05-14-2010
cp and mv do not lock files.
It is a recognised technique to copy a file to a temporary filename then to rename the file (with mv) to the final name. A process looking for the file under its final name will only see the file when the copy is complete.
For this technique to work the temporary filename and the final filename must be in the same filesystem such that the "mv" just changes the inode rather than copying the file.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Unable to obtain lock on NFS files

Hello , I am creating a controlfile of database in linux and below is the error coming: SQL> CREATE CONTROLFILE REUSE set DATABASE "newdbcln" RESETLOGS NOARCHIVELOG 2 MAXLOGFILES 5 3 MAXLOGMEMBERS 5 MAXDATAFILES 100 4 5 MAXINSTANCES 1 6 MAXLOGHISTORY... (2 Replies)
Discussion started by: admin_db
2 Replies

2. Shell Programming and Scripting

Find files and execute commands on these files (advanced)

So, I need to find a bunch of files and delete them (this example, but sometimes I need it for something else) and my trusty go-to command has always been: find . -type f -name '*file*' | xargs -I## rm '##' Works wonders... But: touch file\ file\'.txt touch file.txt touch file\ file.txt... (6 Replies)
Discussion started by: Mr.Glaurung
6 Replies

3. Shell Programming and Scripting

Where are lock and unlock commands?

I'm running cygwin bash on Windows 8.1. I would like to to write a OS neutral bash script that uses the commands like lock, block and unlock. Do I need to write lock, block and unlock myself in C++? I'm hoping someone has already written them. My bash script would look something like this:... (2 Replies)
Discussion started by: siegfried
2 Replies

4. Shell Programming and Scripting

lock on files

Hi, I want to write a code where in the file once taken genrates a lock number and other developer/user cannot take the file to make any changes in it. He gets the file only as read only. (2 Replies)
Discussion started by: rac
2 Replies

5. Homework & Coursework Questions

What are different ways of executing shell commands?

I am a student in BCIT in vancouver and taking comp2771 course.(Shell scripting). I would like to know what are different ways of executing shell commands? Thanks (1 Reply)
Discussion started by: adam25ca
1 Replies

6. UNIX for Advanced & Expert Users

Testing privileges -lock lockfile /var/lock/subsys/..- Permission denied

Hi all, I have to test some user priviliges. The goal is to be sure that an unauthorized user can't restart some modules (ssh, mysql etc...). I'm trying to automate it with a shell script but in same cases I got the syslog broadcast message. Is there any way to simply get a return code... (3 Replies)
Discussion started by: Dedalus
3 Replies

7. Red Hat

Security Question: Lock after invalid login, Session Lock and Required Minimum Password Length

Hello all, If anyone has time, I have a few questions: How do I do the following in Linux. We are using Red Hat and Oracle Enterprise Linux, which is based on Red Hat too. 1. How to lock the account after a few (like 3) invalid password attempts? 2. How do you lock a screen after 30... (1 Reply)
Discussion started by: nstarz
1 Replies

8. UNIX for Dummies Questions & Answers

Files still being created in /var/spool/mmdf/lock/home

Hi all I need help finding a process that is continuing to create files in the above area. There are three sub folder titled addr q.local and msg . I have already found a process called mmdf running and have used the kill command to stop this from running. I have also looked for sendmail or... (12 Replies)
Discussion started by: TeaMaker
12 Replies

9. UNIX for Dummies Questions & Answers

Ways to Access Files on Unix Server via Web

Hi all! I'm a web developer with a question. We have a contractor that is working on a project that requires the user to access a ton of files on the clients Unix server. He has plans to built a VB interface for on site windows users to access those files and wants us to develop a web based... (4 Replies)
Discussion started by: Imhotep1963
4 Replies

10. UNIX for Dummies Questions & Answers

how to lock keyboard without using lock command

how can I lock my keyboard while I'm away from the computer without using lock command. What other commands gives me the option to lock keyboard device? thanks (7 Replies)
Discussion started by: dianayun
7 Replies
Login or Register to Ask a Question