Ubuntu – The difference between “>” and “>>”

command line

What is the difference between ls > and ls >>?
I need to understand this for my GCSE computing but don't know what the difference is.

Best Answer

  • > & >> are redirection operators; they transfer output of something, in this case ls, elsewhere. If this output goes to a file, > will truncate the file - ie delete any previous content, whereas >> will append new data onto the end of the file, keeping previous content. This will work with any input, so echo & cat, for example, can also be used this way.

    Also of interest is the | operator, which passes the data to another application - so ls | cat -n will give you a line-numbered listing !

    Pipes is the relevant term.