LinuxQuestions.org
Review your favorite Linux distribution.
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, 06: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, 06: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 06:29 PM.
 
Old 07-24-2012, 07:10 PM   #3
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,454

Rep: Reputation: 2052Reputation: 2052Reputation: 2052Reputation: 2052Reputation: 2052Reputation: 2052Reputation: 2052Reputation: 2052Reputation: 2052Reputation: 2052Reputation: 2052
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, 08:40 PM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,494

Rep: Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867
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, 08:53 PM   #5
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Debian, Mageia, and whatever VMs I happen to be playing with
Posts: 12,140
Blog Entries: 14

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

Rep: Reputation: 2052Reputation: 2052Reputation: 2052Reputation: 2052Reputation: 2052Reputation: 2052Reputation: 2052Reputation: 2052Reputation: 2052Reputation: 2052Reputation: 2052
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, 10:06 PM   #7
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,494

Rep: Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867
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, 12:12 PM   #8
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959
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, 06: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, 02:24 AM   #10
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,494

Rep: Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867
Please mark as SOLVED once you have a solution.
 
Old 07-26-2012, 06: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 07:38 AM
CAT Command ouncya Linux - Newbie 11 08-25-2007 11:48 PM
Cat and Sed Command Help. vidyashankara Linux - General 22 06-23-2006 01:32 PM
cat command juanb Linux - Newbie 4 08-19-2004 11:14 AM
cat Command Moeses Linux - General 1 06-20-2002 03:27 AM


All times are GMT -5. The time now is 02:26 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration