Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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.
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.
~ 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.
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
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.