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 following a tutorial in which I have to use the cat command to create the module.conf file. However, each time I type: $ cat >> /etc/asterisk/modules.conf, the cursor just starts a new line and nothing else happens. Please help, I am new to linux.
I am following a tutorial in which I have to use the cat command to create the module.conf file. However, each time I type: $ cat >> /etc/asterisk/modules.conf, the cursor just starts a new line and nothing else happens. Please help, I am new to linux.
Ernie
if you want to create new empty file use below command.
touch /etc/asterisk/modules.conf
or if you only want to use cat >> /etc/asterisk/modules.conf . after hitting the command press CTRL+ z .
file will be created
Last edited by sharadchhetri; 07-24-2012 at 07:29 PM.
What tutorial is this? cat is used to dump the contents of a file to the terminal, it's not used to create a new file (you should use touch, as sharadchhetri mentioned).
Actually I disagree. Cat may be used to create the contents of a file using the method mentioned. In fact it is quite common in the (C)LFS world as an editor may not yet be installed, example here (section 10.7.3)
Code:
$ cat >> /etc/asterisk/modules.conf
Whatever you type here,
including new lines, will be added
to the file.
After hitting enter on this line you need to press Ctrl-d to advise the entry is complete
If you look at the link I provided, the alternative to requiring ctrl-d is:
Code:
$ cat >> /etc/asterisk/modules.conf <<EOF
Enter data
EOF
In this instance the final EOF (this can be any string) must be at the start of the last line and the only thing on the line.
Me too, though I don't really understand the point of using cat for this vs using echo or some other more "common" approach. I guess it's just another one of those cases where there are 100 different ways to do some task, and which one is best just depends on who you ask.
Always different horses for courses, however, on the subject of cat v echo in this scenario:
Code:
$ cat > tempfile <<EOF
"If we start with double (") quotes"
'and change over to single (')'
It would prove painful and difficult to use echo for both " and '
EOF
You can also quote the EOF variable to prevent parameter expansion if required (see here documents)
cat simply takes all the input given to it from sdtin or a list of files, and prints it to stdout. This has the effect of "concatenating" all input into one continuous stream.
It's traditional uses are to combine multiple files into one (hence the name), as a quick way to print out the contents of a file for reading, and to redirect user input into files or commands, as grail demonstrated. One thing you should generally not use it for, however, is to feed the contents of a single file into another command (the Useless Use Of Cat). Just use the shell's "<" redirection for that, if the command in question can't read files directly.
There are also a handful of useful input filtering options built into it. cat -A will display all non-printing characters, for example, and cat -n will prefix the output with line numbers.
In the OP code, cat wasn't given any files to read, or any scripted form of stdin input (such as the heredocs demonstrated above), so it just sat there listening to stdin for something to print. If you had typed something into the shell then cat would have printed it to stdout (redirected to the file in this case), and continued doing so until it received an EOF (end-of-file) signal or was otherwise externally terminated.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.