LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-23-2018, 11:27 PM   #1
ziggs
Member
 
Registered: Jan 2018
Posts: 37

Rep: Reputation: Disabled
Confusing instructions


Hello all,

I am new to Linux, and I am currently have some trouble with a simple text command:

I am using echo "test 1 2 3">~root/testfile.txt. Nothing happens. It just goes to the next line with no output. When I use something like echo "Linux is interesting", the text will appear. But not in the case when I use the top version? Should I be declaring a specific path? Other commands work, but the very top one does nothing?

Thank you all for your help or direction? Can anyone recommend a good reference guide as well?

Thanks,

Ziggs
 
Old 01-23-2018, 11:57 PM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,139

Rep: Reputation: 4122Reputation: 4122Reputation: 4122Reputation: 4122Reputation: 4122Reputation: 4122Reputation: 4122Reputation: 4122Reputation: 4122Reputation: 4122Reputation: 4122
Sorry - posted to the wrong thread. Ignore what I wrote ...

Last edited by syg00; 01-24-2018 at 12:11 AM.
 
Old 01-24-2018, 01:17 AM   #3
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,627

Rep: Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651
Quote:
I am using echo "test 1 2 3">~root/testfile.txt.
first you shold NOT!!! be running as root !!! for normal everyday things

try this as your NON root user
Code:
echo "test 1 2 3" > ~/testfile

cd ~/

nano testfile
 
Old 01-24-2018, 01:26 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,925

Rep: Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320
how do you know nothing happened?
 
Old 01-24-2018, 01:32 AM   #5
907_N8tiv
LQ Newbie
 
Registered: Aug 2017
Location: Anchorage, Alaska
Distribution: CentOS 7 64-bit
Posts: 13

Rep: Reputation: Disabled
Cool

Quote:
Originally Posted by ziggs View Post
I am using echo "test 1 2 3">~root/testfile.txt. Nothing happens. It just goes to the next line with no output. When I use something like echo "Linux is interesting", the text will appear.
This is a perfect, and easy question for me to answer… I'm currently studying "Linux System Administration Certification", the course material has gone over this…
I'm going to do my best to explain it, hopefully somebody with a bit more experience will chime in and correct me if I'm wrong.

Your second "echo command", is taking what you put in between quotation marks… And it's "redirecting", What you had put between the quotation marks and putting it into a text file That you named "testfile.txt", This newly created text file is in your root directory.

I'm assuming you did this as a root user, otherwise it would've told you… That you don't have permission to do this.
 
Old 01-24-2018, 04:25 AM   #6
fatmac
LQ Guru
 
Registered: Sep 2011
Location: Upper Hale, Surrey/Hants Border, UK
Distribution: Mainly Devuan, antiX, & Void, with Tiny Core, Fatdog, & BSD thrown in.
Posts: 5,503

Rep: Reputation: Disabled
Quote:
I am using echo "test 1 2 3">~root/testfile.txt. Nothing happens.
There is no directory named ~root - ~ = your home directory, whilst /root would put into the root directory if you have permission to write there.

(If you want to append to that file, rather than over write it, use >> instead of >)
 
1 members found this post helpful.
Old 01-24-2018, 10:05 AM   #7
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,733

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Quote:
Originally Posted by fatmac View Post
There is no directory named ~root
~root is the home directory of the user root, and is the equivalent of /root in RHEL and derivative distros

OP: as 907_N8tiv pointed out, your command is creating a file in /root named testfile.txt You can view it with
Code:
cat ~root/testfile.txt
Welcome, 907_N8tiv !

Last edited by scasey; 01-24-2018 at 10:44 AM.
 
1 members found this post helpful.
Old 01-24-2018, 04:53 PM   #8
ziggs
Member
 
Registered: Jan 2018
Posts: 37

Original Poster
Rep: Reputation: Disabled
using the ROOT user is required

Quote:
Originally Posted by John VV View Post
first you shold NOT!!! be running as root !!! for normal everyday things

try this as your NON root user
Code:
echo "test 1 2 3" > ~/testfile

cd ~/

nano testfile

Why should you not use it for everyday things?
 
Old 01-24-2018, 04:54 PM   #9
ziggs
Member
 
Registered: Jan 2018
Posts: 37

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by fatmac View Post
There is no directory named ~root - ~ = your home directory, whilst /root would put into the root directory if you have permission to write there.

(If you want to append to that file, rather than over write it, use >> instead of >)

So the instructions to write that command and get an output are incorrect? I should use >> instead?

Thank you
 
Old 01-24-2018, 05:15 PM   #10
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,740

Rep: Reputation: 5923Reputation: 5923Reputation: 5923Reputation: 5923Reputation: 5923Reputation: 5923Reputation: 5923Reputation: 5923Reputation: 5923Reputation: 5923Reputation: 5923
Lets start over...
The command
Code:
 echo "test 1 2 3"
Will display test 1 2 3 in the terminal which is also known as stdout.

Code:
echo "test 1 2 3" > filename
The ">" means redirect stdout to a file. Instead of displaying "test 1 2 3" in the terminal the string is written to a file called filename. This is why you do not see anything. The following link explains redirection.

www.tldp.org/LDP/abs/html/io-redirection.html

Code:
~root/testfile.txt
As stated it depends on the distribution but

~ is a shortcut for the current users home directory i.e /home/username
~root instead of expanding to /home/username/root expands to /root

We assume since you posted that you did not see anything or an error message which means you are logged in as root. As stated you should be logged in as a regular user and not root.

Last edited by michaelk; 01-24-2018 at 05:17 PM.
 
2 members found this post helpful.
Old 01-24-2018, 05:23 PM   #11
yancek
LQ Guru
 
Registered: Apr 2008
Distribution: Slackware, Ubuntu, PCLinux,
Posts: 10,534

Rep: Reputation: 2495Reputation: 2495Reputation: 2495Reputation: 2495Reputation: 2495Reputation: 2495Reputation: 2495Reputation: 2495Reputation: 2495Reputation: 2495Reputation: 2495
Quote:
Why should you not use it for everyday things?
There is no need to run as root/administrator for ordinary usage. The root/admin user is for modifying/managing the system. If you do an online search with 'dangers of running linux as root' or similar and you will find countless sites explaining all the pitfalls.

Why should you not use it for everyday things?dangers of running linux as root
 
Old 01-25-2018, 01:43 AM   #12
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,925

Rep: Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320
I still don't understand (but probably it is only me?). In post #4 I asked how OP "detected" that nothing happened - no answer. The statement
Quote:
It just goes to the next line with no output
probably true, but that definitely does not mean nothing happened at all.
How can you (we) give any answer without knowing the real (original) problem?
post #6 is false ~user is the home dir of user, so ~root is the home of root (usually /root) - this was already explained.
in post #9 using >> and/or > is not related to ~root at all, but probably related to the original issue. The question "to write that command and get an output are incorrect" is a bit strange, I don't know what kind of output do you expect? Why do you think it (any command) should print anything? Both > and >> are silent, will not print anything just in case of an error (and also depends on the redirection target).
"you should logged in as regular user, not root" is not related to the original question again, although it is recommended.
here are two links to understand redirection: http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-3.html, http://www.tldp.org/LDP/abs/html/io-redirection.html
And finally, executing the original command (as root) echo "test 1 2 3">~root/testfile.txt will definitely do something, it will create the specified file and the content will be "test 1 2 3". But if you execute this command again and again it will create the same file again and again with the same content again. But it is still "something", the command always create a new file - or drop an error message. You can check it by: ls -l ~root/testfile.txt.
 
Old 01-25-2018, 07:38 PM   #13
ziggs
Member
 
Registered: Jan 2018
Posts: 37

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
I still don't understand (but probably it is only me?). In post #4 I asked how OP "detected" that nothing happened - no answer. The statement probably true, but that definitely does not mean nothing happened at all.
How can you (we) give any answer without knowing the real (original) problem?
post #6 is false ~user is the home dir of user, so ~root is the home of root (usually /root) - this was already explained.
in post #9 using >> and/or > is not related to ~root at all, but probably related to the original issue. The question "to write that command and get an output are incorrect" is a bit strange, I don't know what kind of output do you expect? Why do you think it (any command) should print anything? Both > and >> are silent, will not print anything just in case of an error (and also depends on the redirection target).
"you should logged in as regular user, not root" is not related to the original question again, although it is recommended.
here are two links to understand redirection: http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-3.html, http://www.tldp.org/LDP/abs/html/io-redirection.html
And finally, executing the original command (as root) echo "test 1 2 3">~root/testfile.txt will definitely do something, it will create the specified file and the content will be "test 1 2 3". But if you execute this command again and again it will create the same file again and again with the same content again. But it is still "something", the command always create a new file - or drop an error message. You can check it by: ls -l ~root/testfile.txt.
Hello! Appreciate your help! Well, I can only assume nothing happened as it went back to the same starting line right under it. Unless it happened in the background where I cannot see? I was expecting it to output "1 2 3" testfile. I know I should not be using the root user, but this is how it it needs to be done. I greatly appreciate your feedback!! I will try what you stated and see what comes of it.

Thank you!! All of you who posted on the thread as well.
 
Old 01-25-2018, 07:51 PM   #14
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,740

Rep: Reputation: 5923Reputation: 5923Reputation: 5923Reputation: 5923Reputation: 5923Reputation: 5923Reputation: 5923Reputation: 5923Reputation: 5923Reputation: 5923Reputation: 5923
Yes, something happened but due to using redirection i.e. > the output was written to a file instead of the screen. If you look in the /root directory there should be a fIle called testfile.txt and it's content are test 1 2 3.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
luckyBackup Normal include instructions confusing fossildoc Linux - Newbie 2 09-17-2016 07:49 AM
Confusing launch6221 Linux - Newbie 10 01-12-2010 06:13 PM
this is so confusing!! theguitarness Linux - Newbie 5 03-07-2006 10:53 PM
so confusing c12ayon Programming 5 10-26-2003 11:52 PM
Very confusing rm Luc Linux - Newbie 3 11-04-2002 01:42 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration