Hello Community!
Im newbie on shell programming and its my first post.
Im trying to make a bash shell script that it removes files of subdirectory.
it is called : rms -{g|l|b} size1 [size2] dir
-g means : remove file or files in dir that is above size1
-l means: remove file or files in dir that is under size1
-b means : remove file or files in dir that is between size1 and size2
i need to find files size with stat
this is my try :
The problem is when i run the script it deletes all files in subdirectory
e.g when i use g in commadn i want to delete the files that they r above size1
it deletes all the files in subdirectory
Can somebody help with this ?
Thank you in advise
Last edited by radoulov; 06-30-2011 at 12:40 PM..
Reason: Code tags.
---------- Post updated at 09:40 AM ---------- Previous update was at 09:33 AM ----------
found another one:
Also I think you could improve your program's organization by using a case statement, and shift. That many if-else's is difficult to look through since what's happening now directly depends on a decision made 3 pages ago, better to break into smaller blocks where you can. Remember that an if - then - exit - fi is as good as an if - else, since you can branch just by quitting.
That way you don't need to keep remembering which number you need to use and can gracefully deal with more than one input directory.
And always make it 'echo rm' when you're just testing, you don't want to run rm when it's not working right!
And you should quote your variables in case the filename contains spaces. "$f" instead of just $f
Last edited by Corona688; 06-30-2011 at 12:45 PM..
I have the below input data in a file and need to get the output as mentioned below. Need to sort the data by size(Asc/des)/by subdirectory
Below is the input which is there in a file:
120 /root/path2/part-00000-d3700305-428d-4b13-8161-42051f4ac5ed-c000.json
532 ... (3 Replies)
Hi
My directory structure is as below.
dir1, dir2, dir3
I have the list of files to be deleted in the below path as below.
/staging/retain_for_2years/Cleanup/log $ ls -lrt
total 0
drwxr-xr-x 2 nobody nobody 256 Mar 01 16:15 01-MAR-2015_SPDBS2
drwxr-xr-x 2 root ... (2 Replies)
Hello,
I have a huge directory (with millions of files) and need to find out duplicates based on BOTH file name and File size.
I know fdupes but it calculates MD5 which is very time-consuming and especially it takes forever as I have millions of files.
Can anyone please suggest a script or... (7 Replies)
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)
To find the whole size of a particular directory i use "du -sk /dirname".. but after finding the direcory's size how do i make conditions like if the size of the dir is more than 1 GB i hav to delete some of the files inside the dir (0 Replies)
Please Help me
Question: - we manually moving/removing old files, when we are getting alarm as /dir1/dir2 size greater than 90%.
we manually moving/removing old files and reduce the file size to less than 90%
- I want to delete all 2months before old files once we get the thresh hold >= 90%... (3 Replies)
I have several files in a folder and I would like to delete the ones that do not contain all the required information (size) let say 1kb.
Any ideas? (4 Replies)
I have a Unix directory, let's call it /home/id for example purposes. It contains the following files: oldfile.txt.20091101, oldfile.txt.20091102, oldfile.txt.20091103, etc.
I am trying to create a Korn Shell script that will go to /home/id and delete any oldfile.txt that has a datetime stamp... (1 Reply)
I have a few txt files in some directory and I need to check their sizes one by one. If any of them are greater than 5mb then I need to split the file in two.
Can someone help?
Thanks. (6 Replies)
hello people
i need your help please
i want to achieve the following with the simplest, most efficient shell-tools:
i have a directory with a lot of files from users.
the script should check which partition the dir is on
if the partition with the directory is more than 90% full
... (2 Replies)