The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
String substitution on find results inside exec/xargs myndcraft Shell Programming and Scripting 2 05-17-2008 02:36 PM
Difference between xargs and exec vibhor_agarwali UNIX for Dummies Questions & Answers 19 06-09-2005 07:54 AM
Help with xargs JimJim UNIX for Dummies Questions & Answers 4 02-08-2005 07:08 PM
use of xargs command kishorebabu UNIX for Dummies Questions & Answers 5 10-30-2003 02:53 PM
xargs jpprial UNIX for Dummies Questions & Answers 4 09-17-2001 08:29 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-28-2008
malaymaru malaymaru is offline
Registered User
  
 

Join Date: May 2005
Posts: 54
MV files with xargs or -exec

Hi

I need to move multiple (say 10 files) from one location to another location. My selection would be like this...

ls -ltr *.arc | head ---> Need to move top 10 files with single command without iterating in loop. I know we can move files like this with find command but not sure if I can move top 10 files in any directory to another one.

Any help would be appreciated.

- Malay
  #2 (permalink)  
Old 04-28-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,643
Code:
find . -name '*.arc' | head ...
but it won't necessarily find the top ten biggest without an extra pipe to sort.
Are you thinking about performance? You've got a decent solution already.
  #3 (permalink)  
Old 04-28-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
Write a script "vm" which works like mv but accepts the destination as the first argument. Then ls -ltr *.arc | xargs -n 10 vm destination
  #4 (permalink)  
Old 04-28-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,794
If you have zsh:

Code:
mv -- *.arc(Om[1,10]) dest
  #5 (permalink)  
Old 04-28-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,643
Quote:
but not sure if I can move top 10 files in any directory to another one.
Modern versions of UNIX allow mv to operate across filesystems - ie., you can move a file from anywhere to anywhere else you have permissions.

Check your mv man page to see what it says about moving file across filesystem boundaries.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



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


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0