Creating a file in Linux? (Touch vs Echo)Why isn't there any shell command to create files?differences...

How could a medieval fortress manage large groups of migrants and travelers?

Why is Katakana not pronounced Katagana?

What is the word for "event executor"?

How to ask my office to remove the pride decorations without appearing anti-LGBTQ?

Unix chat server making communication between terminals possible

How to remove the first colon ':' from a timestamp?

Advice for paying off student loans and auto loans now that I have my first 'real' job

How Can I Process Untrusted Data Sources Securely?

When does Fisher's "go get more data" approach make sense?

Link of a singularity

Manually select/unselect lines before forwarding to stdout

Why does FFmpeg choose 10+20+20 ms instead of an even 16 ms for 60 fps GIF images?

Alphanumeric Line and Curve Counting

What "fuel more powerful than anything the West (had) in stock" put Laika in orbit aboard Sputnik 2?

how many bits in the resultant hash will change, if the x bits are changed in its the original input

Is there a source that says only 1/5th of the Jews will make it past the messiah?

Why did Spider-Man take a detour to Dorset?

How could an animal "smell" carbon monoxide?

Why did Steve Rogers choose this character in Endgame?

Is there any conditions on a finite abelian group so that it cannot be class group of any number field?

What could be reasoning of male prison in VR world to only allow undershirt and sarong as nightwear to male prisoners

Intel 8080-based home computers

Bone Decomposition

Can a Resident Assistant Be Told to Ignore a Lawful Order?



Creating a file in Linux? (Touch vs Echo)


Why isn't there any shell command to create files?differences between echo“”> and > commandFastest way to get list of all file sizesecho string >> file does not workCreation of a WORM fileecho bytes to a fileHow to compare file sizes in two directories?How to list directory/file sizes in general on UNIX-like systems?File size after cutWhen does touch command need the file to exist?How to `touch` and `cat` file named `-`






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







1















I'm pretty new the Linux in general so I'm not too familiar with do's and don'ts or some commands.



I wanted to create a file and noticed that:



touch file.txt `


creates a file but so does:



echo >> file.txt


and also



> file.txt


The files created with ">" and "touch" are both 0 bytes but the file created with "echo" is 1 byte



why are the files different sizes and whats the best way to create a file? when should someone create a file with "echo" instead of "touch" or ">"?










share|improve this question







New contributor



Alex Valdez is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.


























    1















    I'm pretty new the Linux in general so I'm not too familiar with do's and don'ts or some commands.



    I wanted to create a file and noticed that:



    touch file.txt `


    creates a file but so does:



    echo >> file.txt


    and also



    > file.txt


    The files created with ">" and "touch" are both 0 bytes but the file created with "echo" is 1 byte



    why are the files different sizes and whats the best way to create a file? when should someone create a file with "echo" instead of "touch" or ">"?










    share|improve this question







    New contributor



    Alex Valdez is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






















      1












      1








      1








      I'm pretty new the Linux in general so I'm not too familiar with do's and don'ts or some commands.



      I wanted to create a file and noticed that:



      touch file.txt `


      creates a file but so does:



      echo >> file.txt


      and also



      > file.txt


      The files created with ">" and "touch" are both 0 bytes but the file created with "echo" is 1 byte



      why are the files different sizes and whats the best way to create a file? when should someone create a file with "echo" instead of "touch" or ">"?










      share|improve this question







      New contributor



      Alex Valdez is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      I'm pretty new the Linux in general so I'm not too familiar with do's and don'ts or some commands.



      I wanted to create a file and noticed that:



      touch file.txt `


      creates a file but so does:



      echo >> file.txt


      and also



      > file.txt


      The files created with ">" and "touch" are both 0 bytes but the file created with "echo" is 1 byte



      why are the files different sizes and whats the best way to create a file? when should someone create a file with "echo" instead of "touch" or ">"?







      linux ubuntu files echo touch






      share|improve this question







      New contributor



      Alex Valdez is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.










      share|improve this question







      New contributor



      Alex Valdez is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      share|improve this question




      share|improve this question






      New contributor



      Alex Valdez is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      asked 1 hour ago









      Alex ValdezAlex Valdez

      61 bronze badge




      61 bronze badge




      New contributor



      Alex Valdez is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




      New contributor




      Alex Valdez is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.
























          1 Answer
          1






          active

          oldest

          votes


















          1














          For the general question about creating files, see: Why isn't there any shell command to create files?





          With both > file and echo >> file, the shell creates the file if it didn't already exist.



          With > file, the file is truncated if it already existed. No command was specified, so nothing gets written to the file and the file will be empty.



          echo, without any arguments, prints an empty line. So the output contains the line ending character, typically linefeed (LF, n):



          % echo | od -c
          0000000 n
          0000001


          So with echo >> file, you get one byte written to the file. If the file already existed, then it would have one byte added to it, because you used >> (append) instead of > (overwrite).



          touch creates a file if it didn't already exist, and updates the timestamps on it otherwise. touch doesn't change the contents of the file, so if it already existed and had some contents in it, the contents would remain the same after touch.



          Which you want to use depends on what effect you want.






          share|improve this answer


























            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "106"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });






            Alex Valdez is a new contributor. Be nice, and check out our Code of Conduct.










            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f530555%2fcreating-a-file-in-linux-touch-vs-echo%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            For the general question about creating files, see: Why isn't there any shell command to create files?





            With both > file and echo >> file, the shell creates the file if it didn't already exist.



            With > file, the file is truncated if it already existed. No command was specified, so nothing gets written to the file and the file will be empty.



            echo, without any arguments, prints an empty line. So the output contains the line ending character, typically linefeed (LF, n):



            % echo | od -c
            0000000 n
            0000001


            So with echo >> file, you get one byte written to the file. If the file already existed, then it would have one byte added to it, because you used >> (append) instead of > (overwrite).



            touch creates a file if it didn't already exist, and updates the timestamps on it otherwise. touch doesn't change the contents of the file, so if it already existed and had some contents in it, the contents would remain the same after touch.



            Which you want to use depends on what effect you want.






            share|improve this answer




























              1














              For the general question about creating files, see: Why isn't there any shell command to create files?





              With both > file and echo >> file, the shell creates the file if it didn't already exist.



              With > file, the file is truncated if it already existed. No command was specified, so nothing gets written to the file and the file will be empty.



              echo, without any arguments, prints an empty line. So the output contains the line ending character, typically linefeed (LF, n):



              % echo | od -c
              0000000 n
              0000001


              So with echo >> file, you get one byte written to the file. If the file already existed, then it would have one byte added to it, because you used >> (append) instead of > (overwrite).



              touch creates a file if it didn't already exist, and updates the timestamps on it otherwise. touch doesn't change the contents of the file, so if it already existed and had some contents in it, the contents would remain the same after touch.



              Which you want to use depends on what effect you want.






              share|improve this answer


























                1












                1








                1







                For the general question about creating files, see: Why isn't there any shell command to create files?





                With both > file and echo >> file, the shell creates the file if it didn't already exist.



                With > file, the file is truncated if it already existed. No command was specified, so nothing gets written to the file and the file will be empty.



                echo, without any arguments, prints an empty line. So the output contains the line ending character, typically linefeed (LF, n):



                % echo | od -c
                0000000 n
                0000001


                So with echo >> file, you get one byte written to the file. If the file already existed, then it would have one byte added to it, because you used >> (append) instead of > (overwrite).



                touch creates a file if it didn't already exist, and updates the timestamps on it otherwise. touch doesn't change the contents of the file, so if it already existed and had some contents in it, the contents would remain the same after touch.



                Which you want to use depends on what effect you want.






                share|improve this answer













                For the general question about creating files, see: Why isn't there any shell command to create files?





                With both > file and echo >> file, the shell creates the file if it didn't already exist.



                With > file, the file is truncated if it already existed. No command was specified, so nothing gets written to the file and the file will be empty.



                echo, without any arguments, prints an empty line. So the output contains the line ending character, typically linefeed (LF, n):



                % echo | od -c
                0000000 n
                0000001


                So with echo >> file, you get one byte written to the file. If the file already existed, then it would have one byte added to it, because you used >> (append) instead of > (overwrite).



                touch creates a file if it didn't already exist, and updates the timestamps on it otherwise. touch doesn't change the contents of the file, so if it already existed and had some contents in it, the contents would remain the same after touch.



                Which you want to use depends on what effect you want.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 59 mins ago









                murumuru

                41.7k5 gold badges101 silver badges175 bronze badges




                41.7k5 gold badges101 silver badges175 bronze badges






















                    Alex Valdez is a new contributor. Be nice, and check out our Code of Conduct.










                    draft saved

                    draft discarded


















                    Alex Valdez is a new contributor. Be nice, and check out our Code of Conduct.













                    Alex Valdez is a new contributor. Be nice, and check out our Code of Conduct.












                    Alex Valdez is a new contributor. Be nice, and check out our Code of Conduct.
















                    Thanks for contributing an answer to Unix & Linux Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f530555%2fcreating-a-file-in-linux-touch-vs-echo%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

                    Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

                    Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...