LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 10-08-2008, 04:54 AM   #1
venkat_k
Member
 
Registered: Sep 2008
Posts: 36

Rep: Reputation: 15
Temporary files creation in Linux


Can any one of you tell me, what are all the temporary files created during the modification of a file in Linux?

My issue is, i am using "inotify" for figuring out the deletion/modification of a specific file (say test.txt). I am observing quite a few temporary files when i am editing test.txt.

Here are the temporary files i have observed.
.test.txt.swx
.test.txt.swp
test.txt~
4913

I am not sure what is that file 4913?
Please tell me what are all the temporary files created when we try to edit any file in Linux?
 
Old 10-08-2008, 05:15 AM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 678Reputation: 678Reputation: 678Reputation: 678Reputation: 678Reputation: 678
The 4913 is probably the pid of the program editing the file. Look at the contents of the file. If may have to do with advisory locking.

You can run "lsof <filename> <filename2> ..." to get information on the processes and users who have a file open. The .swp is a temporary swap file created by the editor. This allows the program to edit a program without having all of it in memory. The ~ is a backup of the file before editing. I don't know about the .swx file, but it may be a different type of a swap file. Maybe it is a memory mapped file that can be processes as if it were memory.
 
Old 10-08-2008, 05:35 AM   #3
venkat_k
Member
 
Registered: Sep 2008
Posts: 36

Original Poster
Rep: Reputation: 15
No. 4913 - It's not the pid of the file. I have checked for that. I am getting this only when i edited the file through vi editor. I tried with emacs, it is not creating this file.
This file is specially getting created & deleted when i am saving the file. I tried with multiple files, but the created file name(4913) is same for all those.

I am unable to figure out the contents/file type of the file as it is getting deleted by the time my program figures it out.

Is there any generic way that i can detect the temporary file in Linux?
 
Old 10-08-2008, 06:04 AM   #4
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Tribblix, Ubuntu/WSL
Posts: 9,775

Rep: Reputation: 469Reputation: 469Reputation: 469Reputation: 469Reputation: 469
Files have no pid, processes do.

It is to be expected vi and emacs behaving differently, they do it by design ...

If you want to track file creation, you can use the strace command and filter the appropriate calls.
 
Old 10-08-2008, 06:17 AM   #5
venkat_k
Member
 
Registered: Sep 2008
Posts: 36

Original Poster
Rep: Reputation: 15
Hi jlliagre,

Thanks for the reply.
Yeah. Files have no pid, processes do. That was typo error in my previous post.

Here is the part of strace output.
==========================================================================
write(1, "\"file10.txt\" ", 13) = 13
stat64("file10.txt", {st_mode=S_IFREG|0664, st_size=1206, ...}) = 0
access("file10.txt", W_OK) = 0
getxattr("file10.txt", "system.posix_acl_access", 0xbfcfbef0, 132) = -1 ENODATA (No data available)
stat64("file10.txt", {st_mode=S_IFREG|0664, st_size=1206, ...}) = 0
lstat64("file10.txt", {st_mode=S_IFREG|0664, st_size=1206, ...}) = 0
lstat64("4913", 0xbfcfc1ac) = -1 ENOENT (No such file or directory)
open("4913", O_WRONLY|O_CREAT|O_EXCL|O_LARGEFILE|O_NOFOLLOW, 0100664) = 3
fchown32(3, 508, 508) = 0
stat64("4913", {st_mode=S_IFREG|0664, st_size=0, ...}) = 0
close(3) = 0
unlink("4913") = 0
stat64("file10.txt~", {st_mode=S_IFREG|0664, st_size=243, ...}) = 0
stat64("file10.txz~", 0xbfcfbfc8) = -1 ENOENT (No such file or directory)
stat64("file10.txt", {st_mode=S_IFREG|0664, st_size=1206, ...}) = 0
==========================================================================

Please tell me if some thing can be traced out from this.
 
Old 10-08-2008, 08:54 AM   #6
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Tribblix, Ubuntu/WSL
Posts: 9,775

Rep: Reputation: 469Reputation: 469Reputation: 469Reputation: 469Reputation: 469
That 4913 file is a vim "feature". It checks if it can create a file and use a hard-coded "random name" equal to 4913. Note that there is no risk in the process as if the file exists, it tries 4914 and so on.

Look at line 3337 and next ones in this page (vim source code):
http://src.opensolaris.org/source/xr...1/src/fileio.c

This is quite weak programming though. Using a hidden file (.xxx) with a more random name would have be more professional in my opinion.
 
Old 10-13-2008, 12:49 AM   #7
venkat_k
Member
 
Registered: Sep 2008
Posts: 36

Original Poster
Rep: Reputation: 15
Hi jlliagre,

Thanks for the reply. It is really helpful. Finally i am out of panic.
 
Old 10-15-2008, 02:43 AM   #8
reddazz
LQ Guru
 
Registered: Nov 2003
Location: N. E. England
Distribution: Fedora, CentOS, Debian
Posts: 16,298

Rep: Reputation: 75
Moved: This thread is more suitable in Linux General and has been moved accordingly to help your thread/question get the exposure it deserves.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Temporary files. STARHARVEST Slackware 11 03-01-2008 04:46 PM
Temporary internet files in Linux? agentchange SUSE / openSUSE 2 08-05-2006 09:52 PM
temporary internet files in linux gsr_kashyap Linux - Networking 1 08-04-2004 07:36 AM
crontab & quota files are temporary files? hamish Linux - Software 0 07-10-2004 02:09 PM
creation Temporary files with ~ sign?? kushalkoolwal Linux - Newbie 1 03-10-2004 01:21 PM

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

All times are GMT -5. The time now is 09:37 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration