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 > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
need to move find results pimentelgg Shell Programming and Scripting 9 12-20-2007 06:00 PM
Find, Append, Move & Rename Multiple Files Trapper Shell Programming and Scripting 5 08-30-2007 07:39 AM
Find, make and move file based on username Helmi UNIX for Dummies Questions & Answers 5 04-19-2007 09:49 PM
How to do a move in FTP steiner Shell Programming and Scripting 3 06-29-2005 11:15 AM
find move saswerks Shell Programming and Scripting 4 02-24-2005 04:48 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-24-2005
natasha80 natasha80 is offline
Registered User
  
 

Join Date: Jun 2005
Posts: 1
find and move

Hello I am new to this board.

I was looking for a one line command to find the oldest 10,000 files in a directory and move them.

I tried such things as:

find . -type f | ls -ltr | head -n 10000 -exec mv {} directory/ \;

find . -type f | ls -ltr | head -n 50 | xargs mv directory/ \;

I could create a list and find the 10001 st file and use ! -newer or a for loop but there must be a one line solution.


Thanks in advance

Natasha
  #2 (permalink)  
Old 06-26-2005
DogDay's Avatar
DogDay DogDay is offline
Registered User
  
 

Join Date: Jun 2005
Location: /dev/null
Posts: 83
I think your logic is flawed with your find example.


Code:
find . -type f | ls -ltr | head -n 10000 -exec mv {} directory/ \;
This runs the 'ls -ltr' command on ONE FILE then it runs 'head -n 10000' on that ONE FILE. And since you've passed the rest of your find command arguments (the '-exec mv {} directory/ \;' part) are being passed as arguments to the head command you're getting nowhere fast.

I suggest you pick a cutoff date for old files in that directory. Then use the find command to move those.

Something like this:

Code:
/usr/bin/find . -mtime +130 -type f -xdev -exec mv {} /some/other/dir/  \;
So here we've moved all files that haven't been modified in at least 130 days to /some/other/dir/.

The '-xdev' prevents us from searching other filesystems within the current mountpoint. If you wish to search those filesystems then simply remove the '-xdev'.

Please test your command with a different variation of the find example above before you run this on your live system to make sure it does what you expect.

Something like this perhaps:

Code:
/usr/bin/find . -mtime +130 -type f -xdev -ls
Simply shows you which files meet the criteria you specified in the find command.

And then run 'man find' and read all that.

Good Luck.
  #3 (permalink)  
Old 08-25-2005
rosh0623 rosh0623 is offline
Registered User
  
 

Join Date: Jul 2005
Posts: 29
Erroring out ~~

I'm using this following command but its erroring out !!
find /home/xxx/yyy/ . -mtime -7 -type f -exec mv {} /home/xxx/yyy/zzz/

" find: 0652-018 An expression term lacks a required parameter. " -- This is the error i get... My basic requirement here is to move files which are 7 days old !!...

I have tried at the prompt also giving same command but same error is popping up. please suggest what might be the problem here..
  #4 (permalink)  
Old 08-25-2005
SemiOfCol SemiOfCol is offline
Registered User
  
 

Join Date: Jun 2005
Posts: 18
don't forget the \; at the end of the exec command. It always errors out unless it is there. You also have an extra . in the command.

find /home/xxx/yyy/ -mtime -7 -type f -exec mv {} /home/xxx/yyy/zzz/ \;
  #5 (permalink)  
Old 08-25-2005
rosh0623 rosh0623 is offline
Registered User
  
 

Join Date: Jul 2005
Posts: 29
still erroring

Nopes still erroring out !!!!...
find: 0652-018 An expression term lacks a required parameter.
  #6 (permalink)  
Old 08-26-2005
bakunin bakunin is offline Forum Staff  
Bughunter Extraordinaire
  
 

Join Date: May 2005
Location: In the leftmost byte of /dev/kmem
Posts: 1,628
I might be wrong, but I don't think /usr/bin/find is needed to accomplish what OP wanted:

ls -lrt (or, alternatively "-1rt")

gives a list of files sorted ascendingly by modification date, therefore:

ls -1rt | head -10000 | while read file ; do mv $file /somewhere/else ; done

should do the trick. If there are subdirectories and these should be excluded things get a bit more complicated. Replace the "ls -1rt" above with:

ls -lrt | grep "^-" | sed 's/[<space><tab>][<space><tab>]*/<space>/g' | cut -d' ' -f9

I concede, the second is a bit of a stretch of a "one-liner". Replace "<space>" and "<tab>" with literal tabs and spaces respectively.

bakunin
  #7 (permalink)  
Old 11-04-2008
efittery efittery is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 1
why is "find" SUPER fast on ubuntu and not on cygwin

I have a directory tree on my ubuntu which consists of 15000 files and 8Gig of space.

At the command line, I put in:

time find "*.gz"

and it comes back with a response in less than 0.1 seconds.

I do the same thing on my cygwin system and it takes much longer.

My personal machine is much faster. Quad core machine, etc...

Unless I am fooling myself, I am seeing 2000 to 10000 times faster.

any thoughts would be appreciated.
Closed Thread

Bookmarks

Tags
mtime

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 01:55 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
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