Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 04-29-2016, 03:47 PM   #1
Registered: Apr 2012
Distribution: Ubuntu, SUSE, Redhat
Posts: 188

Rep: Reputation: Disabled
what does it mean when bash redirection truncates?

Hi all

I have the following example:
$ cat file | tr -s ' ' > file
And if I check my file later, it had some text before but now is blank.

but this example
$ cat file | tr -s ' ' >> file
If I check my file later, it contains my output exactly as it should from

I looked it up and it says this:

Redirecting output
The TARGET is truncated before writing starts.

Appending redirected output
The TARGET is not truncated before writing starts.
I am assuming truncated is the reason example 1 gives me a blank file while example 2 is not truncated and the reason why my file still contains useful information.

But what is truncated and what does it mean? Why would you want to truncate the file?

Old 04-29-2016, 04:30 PM   #2
LQ Guru
Registered: Nov 2004
Location: Saint Amant, Acadiana
Distribution: Gentoo ~arch
Posts: 6,316

Rep: Reputation: Disabled
You may want to replace the contents of a file.
Old 04-29-2016, 04:49 PM   #3
Registered: Aug 2002
Posts: 18,921

Rep: Reputation: 2849Reputation: 2849Reputation: 2849Reputation: 2849Reputation: 2849Reputation: 2849Reputation: 2849Reputation: 2849Reputation: 2849Reputation: 2849Reputation: 2849
This might be easier to understand.

For command > file, if file does not exist it will be created otherwise it will be overwritten. Overwritten means all existing file contents will be deleted.

For command >> file, if the file does not exist it will be created otherwise data will be appended. Appended mean new data is written at the end of the file and existing data remains.
Old 04-29-2016, 05:00 PM   #4
LQ Veteran
Registered: Jan 2011
Location: Yawnstown, Ohio
Distribution: Mojave
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Bash stdout redirection danielbmartin Programming 6 01-15-2016 02:09 PM
bash redirection help clifford227 Programming 6 07-30-2012 02:36 PM
Bash I/O redirection problem R00ts Programming 1 10-26-2006 07:50 PM
bash: socket redirection? Thinking Linux - Software 1 04-15-2006 12:20 PM
Bash redirection and subshells nx5000 Programming 2 11-03-2005 06:13 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:18 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration