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
createhomedir(1)					    BSD General Commands Manual 					  createhomedir(1)

NAME
createhomedir -- create and populate home directories on the local computer. SYNOPSIS
createhomedir [-scbalh] [-n directoryDomainName] [-u username] DESCRIPTION
createhomedir provides several options for creating and populating home directories. OPTIONS
-s creates home directories for server home paths only (default). -c creates home directories for local home paths only. -b creates home directories for both server and local home paths. -a creates home directories for users defined in all directory domains of the server's search path. -l creates home directories for users defined in the local directory domain. -n directoryDomainName creates home directories for users defined in a specific directory domain in the server's search path. -u username creates a home directory for a specific user defined in the domain(s) identified in the -a, -l, or -n parameter. If you omit the -a, -l, and -n parameters when you use the -u parameter, -a is assumed. -i reads username list from standard input and creates specified home directories. Each username should be on its own line. -h usage help. FILES
/usr/sbin/createhomedir location of tool CAVEATS
When using the -a option, search limits of various directory servers (such as Open Directory or Active Directory) can prevent all possible home directories from being created. In this case, you may need to specify the usernames explicitly. Mac OS X June 1, 2019 Mac OS X
All times are GMT -4. The time now is 12:26 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy