Current Events > Anyone know linux terminal commands well?

Topic List
Page List: 1
Milkman5
07/16/17 3:44:12 PM
#1:


I have to write a script that has to do a bunch of things and one of the requirements is the script must
Redirect text on the command line to a file called data.txt and save it


what does that mean? Am I supposed to write everything written so far on the command line and save it to a file? how to I save all of it?


I know I have to write [placeholder]>data.txt

but what do I put in the placeholder spot
... Copied to Clipboard!
King Rial
07/16/17 3:54:33 PM
#2:


I don't know anything at all. lol

But I'll bump this for you for someone that does.
---
I use Google... A lot.... >______>
... Copied to Clipboard!
DarkDragon400
07/16/17 3:56:44 PM
#3:


I guess you would just echo whatever text you want to save.
---
... Copied to Clipboard!
MutantJohn
07/16/17 3:57:57 PM
#4:


echo 'hello world' > data.txt

Keep in mind, > will either create or overwrite a file that already exists. To append, using >>

You can pipe the output of any command.
---
"Oh, my mother; oh, my friends, ask the angels, will I ever see heaven again?" - Laura Marling
... Copied to Clipboard!
Milkman5
07/16/17 4:00:22 PM
#6:


So he just wants one line that I write specifically to be saved to the file?

I was expecting something more elaborate
... Copied to Clipboard!
Milkman5
07/16/17 4:00:51 PM
#7:


I want to use > because I want to be overwriting it
... Copied to Clipboard!
DarkDragon400
07/16/17 4:01:37 PM
#8:


Milkman5 posted...
So he just wants one line that I write specifically to be saved to the file?

I was expecting something more elaborate

It might be, you don't exactly go into detail on what the requirements are.
---
... Copied to Clipboard!
Milkman5
07/16/17 4:03:23 PM
#9:


DarkDragon400 posted...
It might be, you don't exactly go into detail on what the requirements are.


ok. I copy pasted the requirements. It's in italics. It's just vague.
... Copied to Clipboard!
MutantJohn
07/16/17 4:05:55 PM
#10:


It is a little vague. I'm assuming he just wants command output to be stored somewhere. If he means copying all of the text in the current terminal window and then saving that, that's a bit more interesting.
---
"Oh, my mother; oh, my friends, ask the angels, will I ever see heaven again?" - Laura Marling
... Copied to Clipboard!
Rika_Furude
07/16/17 4:07:15 PM
#11:


Yeah, the requirements mean just add >> data.txt to the end of your command
---
Posted with GameRaven 3.2
... Copied to Clipboard!
DarkDragon400
07/16/17 4:12:43 PM
#12:


Milkman5 posted...
I want to use > because I want to be overwriting it

If there are multiple commands you want to save the output of, you would use > for the first and >> for the rest.
---
... Copied to Clipboard!
Milkman5
07/16/17 4:16:53 PM
#13:


oh I see. Thanks.
I think I understand
... Copied to Clipboard!
Milkman5
07/16/17 4:27:02 PM
#14:


so after every line in the script

should I rewrite it under echo "stuff" >>data.txt

or is there a way to write it to the file WHILE the script runs the command?


Will just adding to each command >>data.txt work?
... Copied to Clipboard!
DarkDragon400
07/16/17 4:28:16 PM
#15:


Milkman5 posted...
Will just adding to each command >>data.txt work?

Yes.
---
... Copied to Clipboard!
Milkman5
07/16/17 4:47:00 PM
#16:


I tried it and got weird results >_>

like if I write cd TEMP >>data.txt

it wasn't writing the whole command or maybe I just overlooked something
... Copied to Clipboard!
MutantJohn
07/16/17 5:47:06 PM
#17:


Piping program output != writing a command to a file and then executing it.
---
"Oh, my mother; oh, my friends, ask the angels, will I ever see heaven again?" - Laura Marling
... Copied to Clipboard!
Milkman5
07/16/17 5:48:04 PM
#18:


MutantJohn posted...
Piping program output != writing a command to a file and then executing it.


ok so just write a dummy line then?
like echo "this is a file" >data.txt?
... Copied to Clipboard!
Milkman5
07/16/17 5:48:36 PM
#19:


I'm almost done with the project, I'll post it here for opinions if it meets every requirement
... Copied to Clipboard!
Milkman5
07/16/17 7:24:58 PM
#20:


what does it mean to " traverse
through all directories"?
... Copied to Clipboard!
MutantJohn
07/16/17 7:35:55 PM
#21:


That you'll most likely pass the "recursive" option to w/e command you're running.
---
"Oh, my mother; oh, my friends, ask the angels, will I ever see heaven again?" - Laura Marling
... Copied to Clipboard!
Milkman5
07/17/17 2:03:15 AM
#22:


how do I use ls -R?

I'm assuming that's what it wants
... Copied to Clipboard!
DarkDragon400
07/17/17 2:15:19 AM
#23:


... Copied to Clipboard!
Milkman5
07/17/17 2:17:06 AM
#24:


Yeah I already did that and turned it in, it's just I saw someone whining on stack overflow to do something else

but I tried it and it worked so I just called it a day and submitted it
... Copied to Clipboard!
Rika_Furude
07/17/17 4:05:35 AM
#25:


... Copied to Clipboard!
TRC
07/17/17 4:14:03 AM
#26:


I am quite interested in this here topic...

*continues testing postgres backups for work*
... Copied to Clipboard!
Milkman5
07/17/17 4:28:38 AM
#27:


Rika_Furude posted...
give us the questions and your answers

anonymized if needed


um I already turned it in so I changed my mind about posting the script.

Plus I don't want the professor to search my homework online and find it here and think I stole my homework from myself
... Copied to Clipboard!
Rika_Furude
07/17/17 4:30:27 AM
#28:


your professor doesnt have a gamefaqs account + it's not like you were copy/pasting your answers, you genuinely seemed to be trying to learn it. no professor would deduct marks for that. stack overflow is an essential tool in any developers kit in the real world
---
... Copied to Clipboard!
Milkman5
07/17/17 4:32:32 AM
#29:


Rika_Furude posted...
your professor doesnt have a gamefaqs account + it's not like you were copy/pasting your answers, you genuinely seemed to be trying to learn it. no professor would deduct marks for that. stack overflow is an essential tool in any developers kit in the real world


No I mean he might think I stole it from me, like maybe he might not believe Milkman5 is me, idk.

I don't know how current events shows up on a google search. Just because you can't view the topics, don't they still show up on a google search while they are still active?
... Copied to Clipboard!
Milkman5
07/17/17 4:33:28 AM
#30:


My professor is young. Mid twenties, so he's p internet savvy
... Copied to Clipboard!
MutantJohn
07/17/17 11:00:50 AM
#31:


And apparently trolling Current Events on gamefaqs ;)

To be fair, learning some Bash is good. But if you're serious about your system scripts, just switch to Python.
---
"Oh, my mother; oh, my friends, ask the angels, will I ever see heaven again?" - Laura Marling
... Copied to Clipboard!
Milkman5
07/17/17 11:02:48 AM
#32:


MutantJohn posted...
And apparently trolling Current Events on gamefaqs ;)

To be fair, learning some Bash is good. But if you're serious about your system scripts, just switch to Python.


it's a capstone course about operating systems
... Copied to Clipboard!
Milkman5
07/17/17 11:03:10 AM
#33:


So it wouldn't make too much sense for him to have us use Python
... Copied to Clipboard!
Milkman5
07/17/17 11:04:45 AM
#34:


anyways, my script was just
clear
echo "Current Working Directory: "
echo "${PWD##*/}"
rm -r TEMP; mkdir TEMP
cd TEMP
read -p "Input contents for datat.txt: " datacontents
echo $datacontents >data.txt
echo "Contents of data.txt: "
cat data.txt
cp data.txt try.txt
echo "Contents of all files ending in .txt: "
find . -type f -name "*.txt" -exec cat {} +
mkdir TEMPSecond
mv try.txt TEMPSecond/rename.txt
ls >hold.txt
ls -a >>hold.txt
ls -l >>hold.txt
ls -R >>hold.txt
echo "Contents of hold.txt: "
cat hold.txt



idk, he might search it, but by the time he does I'm sure this topic will be deleted
... Copied to Clipboard!
Milkman5
07/17/17 11:05:29 AM
#35:


it just does a bunch of random shit that I was told to make it do
... Copied to Clipboard!
MutantJohn
07/17/17 11:07:35 AM
#36:


Milkman5 posted...
So it wouldn't make too much sense for him to have us use Python

Don't conflate the Bash shell with anything about your OS. Well, I guess OS really is kernel + software on top but don't think that Bash is somehow part of Linux. There are other shells you can use as well instead of Bash.
---
"Oh, my mother; oh, my friends, ask the angels, will I ever see heaven again?" - Laura Marling
... Copied to Clipboard!
Milkman5
07/17/17 11:13:15 AM
#37:


This isn't even Bash, I'm using an sh
... Copied to Clipboard!
Milkman5
07/17/17 11:13:37 AM
#38:


I don't remember ever even mentioning bash
... Copied to Clipboard!
mario2000
07/17/17 11:16:36 AM
#39:


is tc seriously scared that his professor will find out about this topic lmao
---
Arrrr the SS Goku, Mighty fine boat... -fatmatt
Hope Frieza doesn't chuck an Iceberg at the Goku, otherwise it's all over. -Nekoslash
... Copied to Clipboard!
Milkman5
07/17/17 11:18:29 AM
#40:


Technically it's not even my OS since I'm accessing a Linux system through a secure shell.
I also have a virtual ubuntu machine on my computer, but it's annoying to use, so I don't unless I need to.

Not sure why you even assumed I was using Bash, but maybe it's because most people with Windows use Bash? not sure
... Copied to Clipboard!
Milkman5
07/17/17 11:19:22 AM
#41:


mario2000 posted...
is tc seriously scared that his professor will find out about this topic lmao


He seems like he would be a CEman. He's a computer nerd who got his BS and Masters in like 3 years combined and he's probably younger than me
... Copied to Clipboard!
MutantJohn
07/17/17 11:27:26 AM
#42:


Not sure why you even assumed I was using Bash, but maybe it's because most people with Windows use Bash? not sure


Do me a favor, define Bash.
---
"Oh, my mother; oh, my friends, ask the angels, will I ever see heaven again?" - Laura Marling
... Copied to Clipboard!
Milkman5
07/17/17 11:29:27 AM
#43:


MutantJohn posted...

Do me a favor, define Bash.


it's not bash

Bash is a unix shell, but it's not the one I was using

my script started with #!/bin/sh for example and not #!/bin/bash
... Copied to Clipboard!
Milkman5
07/17/17 11:31:10 AM
#44:


or were you using Bash as slang for shell scripting? or what. I'm not using bash, but I guess this might be a Kleenex type language thing happening
... Copied to Clipboard!
DarkDragon400
07/17/17 11:34:39 AM
#45:


Milkman5 posted...
or were you using Bash as slang for shell scripting? or what. I'm not using bash, but I guess this might be a Kleenex time language thing happening

I'm pretty sure Bash is probably the most common shell these days, so guessing a person is using Bash as their shell is usually a safe bet.
---
... Copied to Clipboard!
Milkman5
07/17/17 11:39:44 AM
#46:


DarkDragon400 posted...
I'm pretty sure Bash is probably the most common shell these days, so guessing a person is using Bash as their shell is usually a safe bet.


oh, right on. Makes sense I guess
... Copied to Clipboard!
Topic List
Page List: 1