Sponsored Content
Full Discussion: How to truncate as filesize?
Top Forums Shell Programming and Scripting How to truncate as filesize? Post 74070 by jolok on Tuesday 7th of June 2005 03:24:05 PM
Old 06-07-2005
from 'man truncate(1)' :


-s [+|-]size[K|k|M|m|G|g]
If the size argument is preceded by a plus sign (+), files will
be extended by this number of bytes. If the size argument is
preceded by a dash (-), file lengths will be reduced by no more
than this number of bytes, to a minimum length of zero bytes.
Otherwise, the size argument specifies an absolute length to
which all files should be extended or reduced as appropriate.

The size argument may be suffixed with one of K, M or G (either
upper or lower case) to indicate a multiple of Kilobytes,
Megabytes or Gigabytes respectively.

Exactly one of the -r and -s options must be specified.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

filesize

I know in php if you use the function filesize it will return the size of the file in bytes, but is there an easy way to get the size in MB. Cheers (2 Replies)
Discussion started by: jmg5
2 Replies

2. Shell Programming and Scripting

FileSize ???

How do I identify if there is any content in a file? If there is nothing in a specified file, I'd like to send an email indicating that there is nothing to report. Any help appreciated. (3 Replies)
Discussion started by: Cameron
3 Replies

3. UNIX for Dummies Questions & Answers

Sorting ls by filesize

I saw some stuff in the search results on this - but nothing specific..... I have a significant number of files (c. 300) which are output from a large process that I run. These are compared with a 'baselined' set of files - so I can quickly see if there are differences based on the sizes of the... (2 Replies)
Discussion started by: peter.herlihy
2 Replies

4. UNIX for Dummies Questions & Answers

UNIX and filesize

Hey guys. What I need to do is this: I need to find files that have a certain filesize (for this case a file size of 0 (zero) ) When I find this file with a filesize of zero I need to echo a statement that tells the user to delete it and not to delete it if the filesize is greater than... (3 Replies)
Discussion started by: ndoggy020
3 Replies

5. Shell Programming and Scripting

filesize

I want to know if there is any unix command to view the size of the file? eg. i have a directory letter in this i have file a,b,c,d,e. i just want to know the size of file d and not any other. (3 Replies)
Discussion started by: infyanurag
3 Replies

6. Shell Programming and Scripting

getting filesize

Hello, I have a script that should store file size in a variable $filesize. I don't know what is the best way to do it. I tried ls -lt myfile.txt | sed something >$filesize but I don't know how to use sed to get filesize. I know that the owner of the file is root and then we have some... (6 Replies)
Discussion started by: pppswing
6 Replies

7. Shell Programming and Scripting

Filesize not working

I am having problems with finding the filesize with this in my script: filesize=`ls -l | awk '$5=0'` if ; then ls -l | awk '{print $9 " " $5}' if ; then echo "Would you like to delete this file? (y/n)" if yes do this elif no do this fi fi else... (7 Replies)
Discussion started by: akeenabawa
7 Replies

8. Solaris

Check for filesize limit

How do I check for any file size limitations in a directories ? I remember my administrator had set a file limitation for a certain directory. I would like to know how I can check that. Thank you. (2 Replies)
Discussion started by: Leion
2 Replies

9. Shell Programming and Scripting

comparing filesize in unixscript

Well i was trying to code some script where it was required to compare the file size.. i am using solaris 5.10 to get the filesize i used: Filesize=`du -k temp/Final | awk '{print $1}' | sed 's/ //g'` now i need to do if filesize not equal to 0 then do something fi i... (2 Replies)
Discussion started by: egunda
2 Replies

10. Shell Programming and Scripting

if condition for filesize

Hi, I want to check file size in unix, based on file size I am going to execute appropriate command. I tried below, but getting the error. System details – Machine hardware: sun4u OS version: 5.9 if ( -s $f1 ) then echo "filename exists and is > 0 bytes" else echo "filename... (7 Replies)
Discussion started by: rahulbahulekar
7 Replies
TRUNCATE(2)						      BSD System Calls Manual						       TRUNCATE(2)

NAME
truncate, ftruncate -- truncate or extend a file to a specified length LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <unistd.h> int truncate(const char *path, off_t length); int ftruncate(int fd, off_t length); DESCRIPTION
The truncate() system call causes the file named by path or referenced by fd to be truncated or extended to length bytes in size. If the file was larger than this size, the extra data is lost. If the file was smaller than this size, it will be extended as if by writing bytes with the value zero. With ftruncate(), the file must be open for writing. RETURN VALUES
Upon successful completion, the value 0 is returned; otherwise the value -1 is returned and the global variable errno is set to indicate the error. If the file to be modified is not a directory or a regular file, the truncate() call has no effect and returns the value 0. ERRORS
The truncate() system call succeeds unless: [ENOTDIR] A component of the path prefix is not a directory. [ENAMETOOLONG] A component of a pathname exceeded 255 characters, or an entire path name exceeded 1023 characters. [ENOENT] The named file does not exist. [EACCES] Search permission is denied for a component of the path prefix. [EACCES] The named file is not writable by the user. [ELOOP] Too many symbolic links were encountered in translating the pathname. [EPERM] The named file has its immutable or append-only flag set, see the chflags(2) manual page for more information. [EISDIR] The named file is a directory. [EROFS] The named file resides on a read-only file system. [ETXTBSY] The file is a pure procedure (shared text) file that is being executed. [EFBIG] The length argument was greater than the maximum file size. [EINVAL] The length argument was less than 0. [EIO] An I/O error occurred updating the inode. [EFAULT] The path argument points outside the process's allocated address space. The ftruncate() system call succeeds unless: [EBADF] The fd argument is not a valid descriptor. [EINVAL] The fd argument references a socket, not a file. [EINVAL] The fd descriptor is not open for writing. SEE ALSO
chflags(2), open(2) HISTORY
The truncate() system call appeared in 4.2BSD. BUGS
These calls should be generalized to allow ranges of bytes in a file to be discarded. Use of truncate() to extend a file is not portable. BSD
December 13, 2006 BSD
All times are GMT -4. The time now is 11:27 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy