• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Himai Minh
  • Carey Brown
  • salvin francis

cat command in unix

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is this a valid command?
cat filenum1 > cat filenum2. Supposing file1 and file2 are already there. What will this command do?
 
Marshal
Posts: 3250
487
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Rish Dave wrote:What will this command [line] do?


Why not give it a try and see what happens?

    cat    will concatenate the contents of a number of files (if more than one is specified), and then print the contents to standard output
      >    will cause the output of a command (which would normally go to standard output) to be redirected to a file

 
Bartender
Posts: 1075
19
Mac OS X IntelliJ IDE Oracle Spring VI Editor Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah try;

cat filenum1 > filenum2

without the second "cat" that you prefixed filenum2 with.  

While you're on you may as well learn about redirection.  That would be sending the output of a command into the input of a second command using these operators ">, >>, |".  
Is a powerful feature of unix shell commands.    
 
Saloon Keeper
Posts: 22779
153
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Redirection is handled by the command shell, but most command shells will treat



As though it had been written



Which is also equivalent to



In all 3 cases, filenum1 and filenum2 data will be concatenated and output to stdout, which has been redirected to go to a file named "cat". Redirection occurs out-of-band on most shell command lines, so the exact location of the redirection elements doesn't really matter. Although for sanity's sake, we usually do it either before or (more commonly) after the actual command arguments.

And now you know where the "cat" command got its name.
 
Doe, a deer, a female deer. Ray, a pockeful of sun. Me, a name, I call my tiny ad ...
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic