- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Moving files
Categories
Company
Local Language
Forums
Discussions
Knowledge Base
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Forums
Discussions
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
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- 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
08-26-2002 05:41 AM
08-26-2002 05:41 AM
Moving files
I have thousands of files in one directory, and i want to sort them by month in sub folders to that its a little easyer on the eye's, can anyone help me ?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2002 05:49 AM
08-26-2002 05:49 AM
Re: Moving files
# cd dir_name
# find . -depth -atime +10 | cpio -pdlmuva /dest_dir
This will copy all directories and files under dir_name which was not accessed for last 10 days to the dest_dir
For sorting, you can use sort command:
# man sort
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2002 06:08 AM
08-26-2002 06:08 AM
Re: Moving files
there is a one more way
cd / test ( direcorty where you ahve files )
where you have the files
ls -l | awk '{id ($6=="Jan") print $NF }' > January
and so on till you get 12 files with the file names of each month , at this point you can check the total sum to ensure u got everything.
now run the following
for i in Jan Feb Mar Apr .....
do
mkdir $i02
cat $i | while read file_name
do
cp /test/filename /test/$i02/
done
done
you will definately have to test it ,
Manoj Srivastava
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2002 06:33 AM
08-26-2002 06:33 AM
Re: Moving files
@mths=qw/jan feb mar apr may jun jul aug sep oct nov dev/;
opendir(DIR,".");
while($fn=readdir(DIR)) {
next unless -f $fn;
($mtime)=(stat $fn)[9];
($mthn)=(localtime($mtime))[4];
$mth=$mths[$mthn];
mkdir $mth,0777 unless -e $mth;
die "$mth is not a directory" unless -d $mth;
system("mv $fn $mth");
}
Hope this helps...
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2002 06:36 AM
08-26-2002 06:36 AM
Re: Moving files
# touch -m -t 200208031230.01 /tmp/olderthan
# ls -l /tmp/olderthan
-rw-rw-rw- 1 root sys 0 Aug 3 12:30 /tmp/olderthan
# find /tmp ! -newer /tmp/olderthan -exec mv {} /newdirectorypath \;
TOUCH format
YYYYMMDDHHMM.SS
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2002 07:42 AM
08-26-2002 07:42 AM
Re: Moving files
After you move the file, you probably want to do a touch so that the original datestamps are preserved.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2002 01:58 AM
09-02-2002 01:58 AM
Re: Moving files
In order to preserve all file times you could do a cp(1) / rm(1) command pair instead of a mv. This is of course much slower than using mv(1) but nothing else needs to be done.
Of course you will need the -p option of the cp(1) command (i.e. preserve file times and ownership).
Die captive, or just live,
Timo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2002 02:50 AM
09-02-2002 02:50 AM
Re: Moving files
"mv" will preserve times, see below:
# ls -l sd_ipd_acl.2096
-rw-r--r-- 1 root sys 55 Dec 12 2001 sd_ipd_acl.2096
# mv sd_ipd_acl.2096 abc
# mv abc sd_ipd_acl.2096
# ls -l sd_ipd_acl.2096
-rw-r--r-- 1 root sys 55 Dec 12 2001 sd_ipd_acl.2096
# mv sd_ipd_acl.2096 /var
# mv /var/sd_ipd_acl.2096 /tmp
# ls -l sd_ipd_acl.2096
-rw-r--r-- 1 root sys 55 Dec 12 2001 sd_ipd_acl.2096
# ls -la sd_ipd_acl.2096
-rw-r--r-- 1 root sys 55 Dec 12 2001 sd_ipd_acl.2096
# ls -lu sd_ipd_acl.2096
-rw-r--r-- 1 root sys 55 Sep 2 06:23 sd_ipd_acl.2096
# date
Mon Sep 2 06:40:13 EDT 2002
#
live free or die
harry