LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   What does >> do? (https://www.linuxquestions.org/questions/linux-newbie-8/what-does-do-4175532614/)

flyingmouse77 01-31-2015 11:08 AM

What does >> do?
 
Hello all,

I've been given a basic Linux assignment in my Computer Concepts class, and I *think* I managed to enter all the commands and get the results expected. :) But I also have to define terms relating to Linux, and I've found everything except >>. I actually used it in my exercise: Type echo “enter_your_name_here” >> test2, but I'm not sure exactly what it did. Can anyone help?

Thanks!
flyingmouse77

Head_on_a_Stick 01-31-2015 11:55 AM

It appends the output to the specified file.

By contrast, the ">" operator would replace the content with the output.

flyingmouse77 01-31-2015 12:20 PM

Thank You!
 
I really appreciate your help! I was surprised to find I actually enjoyed playing around with Linux. :) It was fun to use the commands and see things happen.

frankbell 01-31-2015 09:09 PM

I'm happy to hear you are enjoying your taste of Linux.

Don't look back.:)

flyingmouse77 02-04-2015 01:42 PM

Now it's >
 
Hello all,

Head on a Stick told me that > would replace the content with the output. In this Linux exercise, our first step is to create a file named test1, using the touch command. The following step is to type echo "This is a test" > test1. Typing cat test1 shows This is a test. So am I understanding this correctly when I think test1 has been replaced with This is a test? When I try to duplicate the effect, I'm not successful. :(

flyingmouse77

veerain 02-04-2015 01:47 PM

'touch test1' creates a empty file named test1 if only no such file exists.

So better do 'echo abc > test1'
Then check with 'cat test1'
Then again put some text with 'echo def > test1'
Then check with 'cat test1'
So you would see abc replaced with def.

chrism01 02-05-2015 05:40 AM

Basically, when talking about files, take care to be explicit about whether you are talking about the file as a whole, the filename, or the file content... ;)

'cat' is short for catalogue (way back when) - basically types out the content of the file to stdout
touch is used to create a file (also to alter timestamps)

echo 'string' > file puts 'string' into file REPLACING current content ( '>>' appends to current content)
NB: this means that '>file' empties the file :)


HTH

pan64 02-05-2015 05:46 AM

see the complete description for example here: http://www.tldp.org/LDP/abs/html/io-redirection.html
(or you can check the redirections in the man page of bash too)

flyingmouse77 02-05-2015 10:48 AM

Thanks for all your replies!

I got a perfect score on my Linux lab, and actually learned a lot! The professor suggested working with DOS as well as Apple (ugh) to see similarities and differences. Apparently learning directory hierarchies was one of the goals here.

This is definitely fun for me to play with, but when do you actually use Linux in this way?

suicidaleggroll 02-05-2015 10:52 AM

Quote:

Originally Posted by flyingmouse77 (Post 5312568)
This is definitely fun for me to play with, but when do you actually use Linux in this way?

Multiple times per day, every day.

OSX is very similar to Linux when you're working on the command line, everything just translates straight over.

Head_on_a_Stick 02-05-2015 11:24 AM

Quote:

Originally Posted by flyingmouse77 (Post 5312568)
when do you actually use Linux in this way?

All the time: I have Arch as my main system -- it is a terminal condition...

273 02-05-2015 11:39 AM

Quote:

Originally Posted by flyingmouse77 (Post 5312568)
This is definitely fun for me to play with, but when do you actually use Linux in this way?

One could, I suppose, install and use modern Linux day in day out and only in rare cases have to touch the command line (much as with Windows) but for me, and others I suspect, typing a few commands to update the system and install packages seems more straightforward than messing with a GUI and in the case of my Pi, for example, I don't have a monitor or input devices attached so it is much easier to use SSH to get into it and work on the command line.

flyingmouse77 02-05-2015 02:48 PM

There is something really satisfying about typing in commands and seeing results. :)

chrism01 02-06-2015 03:18 AM

Use that stuff all the time: I work on servers :)

Oh, BTW http://rute.2038bug.com/index.html.gz - Enjoy ;)

flyingmouse77 02-06-2015 09:25 AM

Head on a stick, I see what you did there. :) Clever.

rtmistler 02-06-2015 10:00 AM

Quote:

Originally Posted by flyingmouse77 (Post 5312568)
This is definitely fun for me to play with, but when do you actually use Linux in this way?

As others have said, you could install and use a desktop distribution and use it much like Windows and never end up entering anything to a command line. I guess another parallel is if you use Windows, you may also never use the command line, but there are rare occasions where that can happen and usually it's either because you were recommended or instructed to do so, or you learned enough about the system to eventually use it for more technical reasons than a casual user.

And then there are cases where you do more with Linux besides use it as a desktop. For instance a server, or maintain systems for others, or write code and scripts. In those cases, you'd find that you'd use the command line very much. Similarly the subtle differences between ">" and ">>" would be important if you wished to do something in a script I prefer, which is to use those to re-direct to a log file and also have the log file be newly created each time the script runs. Some scripts I have are invoked randomly as needed and each time they may be doing a repetitive task, but still unique to the time I'm running it. Therefore the first write to my log file will cause any existing log file to be replaced, and then following writes to the log file will append versus overwrite.

flyingmouse77 02-06-2015 11:36 AM

I did have the impression that Linux seemed to be mostly used for servers. If used in a server situation, is the command line version or the GUI version? I was thinking command line...

suicidaleggroll 02-06-2015 11:49 AM

Quote:

Originally Posted by flyingmouse77 (Post 5313126)
I did have the impression that Linux seemed to be mostly used for servers. If used in a server situation, is the command line version or the GUI version? I was thinking command line...

It could be either. Most of the time servers have no keyboard, monitor, or mouse attached, so a GUI is just a waste of space and is not installed. That doesn't mean it can't be installed though.

273 02-06-2015 11:52 AM

Quote:

Originally Posted by flyingmouse77 (Post 5313126)
I did have the impression that Linux seemed to be mostly used for servers. If used in a server situation, is the command line version or the GUI version? I was thinking command line...

I think it is safe to assume that most machines used exclusively as some kind of server will likely use mainly the command line.
Last I saw Microsoft are heading that way a little too offering a command line only version and making a lot of tasks, such as creating Exchange mailboxes, much easier on the command line that through the GUI.


All times are GMT -5. The time now is 06:17 PM.