LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 07-24-2012, 07:25 PM   #1
teletalky
LQ Newbie
 
Registered: Jul 2012
Posts: 8

Rep: Reputation: Disabled
Problems using 'cat' command on centOS.


Hi,

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
 
Old 07-24-2012, 07:27 PM   #2
sharadchhetri
Member
 
Registered: Aug 2008
Location: INDIA
Distribution: Redhat,Debian,Suse,Windows
Posts: 179

Rep: Reputation: 23
Quote:
Originally Posted by teletalky View Post
Hi,

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.
 
Old 07-24-2012, 08:10 PM   #3
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
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).
 
Old 07-24-2012, 09:40 PM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,988

Rep: Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182
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.
 
2 members found this post helpful.
Old 07-24-2012, 09:53 PM   #5
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,085
Blog Entries: 28

Rep: Reputation: 6086Reputation: 6086Reputation: 6086Reputation: 6086Reputation: 6086Reputation: 6086Reputation: 6086Reputation: 6086Reputation: 6086Reputation: 6086Reputation: 6086
Thanks, Grail! That was a new one on me.
 
Old 07-24-2012, 09:59 PM   #6
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
Quote:
Originally Posted by frankbell View Post
Thanks, Grail! That was a new one on me.
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.
 
Old 07-24-2012, 11:06 PM   #7
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,988

Rep: Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182
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)
 
Old 07-25-2012, 01:12 PM   #8
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
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.
 
1 members found this post helpful.
Old 07-25-2012, 07:45 PM   #9
teletalky
LQ Newbie
 
Registered: Jul 2012
Posts: 8

Original Poster
Rep: Reputation: Disabled
I got it. Thank you all for the help.
 
Old 07-26-2012, 03:24 AM   #10
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,988

Rep: Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182
Please mark as SOLVED once you have a solution.
 
Old 07-26-2012, 07:46 PM   #11
sharadchhetri
Member
 
Registered: Aug 2008
Location: INDIA
Distribution: Redhat,Debian,Suse,Windows
Posts: 179

Rep: Reputation: 23
Quote:
Originally Posted by grail View Post
Please mark as SOLVED once you have a solution.
grail gave rt. way to use cat command.
with ctrl+z it will go backend but stopped also.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Makefile:How to use cat command Ashok_mittal Linux - Newbie 1 01-18-2008 08:38 AM
CAT Command ouncya Linux - Newbie 11 08-26-2007 12:48 AM
Cat and Sed Command Help. vidyashankara Linux - General 22 06-23-2006 02:32 PM
cat command juanb Linux - Newbie 4 08-19-2004 12:14 PM
cat Command Moeses Linux - General 1 06-20-2002 04:27 AM

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

All times are GMT -5. The time now is 07:56 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