Questions tagged [truncate]

19 questions
283
votes
3 answers

Most efficient method to empty the contents of a file

I am aware of three methods to delete all entries from a file. They are >filename touch filename1 filename < /dev/null Of these three I abuse >filename the most as that requires the least number of keystrokes. However, I would like to know which…
debal
  • 3,664
  • 5
  • 17
  • 18
24
votes
4 answers

Is there any limit on line length when pasting to a terminal in Linux?

I am trying to send messages from kafka-console-producer.sh, which is #!/bin/bash if [ "x$KAFKA_HEAP_OPTS" = "x" ]; then export KAFKA_HEAP_OPTS="-Xmx512M" fi exec $(dirname $0)/kafka-run-class.sh kafka.tools.ConsoleProducer "$@" I am pasting…
Dims
  • 3,181
  • 9
  • 49
  • 107
6
votes
9 answers

Is it possible to truncate a file (in place, same inode) at the beginning?

It is possible to remove trailing bytes of a file without writting to a new file (> newfile) and moving it back (mv newfile file). That is done with truncate: truncate -s -1 file It is possible to remove leading bytes but by moving it around (which…
user232326
4
votes
1 answer

Difference between writing file from /dev/zero and truncate

$ timeout 1 cat /dev/zero > file1 $ wc -c file1 270422016 file1 $ du file1 264084 file1 Questions : (1) How do 270422016 null characters come out to be 264084 bytes (i.e 258M). $ truncate -s 270422016 file2 $ wc -c file2 270422016 file2 $ du…
GypsyCosmonaut
  • 3,988
  • 7
  • 38
  • 62
2
votes
1 answer

Truncate file that is opened in another procces

If I try truncate -s 0 log.log (:>log.log has same behavior) the displayd space on disk do become free but the size (ls -l) of file is still the same (tho du shows less). As far as I understand, it happens because the pointer is still "old". This…
Sova
  • 23
  • 2
2
votes
2 answers

/usr/bin/truncate: Argument list too long

I want to use the truncate command to create a huge number of small files for testing. I tried the command with a small number of files (100) and it worked. When I changed the number to 1000000, it reports an error: root:[~/data]# truncate -s 1k…
Just a learner
  • 1,766
  • 4
  • 22
  • 32
1
vote
0 answers

truncate command to to safely remove Celery log files?

I my Ubuntu server that is running Python/Celery has about 9 log files totaling to 9GB space. Is it safe to reduce the size of these files by running the following command? truncate -s 0 *log If not, is there any other suggestions to reduce the…
1
vote
1 answer

tee pipeline and pnmtools - truncated file

This sequence of commands works OK: pngtopnm file.png 2> /dev/null > dump1 pnmfile < dump1 stdin: PPM raw, 1920 by 1080 maxval 255 ls -l dump1 -rw-r----- 1 cmb 6220817 Sep 15 14:26 dump1 But redoing the pipeline to use 'tee' truncates the output…
ColinB
  • 113
  • 3
1
vote
1 answer

ffmpeg truncates paths on output when there are dots involved when run on bash

If I have a path with dots in the path, for instance: /home/user/Documents/hello/test.testing_23-24.123/test.testing_23-24.124 ffmpeg can locate the file if you pass the file's path as an argument but it will truncate the path name to the first dot…
1
vote
1 answer

How to print multiple columns without truncating?

I know that pr -m -t file1 file2 will give me 2 columns like so: file1: a abc abcdefg abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz file2: 1 123 12345678 12345678901234567890 - $ pr -m -t file1 file2 a 1 abc …
Timothy Swan
  • 141
  • 10
1
vote
1 answer

What size blocks does `truncate --io-blocks` use?

What size blocks does GNU truncate --io-blocks use? -o, --io-blocks treat SIZE as number of IO blocks instead of bytes 512 bytes blockdev --getbsz blockdev --getpbsz
Tom Hale
  • 28,728
  • 32
  • 139
  • 229
0
votes
1 answer

Problem creating a disk image of an SD card

I have built a custom image of Armbian with a partition size of 3.1 GB, and I am now finished working with it. It is currently written to a bootable 64 GB SD card which is using a GUID partition table (GPT). My problem is, is that when I want to…
0
votes
0 answers

"> $logfile" does not truncate, file size goes to 0 and a second later, is back to full size

I have a script that writes to a logfile like this: $ nohup myscript.sh > myscript.out 2>&1 & when the log file gets very large, I need to truncate it like this: > myscript.out I see the size go to 0 briefly but immediately jumps back to full size…
chiwal
  • 1
  • 1
0
votes
1 answer

Truncate expand doesnt seem to work?

I just expanded my 1G "homefile" which is mounted to /home/user by another GB using truncate -s +1G homefile, and while it changed the size of homefile shown with df to 2GB, when mounted it is still only 1GB. Am I missing something? I dont have to…
alchemy
  • 537
  • 5
  • 16
0
votes
0 answers

truncate linux kernel

firstly sorry for my English. I want to truncate kernel options like Bluetooth, mouse, keyboard etc.. except for my use. but how can I know that kernel options related to devices that I want to remove? I've been that work with "make…
Jinwoo Bae
  • 13
  • 4
1
2