Sponsored Content
Top Forums Shell Programming and Scripting Compare file size and then copy/overwrite Post 302968027 by RudiC on Wednesday 2nd of March 2016 05:03:51 PM
Old 03-02-2016
It won't be the latest but the largest file.

Do you NEED to run that with sh? Does your system have the stat (or equivalent) command?

---------- Post updated at 22:58 ---------- Previous update was at 22:49 ----------

With bash and stat:
Code:
 (( ($(stat -c"%s-" "$f" /P2/backup/"$f") 0)  > 0 )) && cp "$f" /P2/backup/

---------- Post updated at 23:03 ---------- Previous update was at 22:58 ----------

No bash required:
Code:
expr $(stat -c"%s >" "$f") $(stat -c"%s" /P2/backup/"$f") && cp "$f" /P2/backup/

These 3 Users Gave Thanks to RudiC For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to compare file size after ftp?

Is possible if I want to campare file size on source and destination after ftp transfer? If anybody know, please explain to me. (1 Reply)
Discussion started by: icemania
1 Replies

2. Shell Programming and Scripting

compare file size from a output file from a script

Hi guys, firstly I'm working on SunOS 5.10 Generic_125100-10 sun4u sparc SUNW,Sun-Fire-V240 I've made a script to compress two directory and then send them to an other server via ftp. This is working very well. Inside theis script I decide to log usefull data for troubleshooting in case of... (7 Replies)
Discussion started by: moustik
7 Replies

3. Shell Programming and Scripting

How to compare size of two file which is in one directory

I have two file in a Directory.I want a script which will compare the Size of Two file. Can Anyone Help me on this: linasplg11:/opt/dataout/kk/linasplg11 # cat size -rwxrwxrwx 1 root root 16658 Jan 8 13:58 lina_IP_SIP_1231325621210.xml -rwxr-xr-x 1 root root 16672 Jan 8 14:30... (1 Reply)
Discussion started by: Aditya.Gurgaon
1 Replies

4. UNIX for Dummies Questions & Answers

Copy a file based on the size-Urgent

Hi, I need unix code to check the size of a file. for example if the size of the file in A folder is more than 1BM, then i have to move that particular file in to B folder whenever I run that particular script. regards, Srinivas. (7 Replies)
Discussion started by: vysrinivas
7 Replies

5. UNIX for Dummies Questions & Answers

PSFTP- Compare file size

Hi, I'm using PSFTP to transfer files from one machine to a virtual machine with UBUNTU OS installed on it. I'm trying to find a way to make sure the files that I'm uploading / downloading are being uploaded/ downloaded properly. I want to compare the size of the local file and the remote... (0 Replies)
Discussion started by: sessie
0 Replies

6. Shell Programming and Scripting

Script to Compare file size and delete the smaller

I am pretty new to scripting, so I appreciate your advice in advance. The problem: 100 directories each containing 2 files that have the same extension with random names. The only attribute that discriminates the files is size. I would like to write a script that compares the files for size... (6 Replies)
Discussion started by: JC_1
6 Replies

7. Shell Programming and Scripting

overwrite only if both files are the same size

Dear users, I've been looking for a way to overwrite files only if both have the same size, how could I do this? any help is very appreciated. Best regards, Gery (5 Replies)
Discussion started by: Gery
5 Replies

8. Shell Programming and Scripting

Compare two files, then overwrite first file with only that in both files

I want to compare two files, and search for items that are in both. Then override the first file with that containing only elements which were in both files. I imagine something with diff, but not sure. File 1 One Two Three Four Five File 2 One Three Four Six Eight (2 Replies)
Discussion started by: castrojc
2 Replies

9. Shell Programming and Scripting

Script to overwrite & before that keep copy a file on many servers

I have ssh password less auth enable & script does the job well as well #/bin/bash for i in `cat ip` do scp /etc/resolv.conf root@$ip done But I need to take backup of the file i will overwrite .. is there any simple way ? Kindly respond (5 Replies)
Discussion started by: heman96
5 Replies

10. Shell Programming and Scripting

Compare file dates before copy

Sometimes when I boot, my system goes into emergency mode. I then use Clonezilla to restore an image. Usually the image is older than the current date. This is part of a backup script that runs as a startup program. cd /home/andy/bin/ zip -u -q Ubuntu_Scripts.zip *.sh *.rb *.c *.py... (22 Replies)
Discussion started by: drew77
22 Replies
explain_setenv(3)					     Library Functions Manual						 explain_setenv(3)

NAME
explain_setenv - explain setenv(3) errors SYNOPSIS
#include <libexplain/setenv.h> const char *explain_setenv(const char *name, const char *value, int overwrite); const char *explain_errno_setenv(int errnum, const char *name, const char *value, int overwrite); void explain_message_setenv(char *message, int message_size, const char *name, const char *value, int overwrite); void explain_message_errno_setenv(char *message, int message_size, int errnum, const char *name, const char *value, int overwrite); DESCRIPTION
These functions may be used to obtain explanations for errors returned by the setenv(3) system call. explain_setenv const char *explain_setenv(const char *name, const char *value, int overwrite); The explain_setenv function is used to obtain an explanation of an error returned by the setenv(3) system call. The least the message will contain is the value of strerror(errno), but usually it will do much better, and indicate the underlying cause in more detail. The errno global variable will be used to obtain the error value to be decoded. name The original name, exactly as passed to the setenv(3) system call. value The original value, exactly as passed to the setenv(3) system call. overwrite The original overwrite, exactly as passed to the setenv(3) system call. Returns: The message explaining the error. This message buffer is shared by all libexplain functions which do not supply a buffer in their argument list. This will be overwritten by the next call to any libexplain function which shares this buffer, including other threads. Note: This function is not thread safe, because it shares a return buffer across all threads, and many other functions in this library. Example: This function is intended to be used in a fashion similar to the following example: if (setenv(name, value, overwrite) < 0) { fprintf(stderr, "%s ", explain_setenv(name, value, overwrite)); exit(EXIT_FAILURE); } The above code example is available pre-packaged as the explain_setenv_or_die(3) function. explain_errno_setenv const char *explain_errno_setenv(int errnum, const char *name, const char *value, int overwrite); The explain_errno_setenv function is used to obtain an explanation of an error returned by the setenv(3) system call. The least the message will contain is the value of strerror(errno), but usually it will do much better, and indicate the underlying cause in more detail. errnum The error value to be decoded, usually obtained from the errno global variable just before this function is called. This is neces- sary if you need to call any code between the system call to be explained and this function, because many libc functions will alter the value of errno. name The original name, exactly as passed to the setenv(3) system call. value The original value, exactly as passed to the setenv(3) system call. overwrite The original overwrite, exactly as passed to the setenv(3) system call. Returns: The message explaining the error. This message buffer is shared by all libexplain functions which do not supply a buffer in their argument list. This will be overwritten by the next call to any libexplain function which shares this buffer, including other threads. Note: This function is not thread safe, because it shares a return buffer across all threads, and many other functions in this library. Example: This function is intended to be used in a fashion similar to the following example: if (setenv(name, value, overwrite) < 0) { int err = errno; fprintf(stderr, "%s ", explain_errno_setenv(err, name, value, overwrite)); exit(EXIT_FAILURE); } The above code example is available pre-packaged as the explain_setenv_or_die(3) function. explain_message_setenv void explain_message_setenv(char *message, int message_size, const char *name, const char *value, int overwrite); The explain_message_setenv function is used to obtain an explanation of an error returned by the setenv(3) system call. The least the mes- sage will contain is the value of strerror(errno), but usually it will do much better, and indicate the underlying cause in more detail. The errno global variable will be used to obtain the error value to be decoded. message The location in which to store the returned message. If a suitable message return buffer is supplied, this function is thread safe. message_size The size in bytes of the location in which to store the returned message. name The original name, exactly as passed to the setenv(3) system call. value The original value, exactly as passed to the setenv(3) system call. overwrite The original overwrite, exactly as passed to the setenv(3) system call. Example: This function is intended to be used in a fashion similar to the following example: if (setenv(name, value, overwrite) < 0) { char message[3000]; explain_message_setenv(message, sizeof(message), name, value, overwrite); fprintf(stderr, "%s ", message); exit(EXIT_FAILURE); } The above code example is available pre-packaged as the explain_setenv_or_die(3) function. explain_message_errno_setenv void explain_message_errno_setenv(char *message, int message_size, int errnum, const char *name, const char *value, int overwrite); The explain_message_errno_setenv function is used to obtain an explanation of an error returned by the setenv(3) system call. The least the message will contain is the value of strerror(errno), but usually it will do much better, and indicate the underlying cause in more detail. message The location in which to store the returned message. If a suitable message return buffer is supplied, this function is thread safe. message_size The size in bytes of the location in which to store the returned message. errnum The error value to be decoded, usually obtained from the errno global variable just before this function is called. This is neces- sary if you need to call any code between the system call to be explained and this function, because many libc functions will alter the value of errno. name The original name, exactly as passed to the setenv(3) system call. value The original value, exactly as passed to the setenv(3) system call. overwrite The original overwrite, exactly as passed to the setenv(3) system call. Example: This function is intended to be used in a fashion similar to the following example: if (setenv(name, value, overwrite) < 0) { int err = errno; char message[3000]; explain_message_errno_setenv(message, sizeof(message), err, name, value, overwrite); fprintf(stderr, "%s ", message); exit(EXIT_FAILURE); } The above code example is available pre-packaged as the explain_setenv_or_die(3) function. SEE ALSO
setenv(3) change or add an environment variable explain_setenv_or_die(3) change or add an environment variable and report errors COPYRIGHT
libexplain version 0.52 Copyright (C) 2010 Peter Miller explain_setenv(3)
All times are GMT -4. The time now is 04:41 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy