Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mkdir and cd using xargs... help needed

Status
Not open for further replies.

annanathan

Programmer
May 1, 2002
24
0
0
CA
Hi all,

I'm trying to create a directory with the current day of the following format: "date '%d_%B_%y'", since I want this job to run every day and create directory for each day...

Then I want to change directory of the newly created directory, but it's not working.

This is what I did...
Code:
date '%d_%B_%y' |xargs mkdir
date '%d_%B_%y' |xargs cd
The directory is getting created fine, but i get error saying that the 'cd' command cannot be found ...


The whole purpose of this script is to find all the .log files with the current date and put them is the current date directory (does anyone has any other approach to this problem?)

Please help...
Any help is appreciated,
Thank you.
 
You don't really need xargs for this .. you could just do mkdir $(date +%d_%B_y)

For the 2nd bit ... how are you going to find the log files with the current date? Is the date part of the filename, or are you going to use the last modification time?

Greg.
 
Hi,

you don't need xargs for the second command either: cd $(date +%d_%M_%y) does the same thing.

If the log files have the date in it then you find them with:

find your_search_path -type f -name "*$(date +%d_%B_%y)*"

alternatively if the file names don't contain the date you can do a find like this:

find your_search_path -type f -mtime -1

This will find all files modified less than 24 hours ago. Maybe your filtering has to be a bit more restrictive?

mrjazz [pc2]
 
Thank you all...

This is exactly what I wanted.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top