- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: script help
Operating System - HP-UX
1752479
Members
5761
Online
108788
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Discussions
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2010 12:29 PM
06-05-2010 12:29 PM
script help
I have around 20 directories dirA,dirB.... and there are 3 to 4 subdirectories subdirA, subdirB ...in each of these 20 directories. I have files of last month and the months before in these subdirectories. I would like to move these files for archival purposes by month to another directory in the the format /archive/dirA/subdirA/Feb2010 . Could someone guide me on how to do this.
I have been doing this manually as below
cd to DirA and then use the below command
for i in `ls -l |grep Feb|awk '{print $9}'`
do
mkdir -p /archive/dirA/subdirA/Feb2010
mv $i /archive/dirA/subdirA/Feb2010
done
This is taking quite a long time.
I have been doing this manually as below
cd to DirA and then use the below command
for i in `ls -l |grep Feb|awk '{print $9}'`
do
mkdir -p /archive/dirA/subdirA/Feb2010
mv $i /archive/dirA/subdirA/Feb2010
done
This is taking quite a long time.
- Tags:
- scripting
1 REPLY 1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2010 01:17 PM
06-05-2010 01:17 PM
Re: script help
Hi:
You could try this (untested):
# cat ./archiveit
#!/usr/bin/sh
for DIR in DirA DirB DirC #...etc...
do
cd ${DIR} || exit 1
for SUBDIR in subdirA surdirB subdirC #...etc
do
cd ${SUBDIR} || continue #...skip if missing...
mkdir -p /archive/${DIR}/${SUBDIR}/Feb2010
for FILE in $(ls -l|awk '{if ($6=="Feb") {print $9}}')
do
mv ${FILE} /archive/${DIR}/${SUBDIR}/Feb2010
done
cd .. #...back out of current SUBDIR...
done
cd .. #...backup out of current DIR...
done
exit
...
Regards!
...JRF...
You could try this (untested):
# cat ./archiveit
#!/usr/bin/sh
for DIR in DirA DirB DirC #...etc...
do
cd ${DIR} || exit 1
for SUBDIR in subdirA surdirB subdirC #...etc
do
cd ${SUBDIR} || continue #...skip if missing...
mkdir -p /archive/${DIR}/${SUBDIR}/Feb2010
for FILE in $(ls -l|awk '{if ($6=="Feb") {print $9}}')
do
mv ${FILE} /archive/${DIR}/${SUBDIR}/Feb2010
done
cd .. #...back out of current SUBDIR...
done
cd .. #...backup out of current DIR...
done
exit
...
Regards!
...JRF...
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP