Objective, move dated files to a directory by MONTH.
just some quick ideas... nothing refined, just a sample of what can
be done with some basic UNIX commands. Simple, reliable and portable.
ls -al reveals (truncated list):
-rw------- 1 root sys 264 Mar 16 2000 9737_sh_history
-rw------- 1 root sys 974 Jul 28 2000 976_sh_history
-rw------- 1 root sys 34 Aug 16 2000 9782_sh_history
-rw------- 1 root sys 60 Nov 10 04:11 9816_sh_history
-rw------- 1 root sys 30 Dec 7 21:12 983_sh_history
mkdir Dec (and all the months, then change Dec to month)
touch list
chmod 750 list
(return here for each month)
ls -al | grep Dec | awk '{print "mv " $9 " Dec"}' | tee list
list looks like:
mv 102_sh_history Dec
mv 1044_sh_history Dec
mv 1061_sh_history Dec
mv 1069_sh_history Dec
mv 1116_sh_history Dec
mv 1335_sh_history Dec
mv 1440_sh_history Dec
mv 15598_sh_history Dec
mv 1934_sh_history Dec
mv 19661_sh_history Dec
mv 21969_sh_history Dec
mv 2628_sh_history Dec
mv 279_sh_history Dec
mv Dec Dec
One problem comes up in the generated list, the last line which includes
the Directory Dec. You can either live with the error you get when
you execute "list" or,
we can use a little perl to clean that up...
perl -pi -e 's/mv Dec Dec//g' list
execute ./list
and repeat process...
it's possible to make one line and just change the Month...
>--> mkdir May ; ls -al | grep May | awk '{print "mv " $9 " May"}' | tee list
mv 26906_sh_history May
mv 26970_sh_history May
mv May May
-----------------------------------------------------
root@engineering [/root/historyfiles]
>--> perl -pi -e 's/mv May May//g' list ; ./list
this could be done for any field.
could be used to identify file ownership
if I get time I'll modify it to use FIND to traverse a full directory structure,
and could even use perl to update files along that tree instead of
moving them...
UNIX is amazing... :) There's no wrong way of doing most of this stuff,
and plenty of right ways. The trick is to realize when you're doing something
too many times and then script it somehow. Of course if you can think ahead
more than 30 seconds you could map it all out first and then execute it... if
you have the ability to do that you're obviously not a Systems Administrator, or
you're not busy enough and I want to work where you are... ;)
---------------------------------------------
Fundamental Issues
---------------------------------------------
the Bible on line
What must I do to be saved?
BELIEVE THIS!
BIBLE passages and books
---------------------------------------------
So if it's not sunny in Snohomish, where is it SUNNY?
winter storm 96/97
AMSOIL information
Full Size Jeeps
downsized Jeeps
Diesel Benz info
wagoneers.com
more UNIX pages on wagoneers.com