Sponsored Content
Top Forums Shell Programming and Scripting Fetch the last two days directory names and rename them Post 302919285 by ibad_urs on Tuesday 30th of September 2014 06:19:31 AM
Old 09-30-2014
Question Fetch the last two days directory names and rename them

Hi All,

I have below directory structure and from these directories, I would like to fetch the last two days list of directories and append a '0' (zero) to those directories.

Code:
bash-4.1$ ls -lrt
total 32
drwxr-xr-x+ 6 root root 9 Sep  5 01:05 tested-597
drwxr-xr-x+ 6 root root 9 Sep  9 01:04 tested-605
drwxr-xr-x+ 6 root root 9 Sep  9 13:34 tested-606
drwxr-xr-x+ 6 root root 9 Sep 10 13:35 tested-608
drwxr-xr-x+ 6 root root 9 Sep 11 13:47 tested-614
drwxr-xr-x+ 4 root root 4 Sep 22 16:13 647
drwxr-xr-x+ 4 root root 4 Sep 23 00:49 650
drwxr-xr-x+ 6 root root 9 Sep 23 15:19 tested-652
drwxr-xr-x+ 8 root root 8 Sep 24 11:52 659
drwxr-xr-x+ 8 root root 8 Sep 24 13:12 660
drwxr-xr-x+ 8 root root 8 Sep 24 23:26 661
drwxr-xr-x+ 8 root root 8 Sep 25 02:59 664
drwxr-xr-x+ 8 root root 8 Sep 25 13:58 tested-665
drwxr-xr-x+ 8 root root 8 Sep 26 01:17 666
drwxr-xr-x+ 8 root root 8 Sep 26 13:52 667
drwxr-xr-x+ 8 root root 8 Sep 27 01:19 668
drwxr-xr-x+ 8 root root 8 Sep 27 13:40 669
drwxr-xr-x+ 8 root root 8 Sep 28 01:12 670
drwxr-xr-x+ 8 root root 8 Sep 28 13:36 671
drwxr-xr-x+ 8 root root 8 Sep 29 01:12 672
drwxr-xr-x+ 8 root root 8 Sep 29 13:45 673
bash-4.1$
bash-4.1$
bash-4.1$
bash-4.1$ find . -maxdepth 1 -mtime -2
.
./673
./672
./671
bash-4.1$

With the below find command, I am able to fetch the last two days list of directories but unable to combine this with 'mv' command in a shell script (what ever the output from find cmd, those dir should be appended with a '0')

Code:
find . -maxdepth 1 -mtime -2

For e.g. from above list, I am able to fetch the last two days directory names 671, 672, 673 and I would like rename these dir as 0671, 0672, 0673.

Any advise is much appreciated.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ls latest 4 days or specify days of files in the directory

Hi, I would like to list latest 2 days, 3 days or 4 days,etc of files in the directory... how? is it using ls? (3 Replies)
Discussion started by: happyv
3 Replies

2. UNIX for Advanced & Expert Users

fetch dates for last 36 days in format yyyy-mm-dd

can anyone please suggest me some ideas for writing a korn shell script which will go back to 36 days from current day and print each day (incremented by 1) in the format yyyy-mm-dd until the current day. Thanks Mark (7 Replies)
Discussion started by: pavan_test
7 Replies

3. Shell Programming and Scripting

Find and rename long file names (html)

Hi Guys, I need a help. I have 1130 zip files. Each one of them has files including 1 html file with long file name (includes special charactors, Alphabetic and numbers). I have copied all 1130 zip files to my linux system and extracted using below command. Find . -name "*.zip" -exec... (7 Replies)
Discussion started by: Rajmani
7 Replies

4. UNIX for Dummies Questions & Answers

How to display only Owner and directory/sub directory names under particular root

hai, I am new to Unix, I have a requirement to display owner name , directory or sub directory name, who's owner name is not equal to "oasitqtc". (here "oasitqtc" is the owner of the directory or sub directory.) i have a command (below) which will display all folders and sub folders, but i... (6 Replies)
Discussion started by: gagan4599
6 Replies

5. Shell Programming and Scripting

Rename multiple file names in a directory

I hope some one can help me I have multiple files in a directory with out extension like as below mentioned. But i want to change all the file names along .DDMMYYYYHHMISS format. And all files should have same DDMMYYYYHHMISS. Scenario: direcory name = /vol/best/srcfiles files in a... (4 Replies)
Discussion started by: hari001
4 Replies

6. UNIX for Dummies Questions & Answers

Loop through directory and extract sub directory names

I am trying to loop through folders and extract the name of the lowest level subfolder I was running the script below, it returns /bb/bin/prd/newyork /bb/bin/prd/london /bb/bin/prd/tokyo I really want newyork london tokyo I couldn't find a standard variable for the lowest level... (1 Reply)
Discussion started by: personalt
1 Replies

7. UNIX for Dummies Questions & Answers

Which Unix & Linux Certifications Names In This Days ??

Hello All My Questions About Which Unix & Linux Certifications Names In This Days ? I Mean Red Hat Certifications , Solaris Certifications , IBM Certifications , HP Certifications and BSD Certifications just i need the names of these Certifications and How can i enter to Certifications... (1 Reply)
Discussion started by: Eng/G.Mohammad
1 Replies

8. Shell Programming and Scripting

Grepping file names, comparing them to a directory of files, and moving them into a new directory

got it figured out :) (1 Reply)
Discussion started by: sHockz
1 Replies

9. Shell Programming and Scripting

How to rename multiple file names?

Hi all, I need to rename more file name in one command or script. The files have this structure: XxY - filename.doc where X and Y are numbers and the x is the letter itself. I need to rename these files with this structure: string.S0XEY.filename.doc the string is a suffix that... (8 Replies)
Discussion started by: idro
8 Replies

10. Shell Programming and Scripting

How to fetch matched records from files between two different directory?

awk 'NR==FNR{arr;next} $0 in arr' /tmp/Data_mismatch.sh /prd/HK/ACCTCARD_20160115.txt edit by bakunin: seems that one CODE-tag got lost somewhere. i corrected that, but please check your posts more carefully. Thank you. (5 Replies)
Discussion started by: suresh_target
5 Replies
uucleanup(1M)															     uucleanup(1M)

NAME
uucleanup - uucp spool directory clean-up SYNOPSIS
time] time] time] time] string] time] system] debug_level] DESCRIPTION
The commands, including are targeted for removal from HP-UX; see the below. scans the spool directories for old files and takes appropriate action to remove them. Depending on the options selected, performs the following: o Informs the requestor of send and/or receive requests for systems that cannot be reached. o Returns mail that cannot be delivered to the sender. o Removes all other files. In addition, warns users of requestors who have been waiting for a given number of days (the default is 1 day). Note that unless time is specifically set, the default time values for the following options are used. Options recognizes the following options: Any files greater or equal to time days old are removed with appropriate information to the requestor. The default time is 7 days. Any files greater or equal to time days old are removed. An attempt is made to deliver mail messages and execute news when appropriate. The default time is 7 days. Any files equal to time cause a message to be mailed to the requestor warning about the delay in contacting the remote. The message includes the JOBID, and in the case of mail, the mail message. The administrator can include a message line telling who to call to correct the problem (see the option). The default time is 1 day. Any files greater than or equal to time days old are removed. The files are probably not present (if they were, the could be executed). But, if files are present, they are taken care of by processing. The default time is 2 days. This string is included in the warning message generated by the option. The default string is Other files whose age is more than time days are deleted. The default time is 2 days. Clean-up the spool directory for system only. The default is to clean-up all spool directories. The debug level is a single digit between 0 and 9. The higher the numbers, the more detailed the debugging information returned. This program is typically started by the script which should be started by (see cron(1M)). WARNINGS
Use of commands, including is discouraged because they are targeted for removal from HP-UX. Use ftp(1) or rcp(1) instead. FILES
spool directory SEE ALSO
cron(1M), uucp(1), uux(1), uuclean(1M). Tim O'Reilly and Grace Todino, O'Reilly & Associates, Inc. USA. Grace Todino and Dale Dougherty, O'Reilly & Associates, Inc. USA. TO BE OBSOLETED uucleanup(1M)
All times are GMT -4. The time now is 10:49 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy