LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 10-23-2014, 10:46 AM   #1
sumncguy
Member
 
Registered: Jun 2013
Posts: 71

Rep: Reputation: Disabled
Tar - find editors and add to tar archive


I think I mentioned once before that I have been working at a nix command line for some time. Decided to take the LPI essentials then sysadmin 1 to fill in blanks then cert.

The question is given in the attachment.

My solution that doesn't quite match the "single command" requirement.

Code:
#!/bin/bash
apropos editor | cut -d" " -f1 | sort -u | while read x junk
 do
  which $x 2>/dev/null >> elist 
done 
tar -zcvf all_editors.tar $(<elist)
sleep 2
echo
tar -tf all_editors.tar
The instructions say a single command.
1. Not sure how to find editors without using which. Locate isnt very pretty.
2. then Im not sure of anyother way to find the location of each item without puttting it through a loop and bumping each againsts which.

Which is basically what I did in the script.
Attached Thumbnails
Click image for larger version

Name:	questioncapture.JPG
Views:	6
Size:	77.6 KB
ID:	16728  
 
Old 10-23-2014, 11:06 AM   #2
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 3,614

Rep: Reputation: 1576Reputation: 1576Reputation: 1576Reputation: 1576Reputation: 1576Reputation: 1576Reputation: 1576Reputation: 1576Reputation: 1576Reputation: 1576Reputation: 1576
You're aware that you can write the script you already have as a single "rather complex" command line, right?
Code:
apropos editor | cut -d" " -f1 | sort -u | while read x junk; do which $x 2>/dev/null >> elist; done; tar -zcvf all_editors.tar $(<elist)
Note that the challenge was for a single command line, not necessarily a single command.

FWIW, you can make it look more like a single command:
Code:
tar -zcvf all_editors.tar $(which $(apropos editor | cut -d" " -f1 | sort -u) 2>/dev/null )
That breaks slightly on my system because "vi" is actually an alias "vi='vim'". That can be fixed by using "type -path" in place of "which".

Last edited by rknichols; 10-23-2014 at 11:42 AM. Reason: add FWIW
 
1 members found this post helpful.
Old 10-23-2014, 11:10 AM   #3
sumncguy
Member
 
Registered: Jun 2013
Posts: 71

Original Poster
Rep: Reputation: Disabled
Well .. I suppose .. its open to interpretation. Yeah .. Im aware of the inline script "feature".
 
Old 10-23-2014, 11:40 AM   #4
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 3,614

Rep: Reputation: 1576Reputation: 1576Reputation: 1576Reputation: 1576Reputation: 1576Reputation: 1576Reputation: 1576Reputation: 1576Reputation: 1576Reputation: 1576Reputation: 1576
See my edited addition for what is as close to a "single command" as you are likely to achieve. You have to run tar, and finding all the editors is not something tar can do on its own.
 
1 members found this post helpful.
Old 10-26-2014, 09:05 PM   #5
sumncguy
Member
 
Registered: Jun 2013
Posts: 71

Original Poster
Rep: Reputation: Disabled
thanks for the input rk ..
 
  


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
Error in TAR - tar: GNU features wanted on incompatible archive format. kuldeep.k Linux - General 3 08-14-2009 12:09 PM
tar this does not look like a tar archive exit depalyed from previous error tasay Linux - Software 1 07-01-2009 04:34 PM
Piping tar bzcat to add a file to a tar.bz2 archive DaveQB Linux - Software 0 06-02-2008 09:28 PM
BackUp & Restore with TAR (.tar / .tar.gz / .tar.bz2 / tar.Z) asgarcymed Linux - General 5 12-31-2006 03:53 AM
Tar gives error when creating a tar file archive davidas Linux - Newbie 10 04-13-2004 01:35 AM

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

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