The script I gave you takes a list of directories to rename as operands; not the name of a file containing a list of directories to rename.
Didn't the error message it gave you saying that renamebuild was not found give you a hint?
And, as the comments in the code I provided clearly states, it will not work on directories with leading 0's in their names. (Doing arithmetic on arbitrary strings of digits instead of decimal numbers leads to ambiguities that will cause my code to fail.) Furthermore, this code is not expecting (and will not correctly handle) attempts to rename 111 to tested-111 or other directories if the target directory name already exists.
Since your new requirements do not match your original requirements and the sample data you provided, feel free to use the code I provided as a template you can use as a start to get working code for your new requirements. As it stands, it clearly is unsuited to do what you want (even though it does everything you originally asked for).
This User Gave Thanks to Don Cragun For This Post:
Thanks a ton Don Cragun and the scripting is working fine.
---------- Post updated 09-24-14 at 02:07 PM ---------- Previous update was 09-23-14 at 07:23 PM ----------
Hi Don Cragun,
One more query on your script please i.e. from below output, when I input 103, the script renames 103 to tested-103 and keeps 102 & 104.
Now, I would like to append an '0' (zero) before the directories that I am keeping (in this e.g. 102 & 104) i.e. new names should be 0102 & 0104.
I tried to modify the script and it doesn't work for me and I don't want to mess-up the script . Please advise.
One more query on your script please i.e. from below output, when I input 103, the script renames 103 to tested-103 and keeps 102 & 104.
Now, I would like to append an '0' (zero) before the directories that I am keeping (in this e.g. 102 & 104) i.e. new names should be 0102 & 0104.
I tried to modify the script and it doesn't work for me and I don't want to mess-up the script . Please advise.
Make a backup copy of the working script in case your changes don't work; but don't be afraid to experiment with your code. If you're worried about messing up your directory hierarchy, remove the | bash -x at the end of the script while you're testing so you can just see the commands that it plans to execute instead of actually running them. Please show us what you tried. (And I'll see if I can figure out why you're getting a warning on line 22 in the awk script that I'm not getting when I run it.)
I assume that you do realize that after you change a directory's name from 102 to 0102, the script as it is currently written cannot then later be used to move 0102 to tested-0102 and any directory with a name starting with "0" will never be considered for automatic removal during a later run.
This User Gave Thanks to Don Cragun For This Post:
Please find the console output (syntax errors as I have not put the code in right way ), when I tried to rename the directories that I am keeping (keep_above1 and keep_below1).
Your assumation is correct i.e. after I change a directory's name from 102 to 0102, I am not going to rename these dir. to tested-0102 (it always be 0102) and won't be deleting.
(I tried to add a '0'(zero) before the directories that i am going to keep.
Please help me in appending a '0' before the directories that I am keeping (I am a new baby to shell scripting and learning the concepts now).
I have a script, which is checking if file exists and move it to another directory
if
then
mkdir -p ${LOCL_FILES_DIR}/cool_${Today}/monthly
mv report_manual_alloc_rpt_A_I_ASSIGNMENT.${Today}*.csv ${LOCL_FILES_DIR}/cool_${Today}/monthly
... (9 Replies)
Hi
My directory structure is as below.
dir1, dir2, dir3
I have the list of files to be deleted in the below path as below.
/staging/retain_for_2years/Cleanup/log $ ls -lrt
total 0
drwxr-xr-x 2 nobody nobody 256 Mar 01 16:15 01-MAR-2015_SPDBS2
drwxr-xr-x 2 root ... (2 Replies)
I need a script which should watch a directory for a file with specific directory.
If it finds a file in directory, it should search for few specific keyword in the file. if the keyword exists, it should trim string from specific column.
The file should be moved to another directory and the a... (8 Replies)
Hi, what function do we use to delete only particular file that we want in directory shell script
for example I want only to delete test.txt in directory how to do it ? in sh
Thank (1 Reply)
Hi ,
I am trying to make a cron job to delete the contents of a directory in a linux environment.The contents created before 2 days should get deleted by this job.Here is what i have written :
/usr/bin/find / -name *.log -ctime +2 -exec /bin/rm -f {} \;
Is it correct....If not so,please... (9 Replies)
There are some files in a directory like a.tx~ , b.txt~,c.txt~.
I want to delete all these files inside that directory and sub directory.
How can i do this?
#!/bin/bash
cd thatdirectory
......
rm -rf *~
...... (7 Replies)
Under TEMP folder, it have many sub-folder, example"0015,0016,etc"
I need to discovery those file which are 2 days ago in this sub-folder , and list out to investigate, at the end delete all file in those sub folder, only keep the emptu directory. Thanks (4 Replies)
I have a file <filestodelete> containing names of files to to be deleted from a directory <filesstore>.
I want a script file which accptes the <filestodelete> and also the location of the directory(<filestore>) and deletes all files matching.
Thanks in Advance.. (3 Replies)