Sponsored Content
Top Forums Programming Difference between cp and mv linux command Post 302424665 by dharshini123 on Wednesday 26th of May 2010 03:18:31 AM
Old 05-26-2010
MySQL Difference between cp and mv linux command

Hi,

I am facing one problem only with mv command not with cp command. I have a test program

Code:
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mount.h>
#include <fcntl.h>
#include <errno.h>

int sync_file(char *file)
{
FILE *fp=NULL;
int fd;

printf("file is %s\n",file);
fp = fopen(file, "r");
if(!fp)
return -1;

fd = fileno(fp);
fflush(fp);
fsync(fd);
ioctl (fd, BLKFLSBUF, 0);
fclose(fp);
return 0;

}

int main()
{
int len=0;
FILE *fp = NULL;
char buf[1024];
char *fname = "/etc/test.conf";
char fname_tmp[129] = "";


len = sprintf(buf, "%s\n", "Newly added Line is there");

snprintf(fname_tmp, 128, "%s.tmp", fname);

if( (fp = fopen(fname_tmp,"a")) == NULL )
printf(" ERROR: open(), error - %s\n",strerror(errno));

fprintf(fp,"%s",buf);
fflush(fp);

fsync(fileno(fp));
fclose(fp);
system("cp -f /etc/test.conf.tmp /etc/test.conf");
// system("mv -f /etc/test.conf.tmp /etc/test.conf");
sync_file(fname);
return 0;
}

Here i am opening a tmp file for writing. Then i am copying/moving for original file. Then i do a fflush, fsync(), ioctl() to the original file. Then i run this binary in linux machine(ext2 file system, 2.6.23.5 kernel) after that immediately power off the machine. Then power on machine, the file is disappeared or written data lost or file gets corrupted if i move the tmp file to the original file. And there is a no problem if i copy the tmp file to original file. So i want to know the difference between the cp and mv command. Can you please give me suggestion on it?

Thanks,
Indira

Moderator's Comments:
Mod Comment Moved post to its own thread - please no "threadjacking"; removed colour formatting; added code tags
 

9 More Discussions You Might Find Interesting

1. Programming

Difference in LINUX and SOLARIS

/* * one-way-pipe.c - example of using a pipe to communicate data between a * process and its child process. The parent reads input * from the user, and sends it to the child via a pipe. * The child prints the received data to the... (1 Reply)
Discussion started by: SQ4LIFE
1 Replies

2. UNIX for Dummies Questions & Answers

Difference between UNIX and Linux

OK, I've used various versions of UNIX(Solaris, HPUX, etc..) over the years. Now the organization I work for is leaning towards more Linux based systems(Redhat, Suse, etc..) I do see differences in in comands and how to accomplish basic adminstration, but nothing mind blowing. So, what is it... (5 Replies)
Discussion started by: pbonilla
5 Replies

3. UNIX for Dummies Questions & Answers

su command difference between unix and linux

Hello all the su with -l option is running normal with linux but when i try to run it on unix AIX 5.2.7 it's not working with -l option any help (6 Replies)
Discussion started by: islam.said
6 Replies

4. UNIX for Dummies Questions & Answers

difference between unix and linux

Hi I am new to linux I have dout waht is the difference between UNIX and LINUX Is there any soft for insatallation for UNIX OS Thanks (0 Replies)
Discussion started by: sanjaya
0 Replies

5. Linux

Difference between Windows and Linux

Hi, What is the difference between Linux and Windows? Thanks. (1 Reply)
Discussion started by: billcrosby
1 Replies

6. Linux

What is the difference between Linux and Windows?

Hi, What is the difference between Linux and Windows? Thanks. (5 Replies)
Discussion started by: billcrosby
5 Replies

7. UNIX for Dummies Questions & Answers

Difference between UNIX and Linux

hi experts please tell me the real difference between unix and linux at kernel structure (1 Reply)
Discussion started by: linurag
1 Replies

8. Red Hat

Difference Redhat Linux/RH Enterprise Linux

what is the difference between Redhat Linux and Redhat Enterprise Linux. whereas Redhat linux have Server installation options too. (2 Replies)
Discussion started by: hananabbas
2 Replies

9. UNIX for Dummies Questions & Answers

AIX to Linux command difference

Moving from AIX 6.1 to RHEL 6.6, I have noticed a few command differences. One that has been causing issue is a simple echo command when I have to use it this way -> "echo -e" On the AIX it outputs to "-e" but since RHEL has "-e" as an option for echo and hence it outputs to blank here. All... (3 Replies)
Discussion started by: aster007
3 Replies
ppmtosixel(1)						      General Commands Manual						     ppmtosixel(1)

NAME
ppmtosixel - convert a portable pixmap into DEC sixel format SYNOPSIS
ppmtosixel [-raw] [-margin] [ppmfile] DESCRIPTION
Reads a portable pixmap as input. Produces sixel commands (SIX) as output. The output is formatted for color printing, e.g. for a DEC LJ250 color inkjet printer. If RGB values from the PPM file do not have maxval=100, the RGB values are rescaled. A printer control header and a color assignment table begin the SIX file. Image data is written in a compressed format by default. A printer control footer ends the image file. OPTIONS
-raw If specified, each pixel will be explicitly described in the image file. If -raw is not specified, output will default to com- pressed format in which identical adjacent pixels are replaced by "repeat pixel" commands. A raw file is often an order of magni- tude larger than a compressed file and prints much slower. -margin If -margin is not specified, the image will be start at the left margin (of the window, paper, or whatever). If -margin is speci- fied, a 1.5 inch left margin will offset the image. PRINTING
Generally, sixel files must reach the printer unfiltered. Use the lpr -x option or cat filename > /dev/tty0?. BUGS
Upon rescaling, truncation of the least significant bits of RGB values may result in poor color conversion. If the original PPM maxval was greater than 100, rescaling also reduces the image depth. While the actual RGB values from the ppm file are more or less retained, the color palette of the LJ250 may not match the colors on your screen. This seems to be a printer limitation. SEE ALSO
ppm(5) AUTHOR
Copyright (C) 1991 by Rick Vinci. 26 April 1991 ppmtosixel(1)
All times are GMT -4. The time now is 09:56 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy