Copy last modified directory from path using Perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Copy last modified directory from path using Perl
# 1  
Old 08-16-2010
Copy last modified directory from path using Perl

Hi
I need to copy last modified directory from path /users/bin to be copied to /tmp in a perl script ...somehow my script is not allowing me to do cd /users/bin.


i have tried
Code:
$dir = `find /users/bin -maxdepth 1 -type d -mtime 0 `
cp -R $dir /tmp/new

but it says missing destination file

regards
shaveta

Moderator's Comments:
Mod Comment Subject title changed. Please use a more meaningful title.

Last edited by Scott; 08-16-2010 at 07:21 AM.. Reason: Code tags
# 2  
Old 08-16-2010
Quote:
Originally Posted by shaveta
...
i have tried
Code:
$dir = `find /users/bin -maxdepth 1 -type d -mtime 0 `
cp -R $dir /tmp/new

but it says missing destination file

...
That's because "cp -R" is a shell command that you are trying to use, as is, inside a Perl program.

You'll have to use Perl's system() command or the backticks to run a shell command in Perl.

Code:
system("cp -R $dir /tmp/new");

or -

Code:
`cp -R $dir /tmp/new`;

Or if you want a pure Perl implementation, then use the dircopy subroutine of the File::Copy::Recursive Perl module.

tyler_durden
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

What is the difference ../directory path and ./directory path in ksh?

What is the difference ../directory path and ./directory path in ksh? (1 Reply)
Discussion started by: TestKing
1 Replies

2. UNIX for Beginners Questions & Answers

Convert Relative path to Absolute path, without changing directory to the file location.

Hello, I am creating a file with all the source folders included in my git branch, when i grep for the used source, i found source included as relative path instead of absolute path, how can convert relative path to absolute path without changing directory to that folder and using readlink -f ? ... (4 Replies)
Discussion started by: Sekhar419
4 Replies

3. UNIX for Advanced & Expert Users

How can i assign directory path to a variable in perl?

Hai how can I assign directory path to a variable in perl Thanks&Regards kiran (3 Replies)
Discussion started by: kiran425
3 Replies

4. UNIX for Dummies Questions & Answers

How can i assign directory path to a variable in perl?

Hai how can I assign directory path to a variable in perl Thanks&Regards kiran (2 Replies)
Discussion started by: kiran425
2 Replies

5. Shell Programming and Scripting

Sizeof a file from directory path in perl

Hai how to find size of a file?? ex : /home/kiran/pdk/sample/calibre this is a path In that I have to find size of a files in side a calibre(it is the folder) like .results or .summary (1 Reply)
Discussion started by: kiran425
1 Replies

6. Shell Programming and Scripting

How to search/replace a directory path in a file using perl

Hello All, Here is what I am trying to do and maybe you guys can point me in the right direction. I have a file that contains the following string(s): WARNING: </d1/test/program1> did not find item1 WARNING: </d1/test/program1> item1 does not exist WARNING: </d1/test/program2> item1 failed... (1 Reply)
Discussion started by: maxshop
1 Replies

7. Shell Programming and Scripting

Perl script to copy last directory

Hi, Plaese help me with perl script which copies the latest directory This is a double post. Continue at your original thread. Thanks. (0 Replies)
Discussion started by: shaveta
0 Replies

8. Shell Programming and Scripting

Copy Last modified directory to another directory

Hi, I have to copy last modified Directory to another directory.How can i Do using pipe or redirect cp -R 'ls -lrt|tail -1' test is not working. please help. (3 Replies)
Discussion started by: shaveta
3 Replies

9. Shell Programming and Scripting

Perl directory path in array

Hi anyone can help how put the directory in array in perl.eg directory paths below:- /home/user/ /home/admin/ /var/log/ IF path eq /home/user/ then the files moved to /data/user/ IF path eq /var/log/ then the files moved to /data/log/ Thanks (1 Reply)
Discussion started by: netxus
1 Replies

10. Shell Programming and Scripting

perl find directory only if modified in last hour

I want a one liner perl command to find a directory only if the modified time is within the last hour I am running this on windows - and I will define a variable for the result. So for example I want to return value of 1 for the variable if the modified time of d:\test1 is within the last... (0 Replies)
Discussion started by: frustrated1
0 Replies
Login or Register to Ask a Question