LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 06-04-2015, 08:12 AM   #1
mcai8rw2
LQ Newbie
 
Registered: Dec 2011
Posts: 15

Rep: Reputation: Disabled
Best practices to get one linux command to do something else afterwards?


Hello all,

As title says.... whats the best way of getting linux to do another command after the first one?

e.g. Say I type "find . -iname "*.dll" this displays a list of all the dlls in a folder/subdirectory. ... then i wanted to copy these files, or du them, or other commands.

The three things i am aware of is:

Pipe |
awk
xargs

Which one is the most useful/standard/best practice to use?

Thanks
 
Old 06-04-2015, 08:33 AM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: Sutton, MA. USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu
Posts: 4,087
Blog Entries: 10

Rep: Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520
Specifically with the find command there's an -exec option:
Code:
find . -name "*.c" -exec cp {} /home/user/backup-sources/. \;
Check the manual page on find for deeper information.

And yes, you can use pipe as well, say you wish to grep and then refine that output even more, although there are better ways to do this:
Code:
$ grep ab *.txt
search.txt:absolute
sedtest.txt:abc/123
sedtest.txt:abc 123
$ grep ab *.txt | grep 123
sedtest.txt:abc/123
sedtest.txt:abc 123
$
 
Old 06-05-2015, 05:41 PM   #3
joec@home
Member
 
Registered: Sep 2009
Location: Galveston Tx
Posts: 290

Rep: Reputation: 70
Just adding to what was said, "for" "do" loops are very useful, constantly using these. Basic example of looping the data output from ls.

[code]
for i in $(ls /) ;do echo $i ;done
[code]
 
  


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
[SOLVED] Command Line Best Practices Pedagogic Material Recommendations Needed SamShovel Linux - Newbie 5 05-22-2013 06:52 PM
best practices for Linux user authentication wlandymore Linux - Security 1 04-18-2013 12:34 AM
Best practices for updating to new Linux version? SlowCoder Linux - Newbie 9 04-05-2007 07:33 PM
LXer: Embedded Linux best practices LXer Syndicated Linux News 0 11-14-2006 04:54 AM
Common practices in Linux SoliTear Linux - General 5 01-10-2005 12:43 AM


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