Please help list/find files greater 1G move to different directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Please help list/find files greater 1G move to different directory
# 1  
Old 04-01-2014
Please help list/find files greater 1G move to different directory

I have have 6 empty directory below. I would like write bash scipt if any files less "1000000000" bytes then move to "/export/home/mytmp/final" folder first and any files greater than "1000000000" bytes then move to final1, final2, final3, final4, final4, final5 and that depend see how many files, but I only want ONE file go into 1 directory. I run the command below with great than "1000000000" bytes and see 3 files then that 3 files should go 3 folders (final1, final2 and final3) only. If see more that 6 or 8 files greater than "1000000000" bytes then should go last folder "final5" . Is some kinda script loop through or command to do this? Please help with this task. Thanks
Code:
/export/home/mytmp/final  <= less "1000000000"
/export/home/mytmp/final1 <= greater "1000000000" but require only file move a
/export/home/mytmp/final2
/export/home/mytmp/final3
/export/home/mytmp/final4
/export/home/mytmp/final5
 
/export/home/mytmp/test1> ls -ltr test*.txt
-rwxrwxr-x   1 ca7prod  ftpusers 1073741824 Mar  4 11:14 test3.txt
-rwxrwxr-x   1 ca7prod  ftpusers 524288000 Mar  4 11:26 test4.txt
-rwxrwxr-x   1 ca7prod  ftpusers 629145600 Mar  4 11:28 test5.txt
-rwxrwxr-x   1 ca7prod  ftpusers 734003200 Mar  4 23:47 test7.txt
-rw-rw-r--   1 ca7prod  ftpusers      14 Mar 12 14:43 test.txt
-rw-------   1 ca7prod  ftpusers 52428800 Mar 31 15:24 test2.txt
-rw-rw-r--   1 ca7prod  ftpusers 104857600 Mar 31 15:27 test8.txt
-rw-rw-r--   1 ca7prod  ftpusers 1178599424 Mar 31 15:31 test9.txt
-rw-------   1 ca7prod  ftpusers 104857600 Mar 31 15:32 test10.txt
-rwxrwxr-x   1 ca7prod  ftpusers 104857600 Mar 31 15:37 test6.txt
-rw-rw-r--   1 ca7prod  ftpusers 157286400 Mar 31 15:38 test1.txt
-rw-rw-r--   1 ca7prod  ftpusers 1335885824 Mar 31 15:40 test11.txt
/export/home/mytmp/test1> ls -ltr test*.txt | awk '{if ($5 < 1000000000) print $9}' -exec mv {} /export/home/mytmp/final \;
test4.txt
test5.txt
test7.txt
test.txt
test2.txt
test8.txt
test10.txt
test6.txt
test1.txt
/export/home/mytmp/test1> ls -ltr test*.txt | awk '{if ($5 > 1000000000) print $9}' -exec mv {} /export/home/mytmp/xxx \;
test3.txt
test9.txt
test11.txt

Please with this script
/export/home/mytmp/test1> cat test.ksh
Code:
 
#!/bin/ksh
cd /export/home/mytmp/test1
###############################################################################
# Any files less than 1G move to final
###############################################################################
ls -ltr test*.txt | awk '{if ($5 < 1000000000) print $9}' -exec mv {} /export/home/mytmp/final \;
###############################################################################
# Any files greater than 1G move to final1, final2, final3, final4, final4, final5
###############################################################################
ls -ltr test*.txt | awk '{if ($5 > 1000000000) print $9}' |sed q | xxxxx bla bla
find /export/home/mytmp/test1 bla bla


Last edited by dotran; 04-01-2014 at 01:40 PM.. Reason: code tags please, not Quotes
# 2  
Old 04-01-2014
have a further look at the options of the find command. There is one about size that should be very useful.

Have a go and let us know how you get on with the code you use (so other people can refer to it in future)



I hope that this helps,
Robin
# 3  
Old 04-01-2014
Can you give some example what's the find command to do this? Thanks
# 4  
Old 04-01-2014
Quote:
Originally Posted by dotran
I have have 6 empty directory below. I would like write bash scipt if any files less "1000000000" bytes then move to "/export/home/mytmp/final" folder first and any files greater than "1000000000" bytes then move to final1, final2, final3, final4, final4, final5 and that depend see how many files, but I only want ONE file go into 1 directory. I run the command below with great than "1000000000" bytes and see 3 files then that 3 files should go 3 folders (final1, final2 and final3) only. If see more that 6 or 8 files greater than "1000000000" bytes then should go last folder "final5" . Is some kinda script loop through or command to do this? Please help with this task. Thanks
... ... ...
I'm confused.
  1. What do you want to do with files that contain exactly 1000000000 bytes?
  2. If you have 6, 7, or 8 files that contain more than 1000000000 bytes, where should they go? (You have said that the 1st goes in final1; the 2nd goes in final2; the 3rd goes in final3; the 4th goes in final4; the 5th, the 9th, and any more files after that go in final5. But, you never specified a destination for the 6th, 7th, and 8th files that meet your criteria.)
  3. You also said you want a bash script, but the first line of your sample code is #!/bin/ksh Do you really want a bash script, or do you want a Korn shell script?
  4. What operating system and release are you using?
# 5  
Old 04-01-2014
  1. What do you want to do with files that contain exactly 1000000000 bytes? Then move to final1, final2...etc. But only want 1 file go ino 1 directory.
  2. If you have 6, 7, or 8 files that contain more than 1000000000 bytes, where should they go? (You have said that the 1st goes in final1; the 2nd goes in final2; the 3rd goes in final3; the 4th goes in final4; the 5th, the 9th, and any more files after that go in final5. But, you never specified a destination for the 6th, 7th, and 8th files that meet your criteria.) Let say I see 8 or 9 big files then last 3 or 4 files move to last folder "final5". Hope explain correct here. Thanks
  3. You also said you want a bash script, but the first line of your sample code is #!/bin/ksh Do you really want a bash script, or do you want a Korn shell script? I mean use #!/usr/bin/bash or #!/bin/ksh and I don't know any different here.
  4. What operating system and release are you using? SunOS Test1 5.10 Generic_147440-25 sun4v sparc SUNW,T5240
# 6  
Old 04-01-2014
You could try something like:
Code:
#!/bin/ksh
# cd /export/home/mytmp/test1
cld=0				# Current large directory
cutoff=${1:-1000000000}		# Min file size to be considered "big"
lt1G_d=/export/home/mytmp/final	# Directory to receive "small" files
ge1G_d_base="$lt1G_d"		# Base directory name to receive "big" files
ge1G_d_cnt=5			# Number of directories for "big" files

printf "Prepare to move text files smaller than %s bytes to directory:\n" \
	"$cutoff"
printf "\t%s\n" "$lt1G_d"
printf "and larger text files to directories:\n\t%s1 - %s%d\n" \
	"$ge1G_d_base" "$ge1G_d_base" "$ge1G_d_cnt"
ls -ltr *.txt | while read x x x x size x x x file
do	if [ "$size" -ge "$cutoff" ]
	then	echo mv -- "$file" \
			"$ge1G_d_base"$((cld = cld + 1 - (cld == ge1G_d_cnt)))
	else	echo mv -- "$file" "$lt1G_d"
	fi
done

If the output you get from this looks like the commands you want the script to execute, remove the echo in both places where it appears in the script and run it again.
# 7  
Old 04-01-2014
Thanks Mr Don C. It's really nice code and I still can't figure out why not move.

Quote:
#!/bin/ksh
cd /export/home/mytmp/test1
cld=0 # Current large directory
cutoff=${1:-1000000000} # Min file size to be considered "big"
lt1G_d=/export/home/mytmp/final # Directory to receive "small" files
ge1G_d_base="$lt1G_d" # Base directory name to receive "big" files
ge1G_d_cnt=5 # Number of directories for "big" files
printf "Prepare to move text files smaller than %s bytes to directory:\n" \
"$cutoff"
printf "\t%s\n" "$lt1G_d"
printf "and larger text files to directories:\n\t%s1 - %s%d\n" \
"$ge1G_d_base" "$ge1G_d_base" "$ge1G_d_cnt"
ls -ltr test*.txt | while read x x x x size x x x file
do if [ "$size" -ge "$cutoff" ]
then echo mv "$file" \
"$ge1G_d_base"$((cld = cld + 1 - (cld == ge1G_d_cnt)))
else echo mv "$file" "$lt1G_d"
fi
done
I run the code but somehow go to folder final, final1, final2....etc and didn't see the files move at all. I am missing something here. Could please help again? Thanks
Quote:
Prepare to move text files smaller than 1000000000 bytes to directory:
/export/home/mytmp/final
and larger text files to directories:
/export/home/mytmp/final1 - /export/home/mytmp/final5
mv test3.txt /export/home/mytmp/final1
mv test4.txt /export/home/mytmp/final
mv test5.txt /export/home/mytmp/final
mv test7.txt /export/home/mytmp/final
mv test.txt /export/home/mytmp/final
mv test2.txt /export/home/mytmp/final
mv test8.txt /export/home/mytmp/final
mv test9.txt /export/home/mytmp/final2
mv test10.txt /export/home/mytmp/final
mv test6.txt /export/home/mytmp/final
mv test1.txt /export/home/mytmp/final
mv test11.txt /export/home/mytmp/final3
---------- Post updated at 06:05 PM ---------- Previous update was at 06:00 PM ----------

Wow....sorry Mr Don C. It's really worked. I didn't remove echo and run the code work like a charm. Thanks very much....for your script expert.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

List files with date, create directory, move to the created directory

Hi all, i have a folder, with tons of files containing as following, on /my/folder/jobs/ some_name_2016-01-17-22-38-58_some name_0_0.zip.done some_name_2016-01-17-22-40-30_some name_0_0.zip.done some_name_2016-01-17-22-48-50_some name_0_0.zip.done and these can be lots of similar files,... (6 Replies)
Discussion started by: charli1
6 Replies

2. UNIX for Dummies Questions & Answers

Find a list of files in directory, move to new, allow duplicates

Greetings. I know enough Unix to be dangerous (!) and know that there is a clever way to do the following and it will save me about a day of agony (this time) and I will use it forever after! (many days of agony saved in the future)! Basically I need to find any image files (JPGs, PSDs etc)... (5 Replies)
Discussion started by: Clyde Lovett
5 Replies

3. Shell Programming and Scripting

Move files in a list to another directory

I have a number of files in a directory that can be grouped with something like "ls | grep SH2". I would like to move each file in this list to another directory. Thanks (4 Replies)
Discussion started by: kg6iia
4 Replies

4. Shell Programming and Scripting

Find files greater than a particular date in filename.

I need a unix command which will find all the files greater that a particular date in the file name. say for example I have files like(filenaming cov : filename.YYDDMMSSSS.txt) abc.201206015423.txt abc.201207013456.txt abc.201202011234.txt abc.201201024321.txt efg.201202011234.txt... (11 Replies)
Discussion started by: lijjumathew
11 Replies

5. UNIX for Dummies Questions & Answers

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..... (7 Replies)
Discussion started by: dssyadav
7 Replies

6. UNIX for Dummies Questions & Answers

List of Files which are Greater then a specific date

A newbie question... I need to get a list of the Files and folders which are greater then a specific date. I want write the output to a Text file. What I know ls -lrt gives me list of all the files ordered by date. Also ls > fileName will write the results to a text file. Please help (6 Replies)
Discussion started by: rkaif
6 Replies

7. Shell Programming and Scripting

Trying to find files equal to and greater than

Hi Guys and Gals, I'm having some difficulty putting this check into a shell script. I would like to search a particular directory for a number of files. The logic I have is pretty simple: Find file named *.txt that are newer than <this file> and count them If the number of files is equal to... (4 Replies)
Discussion started by: bbbngowc
4 Replies

8. Shell Programming and Scripting

find list of files from a list and copy to a directory

I will be very grateful if someone can help me with bash shell script that does the following: I have a list of filenames: A01_155716 A05_155780 A07_155812 A09_155844 A11_155876 that are kept in different sub directories within my current directory. I want to find these files and copy... (3 Replies)
Discussion started by: manishabh
3 Replies

9. UNIX for Dummies Questions & Answers

Find files and display only directory list containing those files

I have a directory (and many sub dirs beneath) on AIX system, containing thousands of file. I'm looking to get a list of all directory containing "*.pdf" file. I know basic syntax of find command, but it gives me list of all pdf files, which numbers in thousands. All I need to know is, which... (4 Replies)
Discussion started by: r7p
4 Replies

10. Shell Programming and Scripting

Important finding --- find files greater than 1 MB

as we can find file greater than 1 MB with find command as: find /dir -name '*' -size +1M find /dir/* -name '*' -size +1M but wats its doing is , its finding files only in current directory not in sub-directories. i want files from sub-directories too. Please help... Thanx in... (3 Replies)
Discussion started by: manoj_dahiya22
3 Replies
Login or Register to Ask a Question