Beset Scripting langauge to delete old directories and contents?
What would the best scripting language be for selecting all the directories in the current directory that are over a week old and deleting there contents?
Perl? bash? groovy? ruby? something else? How would you do it? I got a start with perl in the beginners@perl.org and I started to think: hmmm... what about the bash find command -- would that be easier? What about other scripting languages?
Just run find and post-filter it to discard anything with the wrong number of slashes.
The number of slashes depends on what you mean by "child" and "grandchild". find usually prints one slash for the current directory (like ./fileincurrentdir) so children would have two slashes and grandchildren three, and grand-grandchildren of course one more, etc. So we run egrep to discard anything with at least three slashes, and anything with only one:
I'll answer your other questions, but the real answer was on the previous line.
date -d "week ago" will get you the date of 7 days ago, for any reasonably POSIX version of date. (Excludes some dinosaur architectures, unfortunately. If you're among the unfortunate, get your sysadmin to install the GNU utilities or at least a POSIX add-on. You will congratulate yourself many times over.)
The standard way to pass anything from a subprocess is to run something which prints its result in backticks. I'm sure you are familiar with backticks from Perl, too.
Unlike in Perl, the shell does some sanitization of the printed value, so there will be no trailing newlines, for example. This is mostly a feature.
Hello, this is my first post here.
I'm attempting to write a bash shell script to rm the contents of a directory without deleting the directory, specifically in OS X 10.10 . Here's what I have:
function clear() {
USER="$USER"
DIR=$1
rm -rfv /Users/"$USER"/library/$DIR/*
}
clear... (6 Replies)
Here is my dir structure:
/tmp/dave/myappend.txt
/tmp/dave/dir1/test.txt
/tmp/dave/dir2/test.txt
/tmp/dave/dir3/test.txt
/tmp/dave/dir4/test.txt
I want to append the contents of myappend.txt to the end of each file with the name "test.txt" in all dirs in /tmp/dave/
I have tried this:... (2 Replies)
Hi,
I want to delete the contents of a file which are matching with contents of other file in shell scripting.
Ex.
file1
sheel,sumit,1,2,3,4,5,6,7,8
sumit,rana,2,3,4,5,6,7,8,9
grade,pass,2,3,4,5,6,232,1,1
name,sur,33,1,4,12,3,5,6,8
sheel,pass,2,3,4,5,6,232,1,1
File2... (3 Replies)
Give shell script....which takes two file names as input and compares the contents, is both are same delete second file's contents.....
I try with "diff"...... but confusion how to use "diff" with if ---else
Thanking you (5 Replies)
i have been asked to write a bash shell script comparing two directories and sed or awk should not be used in this assignment. compdir will compare filenames in two directories, and list information about filenames that are in one directory but not the other. The information listed will be a long... (1 Reply)
hi,
I've a folder structure like :
/home/project/LIBNAMEA/FILE1
/home/project/LIBNAMED/FILE2
/home/project/LIBNAMEC/FILE3
/home/project/LIBNAMED/FILE4
/home/project/LIBNAMEX/FILE5
(there is no relation in the letters after the project/ )
and i need to delete the files keeping... (5 Replies)
I am new to shell programming and have an assignment question which requires me to list the contents of the present working directory in 4 column format and highlight any subdirectories. It then requires me to develop the shell script to accept a directory name as a positional parameter (if no... (1 Reply)