473,406 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

os.link makes a copy, not a link

I'm a little bit confused. According to the sources I've looked at on the
net,
os.link('file1', 'file2')
should make a hard link from file1 to file2. But what I'm finding is that
it's actually making a copy. Am I forgetting a step or something?

Python 2.3.4 running on CentOS 4.3

Jun 9 '06 #1
5 8237
Dan M wrote:
I'm a little bit confused. According to the sources I've looked at on the
net,
os.link('file1', 'file2')
should make a hard link from file1 to file2. But what I'm finding is that
it's actually making a copy. Am I forgetting a step or something?

Python 2.3.4 running on CentOS 4.3


Are file1 and file2 on the same filesystem? Looks like os.link just
calls the OS's link system call, which, for your system, might copy the
file.

Carl Banks

Jun 10 '06 #2
Dan M <da*@catfolks.net> writes:
I'm a little bit confused. According to the sources I've looked at on the
net,
os.link('file1', 'file2')
should make a hard link from file1 to file2. But what I'm finding is that
it's actually making a copy. Am I forgetting a step or something?


Are you sure that's what it's doing? Do you know the difference
between a copy and a hard link?

$ echo "Lorem ipsum" > foo.txt
$ ln foo.txt bar.txt
$ cp foo.txt baz.txt
$ ls -l *.txt
-rw-r--r-- 2 bignose bignose 12 2006-06-10 10:16 foo.txt
-rw-r--r-- 2 bignose bignose 12 2006-06-10 10:16 bar.txt
-rw-r--r-- 1 bignose bignose 12 2006-06-10 10:17 baz.txt
$ cat foo.txt
Lorem ipsum
$ cat bar.txt
Lorem ipsum
$ cat baz.txt
Lorem ipsum

--
\ "Good judgement comes from experience. Experience comes from |
`\ bad judgement." -- Frederick P. Brooks |
_o__) |
Ben Finney

Jun 10 '06 #3
Dan M <da*@catfolks.net> wrote:
I'm a little bit confused. According to the sources I've looked at on the
net,
os.link('file1', 'file2')
should make a hard link from file1 to file2. But what I'm finding is that
it's actually making a copy. Am I forgetting a step or something?

Python 2.3.4 running on CentOS 4.3


It works here (Py 2.4.3 on Ubuntu Dapper Drake)

The way to check whether you are getting a copy or a hardlink is to
see whether the inode number is the same.

Otherwise it is impossible to tell whether you have a copy or a
hardlink.
import os
file("z", "w").write("test")
os.link("z", "z2")
os.stat("z").st_ino 1685186L os.stat("z2").st_ino 1685186L print os.popen("ls -li z z2").read()

1685186 -rw-r--r-- 2 ncw ncw 4 2006-06-10 08:31 z
1685186 -rw-r--r-- 2 ncw ncw 4 2006-06-10 08:31 z2

--
Nick Craig-Wood <ni**@craig-wood.com> -- http://www.craig-wood.com/nick
Jun 10 '06 #4
Carl Banks <in**********@aerojockey.com> wrote:
Dan M wrote:
I'm a little bit confused. According to the sources I've looked at on the
net,
os.link('file1', 'file2')
should make a hard link from file1 to file2. But what I'm finding is that
it's actually making a copy. Am I forgetting a step or something?

Python 2.3.4 running on CentOS 4.3


Are file1 and file2 on the same filesystem? Looks like os.link just
calls the OS's link system call, which, for your system, might copy the
file.


The link(2) system call on linux never does that. Eg
import os
file("z", "w").write("test")
os.link("z", "/dev/shm/z")
Traceback (most recent call last):
File "<stdin>", line 1, in ?
OSError: [Errno 18] Invalid cross-device link


--
Nick Craig-Wood <ni**@craig-wood.com> -- http://www.craig-wood.com/nick
Jun 10 '06 #5
I had good results with os.symlink on Solaris, see
http://docs.python.org/lib/os-file-dir.html
Dan M wrote:
I'm a little bit confused. According to the sources I've looked at on the
net,
os.link('file1', 'file2')
should make a hard link from file1 to file2. But what I'm finding is that
it's actually making a copy. Am I forgetting a step or something?

Python 2.3.4 running on CentOS 4.3


Jun 10 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Matt Adams | last post by:
As well known I could specify the text color in the body tag like: <BODY TEXT=WHITE LINK=WHITE VLINK=RED ALINK=WHITE> What I want to achieve now is that always (!) the text of the last visited...
4
by: EJO | last post by:
Using an MS A2K front end running on WinXP and ODBC connections to SQL Server 7 on Win 2K server; there are about 10 users who access the front end via Terminal Server and use the same front end;...
7
by: berkay | last post by:
i have a txt file; berkay#white jack#black smith#jane writes in it. and after i run the program it only prints smith jane and crashes what is wrong?
3
by: David | last post by:
Hi, We a have a small office network of 3 users. Each user has their own copy of an MS Access Front-End which is linked via their own local ODBC connection to our server's MySQL database (Linux...
4
by: Jim Richards | last post by:
Hello all. I need to post a graphic but I understand that it is not allowed in the newsgroups. I know how to upload a graphic to my website and how to compose the link that will access it there. I...
5
by: Edward Mitchell | last post by:
I am trying to include two class files into a web service project. The structure I have is a top level solution and project in a folder and below that, the web service project in it's own folder. ...
14
by: Steve McLellan | last post by:
Hi, Sorry to repost, but this is becoming aggravating, and causing me a lot of wasted time. I've got a reasonably large mixed C++ project, and after a number of builds (but not a constant...
11
by: Kurda Yon | last post by:
Hi, I got this warning: mysql_query(): 4 is not a valid MySQL-Link resource. The line which cause this warning is: mysql_query("insert into $tablename (id,priority) values('$id', '0.00')",...
36
by: pereges | last post by:
Hi, I am wondering which of the two data structures (link list or array) would be better in my situation. I have to create a list of rays for my ray tracing program. the data structure of ray...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.