Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 07-06-2012
Registered User
 
Join Date: Jun 2012
Posts: 19
Thanks: 5
Thanked 0 Times in 0 Posts
look for file size greater than "0" of specific pattern and move those to another directory

Hi ,
i have some files of specific pattern ...i need to look for files which are having size greater than zero and move those files to another directory..

Ex...
abc_0702,
abc_0709,
abc_782
abc_1234 ...etc

need to find out which is having the size >0 and move those to target directory..

Thanks in advance..

Siva Santosh
Sponsored Links
    #2  
Old 07-06-2012
elixir_sinari's Avatar
Gotham Knight
 
Join Date: Mar 2012
Location: India
Posts: 1,370
Thanks: 87
Thanked 476 Times in 456 Posts

Code:
man test

Sponsored Links
    #3  
Old 07-06-2012
methyl methyl is offline Forum Staff  
Moderator
 
Join Date: Mar 2008
Posts: 6,388
Thanks: 286
Thanked 668 Times in 640 Posts
To get you started, first check that you can find the files with a command like this:

Code:
find /dir/subdir -type f -name 'abc_*' -size +0 -print

Please post you Operating System and version and what Shell you use.

As @elixir_sinari implies there could be a pure Shell approach using file pattern matching and the test -s command . If you need to search the tree, find is preferred.

I you need further help, please remember to describe your directory tree.
    #4  
Old 07-06-2012
Registered User
 
Join Date: Jul 2012
Location: Chennai
Posts: 453
Thanks: 34
Thanked 57 Times in 55 Posts
A small correction to the end would help.


Code:
 
find /dir/subdir -type f -name 'abc_*' -size +0 -exec mv {} target_dir \;


Last edited by PikK45; 07-06-2012 at 03:28 PM.. Reason: bad code
The Following User Says Thank You to PikK45 For This Useful Post:
dssyadav (07-06-2012)
Sponsored Links
    #5  
Old 07-06-2012
methyl methyl is offline Forum Staff  
Moderator
 
Join Date: Mar 2008
Posts: 6,388
Thanks: 286
Thanked 668 Times in 640 Posts
@PikK45
Psychic post. You must know the O/P's directory structure.
The Following User Says Thank You to methyl For This Useful Post:
dssyadav (07-06-2012)
Sponsored Links
    #6  
Old 07-06-2012
Registered User
 
Join Date: Jun 2012
Posts: 19
Thanks: 5
Thanked 0 Times in 0 Posts
Thank you all,
Sponsored Links
    #7  
Old 07-07-2012
Registered User
 
Join Date: Jul 2012
Location: Chennai
Posts: 453
Thanks: 34
Thanked 57 Times in 55 Posts
@methyl
I couldn't get you!!
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Difference in file size between "ls -l" and "du -a" jgt SuSE 1 06-04-2012 08:27 AM
replace "," with "." only in specific columns of a file? Unilearn UNIX for Dummies Questions & Answers 8 08-08-2011 12:06 PM
awk command to replace ";" with "|" and ""|" at diferent places in line of file shis100 Shell Programming and Scripting 7 03-16-2011 08:59 AM
Delete files older than "x" if directory size is greater than "y" JamesCarter Shell Programming and Scripting 4 02-11-2010 07:41 AM
"sed" to check file size & echo " " to destination file jockey007 Shell Programming and Scripting 7 04-28-2009 02:08 AM



All times are GMT -4. The time now is 08:54 AM.