Script Rename Files

Dears,
I want to create script to rename multiple file names from unix date to date for example
filename_1421907815_department.txt
rename to
filename_2015_01_22_08_23_department.txt


Similar Content



Inquiry On A Bash Script Using Sed And Grep -c

Hi Everyone,

I need some help on my bash script, I'm trying to rename a certain line in a file which might be 1 or more.

IDXCOUNT=`grep -c 'index .* on ' $FILENAME`;

for n in $(eval echo {1..$IDXCOUNT});
do
timestamp=$(date +"%s");
echo "Renaming index idx_$timestamp..";
if [ $n -eq 1 ]; then
sed -i "0,/^index [^)]* on /s/index idx_$timestamp on /" $FILENAME;

My problem is, if the sed target is 2 or more it will generate an idx_$timestamp that will cause duplicate index value when the script finish. My goal is to have the script recognize that when there are multiple index in the file, it will try to rename it one by one.

I'm new to bash so I'm not sure if I explained my issue well but I will appreciate any help!!

Thanks!

How To Rename A File In Linux

hello,

I am trying to rename the file by adding .txt extension and also
before renaming, I want to replace . in file with _

right now file looks like this mdm.201504021628

after execution of my script file name should be mdm_201504021628.txt


#!bin/bash
//reading all files from directory

files=$(hadoop fs

-ls /dl/data/landing/hivedb/lnd_attunity_kpi_db_backup/auth_master |
awk '!/^d/ {print $8}')

for f in $files; do

//using sed to replace . with _ and then feeding to hadoop fs command

sed 's/./\_/g' $f | hadoop fs -mv $f $f.txt

done

Thanks for your help in advance.

Script To Recursively Enter Subdirectories And Rename Files Sequentially From Scratch

I am new to Bash scripting.

I have a main directory called Photos which has many subdirectories like People, Places and Things. Each of these subdirectories is populated by other subdirectories and lots of JPG photo images.

The digital cameras name the files in a way that is difficult to manage with web hosting.

I would like to go to each directory and subdirectory and rename the photos 1.jpg, 2.jpg, 3.jpg, etc. so that I can use a simple XML template to access them by specifying only a hosting directory.

I tried to use the following script:

#! /bin/bash

cd /home/paul/test

find . -name "*.jpg" -print0 | rename -v 's/.+/our $i; sprintf("%d.jpg", 1+$i++)/e' * -vn

exit 0

It successfully renames all of the files in all of the directories, but it does not restart the numbering for each new subdirectory. So first it goes through Photos and renames the three JPG files there 1.jpg, 2.jpg and 3. jpg, and then it opens the first subdirectory People and names the three JPG files there 4.jpg, 5.jpg and 6.jpg. Next it moves to the next subdirectory and continues sequential renaming until it is done.

I want it to restart sequential renaming with each new subdirectory, so that after renaming the three JPG files in Photos to 1.jpg, 2.jpg and 3.jpg, it moves to the first subdirectory and renames the JPG files there starting with 1.jpg again.

That way I use the links 1.jpg, 2.jpg, 3.jpg, etc in the XML template and just change the directory name to download the photos from the web.

Thanks for any help you can give me.

Linux Bulk Renaming Files

Hello Folks.

I'm searching for a easy way to rename multiple files from CLI but didn't find any easy way for me so I'm reaching out to you guys for help.

This is what I want to do (from CLII or script). I want to move files with a sequence number on the name of the files (msg0000, msg0001, msg0002 and so on) to let's say msg0066, msg0067 and so on. Each of this file name has two other files (msg0000.wav, msg0000.WAV and msg0000.txt).

The idea is to move them from one directory to another and following a sequence in the file names, is there a way I can do this pain free?

Any help on this matter will be greatly appreciates and I'm talking about over 100 files I need to move following the sequence of the receiving directory.

Thanks!

Sed Use To Rename Files Under Multiple Directory

Hi all,

I am trying to use sed to rename multiple files under multiple directory.

so lets say for exmaple:
Under /root I have 2 directory as follows:

# ll {test1,test2}
test1:
total 0
-rw-r--r--. 1 root root 0 Apr 10 19:16 authkey.apollo

test2:
total 0
-rw-r--r--. 1 root root 0 Apr 10 19:16 authkeys.apollo

if I want to change apollo to jupiter then used this:
for i in `ls {test1,test2} | grep -i 'apollo'`; do echo $i; sed -i 's/apollo/jupiter/g'; done

but it seems like it got missed on the file path in sed. is there any other easier way or better approach to make this work?

Thanks in advance.

Blanks In File Name

How do I cope with file names containing a blank, if I want to rename them?

Simple Script Question: ${LOGFILES}.* Not Working

This should be a nice and simple one !

I have a script:

Code:
LOGFILES="schedule_download.log schedule_download_AccountancyServices.log schedule_download_FinancialControl.log schedule_download_IncomeCollection.log schedule_download_banner.log manual_download.log manual_download_AccountancyServices.log manual_download_bacs_cheques.log manual_download_FinancialControl.log manual_download_IncomeCollection.log manual_download_banner.log manual_download_Procurement.log manual_upload.log"

LOGDATE=`date +%Y%m%d`

for file in $LOGFILES
do
    cp $file $file.$LOGDATE
done

## Remove log files older than 30 days

for file1 in ${LOGFILES}.*
do
  find $file1 -mtime +30 -exec rm -v \;
done

However, the 2nd part isn't recognizing the files with a date suffix, ie. manual_download_banner.log.20150114 and is instead picking up all the $LOGFILES.

I've tried many variations $LOGIFILES.* and its driving me mad !

Thanks in advance.

Regarding The Processing Of A File Based On The Date Present In File Name Dynamically

Hi Experts,

i am completely new to scripting.i had a requirement where i need to add the time to name of the file and i need to get the latest file. in order to fulfill this i need a script. and my os is unix.so please help me guys




Thanks
Giridhar

Cygwin Rsync Script Copying File Incorrectly

I am trying to write a simple test script that executes a single rsync call. Once I get the syntax right, the script will be expanded to incorporate several rsync instructions to save me time.

I'm using a Cygwin Terminal on Windows 7 to run Rsync.

The script is called "backup" and I call it from the cygwin terminal using "./backup". Have used chmod to make it executable.

When I execute the rsync instruction as a standalone instruction at terminal prompt, the file copies to the target folder perfectly.

However, when I try and drop the same instruction into a script, it copies the file over from it's original file name "mvi_1840.mov" to a file with the name "." -- literally a single period. I can rename the file to a .mov file and it works fine but naturally, I don't want to have to do this.

The one other thing I will mention is that the file is located in the /home/"username" directory in cygwin vs /bin. But I would not think that this would make a difference.

I have pasted the contents of the script file below:
Code:
#!/bin/bash
    rsync.exe -rltDvP --exclude "System Volume Information" --exclude
 "RECYCLER" --exclude=\$RECYCLE.BIN --delete "/cygdrive/c/users/<USERNAME>
/desktop/mvi_1840.mov" "/cygdrive/c/users/<USERNAME>/desktop/test/"

Any help would be greatly appreciated!

Thanks

Script To Find The File Creation Time Is More Than Ten Minutes

Hi All,

Im trying to create a script which checks the creation time of a file and if it is more than ten minutes, send out an alert.

For ex : Creation date of file is 10:30 AM
current time is 10:45 AM

Then send an alert/ message.

This is the script i wrote below :

Code:
#!/bin/ksh

filename="/apps/log/file.txt"

if [ -f "${filename}" ]
then
        createTime=`ls -lad "${filename}" | awk '{print $8}'`
        echo "$createTime"
        currentTime=`date '+%M'`
        echo "$currentTime"
        DIFF=$(( $currentTime - $createTime )) 
        echo "$DIFF"

else

        exit 1

fi

I am getting syntax error on the subraction when i try to run this script . I can understand that creation time and current time is in different format thats y this error throws, but i dont know how to rectify it .

I need to find out if the file creation time is more than ten minutes.

Please help me in achieving this output.