13

This question already has an answer here:

I am currently doing preparation for my GCSE computing controlled assessment on Linux. I type ls > list and ls >> list into the command line, but it does not do anything. I have googled it but I can't find what it exactly does.

What does:

ls > list

and

ls >> list

do?

marked as duplicate by don_crissti, a CVn, Anthon, slm Dec 2 '14 at 13:22

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

18

Both redirect stdout to file.

ls > list

If the file exists it'll be replaced.

ls >> list

If the file does not exist it'll be created. If it exists, it'll be appended to the end of the file.

Find out more: IO Redirection

4

This:

ls > list

means redirect the output from the ls command to create a new file called list. If the file already exists, replace it.

Whereas

ls >> list

means redirect the output from the ls command and append it to the file called list If the file doesn't exist then create it.


Typically > is used when wiping out an existing file is ok. This often means that outputs continually overwrites a file based on the latest current state of things. For instance every time you test a program you might over-write the previous test output.

Typically >> is used for items such as logging events, parsing or other data processing where data is created or transformed piece by piece into a new form

0

Both commands redirect output of ls command to file with name list. > will create/replace the output file with name list. >> will create (if file list not exists already) or append the file list. Can see the contents of file list using cat list.

Not the answer you're looking for? Browse other questions tagged or ask your own question.