LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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 04-24-2016, 02:30 PM   #1
PleaseHelpMeUnderstand
Member
 
Registered: Apr 2016
Posts: 32

Rep: Reputation: 0
Capturing output of command


If I want to write a command that would capture the output of the command: ls -l /home/newbie to a file named: newbielisting in my current directory; would this command be ok to use?
ls –l /home/newbie >> newbielisting

Last edited by PleaseHelpMeUnderstand; 04-24-2016 at 02:34 PM.
 
Old 04-24-2016, 03:35 PM   #2
jailbait
LQ Guru
 
Registered: Feb 2003
Location: Virginia, USA
Distribution: Debian 12
Posts: 8,337

Rep: Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548
Yes, that will work. Each time that you run the command it will add the latest listing to the end of newbielisting.

-------------------------
Steve Stites
 
1 members found this post helpful.
Old 04-24-2016, 11:24 PM   #3
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,306
Blog Entries: 3

Rep: Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720
Quote:
Originally Posted by jailbait View Post
it will add the latest listing to the end of newbielisting.
The >> will add to the target file and a single > by itself will simply replace the whole target file.
The > and >> are "redirects" which can get quite fancy as you get more familiar with them.
 
1 members found this post helpful.
Old 04-25-2016, 11:42 AM   #4
PleaseHelpMeUnderstand
Member
 
Registered: Apr 2016
Posts: 32

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Turbocapitalist View Post
The >> will add to the target file and a single > by itself will simply replace the whole target file.
The > and >> are "redirects" which can get quite fancy as you get more familiar with them.
Is there a right or wrong to > and >> in my case?
 
Old 04-25-2016, 11:47 AM   #5
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,306
Blog Entries: 3

Rep: Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720
If you want the file to contain only one set then > is right, because it will overwrite the target file each time.

If you want the file to keep growing then >> is right, because it will keep appending the new output to the target file each time.

Your choice, depending on what you want to do.
 
1 members found this post helpful.
  


Reply



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
Capturing the Output of the command SoLostNConfused Linux - Newbie 3 04-19-2016 10:09 AM
Capturing output of top command RHCE_ran Linux - Enterprise 2 05-15-2015 08:58 PM
[SOLVED] capturing output of command in vim editor sumeet inani Linux - Newbie 11 03-22-2011 02:01 AM
Capturing Output from net ads dns register Command jfmorales Linux - General 2 04-07-2010 03:07 PM
Capturing output from background FTP command Lazypete Linux - Server 6 05-22-2008 10:41 AM

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

All times are GMT -5. The time now is 08:19 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
Open Source Consulting | Domain Registration