Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The method of changing file size by Linux

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Function prototype:

# include int ftruncate (int fd, off_t length); / / change the file size to the specified size of length; return value 0 for successful execution and-1 for failure.

The function ftruncate changes the file size specified by parameter fd to the size specified by parameter length. The parameter fd is an open file descriptor and must be a file opened in write mode. If the original file size is larger than the parameter length, the excess will be deleted.

Test.c

# include#include#include#include#include#includeint main (int argc,char** argv) {struct stat st; bzero (& st,sizeof (st)); stat (argv [1], & st); printf ("% s% ld\ n", argv [1], st.st_size); int fd=open (argv [1], O_RDWR); ftruncate (fd,20); bzero (& st,sizeof (st)); stat (argv [1], & st) Printf ("% s% ld\ n", argv [1], st.st_size); close (fd); return 0;}

Summary

The above is the method of changing the file size of Linux introduced by the editor. I hope it will be helpful to you. If you have any questions, please leave a message for me, and the editor will reply you in time. Thank you very much for your support to the website!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report