Visit Our UNIX and Linux User Community


Moving files till the size is less than 200000.


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Moving files till the size is less than 200000.
# 1  
Old 04-06-2002
Moving files till the size is less than 200000.

Hi,
I need your help.

Suppose I have a directory called /home/rooh
This directory contains files and directories.
For ex
drwxr-xr-x 3 rooha arboradm 96 Apr 6 03:24 batches
drwxr-xr-x 2 rooha arboradm 96 Apr 6 03:21 worker
-rw-rw-rw- 1 rooha arboradm 12661 Apr 4 05:46 RLO00220404144142ENG01
-rw-rw-rw- 1 rwata arboradm 16761 Apr 4 05:46 PD0022040414414200000AF-000
-rw-rw-rw- 1 rwata arboradm 13895 Apr 4 03:44 RLO00220404123602ENG01
-rw-rw-rw- 1 rwata arboradm 18586 Apr 4 03:44 SOR022040412360200000AF-000
-rw-rw-rw- 1 rwata arboradm 13749 Apr 4 03:44 SOR022040412360200000AF-001
-rw-rw-rw- 1 rwata arboradm 11974 Apr 4 03:44 RLO00220404123602ENG02

Now I want that I should list only the files and not directories and put them in a file.
So this is what I do:
cd /home/rooh
ls -al |grep ^->>/tmp/fileslist

So that looks fine. My /tmp/filelist contains only files and no directories.

Now what I want is that move the files from /home/rooh to /home/rooh/RIM/APRIL on the basis of size.
Means First I just want to move files till the size is less than 200000.

So I thought of doing something like this.
FILESIZE=0
for file in `cat /tmp/fileslist`
do
{
FILENAME=`cat $file |awk '{print $9}'`
#FILE=`cat $FILENAME |cut -f7 -d "/"`
SIZE=`cat $file |awk '{print $5}'`
if [ $FILESIZE -lt 200000 ]; then
{
mv $FILENAME /home/rooh/RIM/APRIL
[ $? = 0 ] && /bin/printf "$FILE\n " >> $LOGFILE
FILESIZE=`expr $FILESIZE + $SIZE`
}
else
/bin/printf "File size is $FILESIZE."
exit 1
fi
} done

But It gives me various error messages. Can you please suggest what i should do.
Or is there an alternate way of doing this.

Basically I just want to move files until the size is less than 200000.
Your suggestion will be highly appreciated.

Thanx a ton in advance for your valuable advice.

Rooh

Smilie
# 2  
Old 04-06-2002
Hi All,

Sorry to bother you . Found out the solution to my problem.

Instead of using ls -al |grep ^->>/tmp/fileslist, where I had selected everything , I used this command

ls -al $SOURCE/* |grep ^- |awk '{print $5 " " $9}'>>$tmpfile

And also changed the for loop to while read.
It has worked and looks good.

If you think there is still a better way of doing it.

Your responce & suggestion will be highly appreciated.

Thanx
Smilie Smilie
 

Previous Thread | Next Thread
Test Your Knowledge in Computers #334
Difficulty: Easy
For security reasons, Android versions are not named in alphabetical order.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

For loop till the files downloaded

Need assistance in writing a for loop script or any looping method. Below is the code where i can get all the files from the URL . There are about 80 files in the URL .Every day the files get updated . Script that i wanted is the loop must keep on running till it gets 80 files. It matches the count... (5 Replies)
Discussion started by: ajayram_arya
5 Replies

2. Shell Programming and Scripting

Moving files based on size (string to integer)

I have a log file that I want to archive out as it reaches 100MB. I am using the following to get the file size into a variable but get the error "line 5: filesize=$(wc -c < logfile.log) if then echo "is greater than 100M" else echo "is less than 100M" fi I'm sure there's something... (2 Replies)
Discussion started by: Flakman
2 Replies

3. UNIX for Dummies Questions & Answers

[SOLVED] How to set a default of 200000 as scrollback size in Putty ?

Putty release : 0.61 For saved sessions , you can configure Scrollback size just once using "Lines of Scrollback" in the 'Window' menu For a non-saved session (an ad-hoc session ) , If you want a higer scrollback size for a putty session , you have to set the "Lines of Scrollback" manually... (4 Replies)
Discussion started by: kraljic
4 Replies

4. Shell Programming and Scripting

Moving a file based on size

hello, I am creating a script that is going to scan the contents of a directory, and if it finds a certain DocumentName that is a certain size (The example, DocumentName and a size of 8777) If this file exists, it needs to be moved to a directory for later removal/processing..anyone have... (7 Replies)
Discussion started by: jeffs42885
7 Replies

5. Shell Programming and Scripting

Pause shell script till folder doesn't change size anymore

Hi, I recently would like to write a shell script that 1. Runs in the background (can be done with "&", but i'd be happy for other solutions to keep programs running) 2. Does its stuff 3 THEN checks a specified folder for a size change over time (say, each 5 seconds. AND ONLY continues with... (9 Replies)
Discussion started by: pasc
9 Replies

6. HP-UX

Make command performs badly and refuses to compile on 200000 files

I am trying to run make command on 200000 files in HP UX but it refuses to compile giving a message that " command line is too long .stop" I checked and found out that there is a limit imposed by the operating system on the command line .for Eg refer following link : The maximum length of... (6 Replies)
Discussion started by: madhur.tripathi
6 Replies

7. Shell Programming and Scripting

Program to tar files to packages less then 200000 bytes

Trying to write program to archive files from a file system. I got some problem with appropriate selection of files in regard to size. Algorithm basic : ----------------- 1. Remotely executes on machine ls cmd and its output redirects and sorts by size of a files : # cd... (0 Replies)
Discussion started by: presul
0 Replies

8. Shell Programming and Scripting

Want to zip the all files till nth depth

All, i need a script which can zip the all files which are in directories and its subdirectories for example: dir1 contains file1,file2,dir1a,dir1b now dir1a also contains fil11,fil12 ,dirab so script should look for files in dir or sub dir till files not found and... (2 Replies)
Discussion started by: vijays3
2 Replies

9. Shell Programming and Scripting

How to print lines till till a pattern is matched in loop

Dear All I have a file like this 112534554 446538656 444695656 225696966 226569744 228787874 113536566 443533535 222564552 115464656 225445345 225533234 I want to cut the file into different parts where the first two columns are '11' . The first two columns will be either... (3 Replies)
Discussion started by: anoopvraj
3 Replies

10. Shell Programming and Scripting

bash script working for small size files but not for big size files.

Hi, I have one file stat. Stat file contents are as follows: for example. H50768020040913,00260100,507680,13,0000000643,0000000643,00000,0000 H50769520040808,00260100,507695,13,0000000000,0000000000,00000,0000 H50770620040611,00260100,507706,13,0000000000,0000000000,00000,0000 Now i... (1 Reply)
Discussion started by: davidpreml
1 Replies

Featured Tech Videos