LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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 04-01-2014, 12:45 PM   #1
dotran
LQ Newbie
 
Registered: Apr 2012
Posts: 27
Blog Entries: 2

Rep: Reputation: Disabled
please help script list/find move files greate than 1G 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

Quote:
/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 help with this script
/export/home/mytmp/test1> cat test.ksh
Quote:
#!/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
 
Old 04-01-2014, 06:47 PM   #2
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,371

Rep: Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750
Without writing a script for you, I will offer some thoughts on how I would go about this.

First, it is considered poor practice to parse the output from the 'ls' command in scripts. http://mywiki.wooledge.org/ParsingLs

For getting a list of files to process, use the 'find' command with the '-size' option.

Code:
# Pseudocode to show a general logic

# Find files <1G in size
find . -size -1G -type f

# Find files >1G in size
find . -size +1G -type f
test number of files found
if count=1 then
elif count=2 then
...
elif count>6 then
fi

Last edited by allend; 04-01-2014 at 06:52 PM. Reason: Added link
 
1 members found this post helpful.
  


Reply



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] move files or a directory to another directory using shell script user1111 Linux - Newbie 6 11-15-2013 08:13 AM
find files but move the parent directory instead? Springs Linux - General 4 12-21-2012 11:27 AM
[SOLVED] script to move files to a directory arturo393 Linux - General 6 08-13-2011 09:24 AM
[SOLVED] Find files with specific extension and move to a directory moyorakkhi Linux - Newbie 10 04-19-2011 08:50 AM
Need to create a script to move files from one directory to another mustang05 Solaris / OpenSolaris 4 06-16-2006 10:25 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:47 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
Open Source Consulting | Domain Registration