Sponsored Content
Top Forums Shell Programming and Scripting A script that will move a file to a directory with the same name and then rename that file Post 302370450 by marcozd on Wednesday 11th of November 2009 12:06:42 PM
Old 11-11-2009
Question A script that will move a file to a directory with the same name and then rename that file

Hello all.

I am new to this forum (and somewhat new to UNIX / LINUX - I started using ubuntu 1 year ago).Smilie

I have the following problem that I have not been able to figure out how to take care of and I was wondering if anyone could help me out.Smilie

I have all of my music stored in the following structure

"/home/Music/artist name/" where "artist name" is the name of the artist. For example, there is a directory called "/home/Music/ACDC/" with all of my ACDC.

I have a directory of picture files for all of the artists in my music library i.e "/home/artists/" and all of the files have the extension .jpg. Each artist has one file that is named exactly as the directory in my "/home/Music/" directory. That is, I have a file called ACDC.jpg to match "/home/Music/ACDC/"

Now, what I want to do is the following: move each of the picture files in "/home/artists/" to the matching directory in /home/Music/.

So it should move "/home/artists/ACDC.jpg" to "/home/Music/ACDC/". Maybe this requires regular expressions of some kind, I don't know.

THEN:

After the files are moved, I want ALL of the newly moved files stored in each of the artist directories in "/home/Music/" to be renamed to "folder.jpg".

Thus "/home/Music/ACDC/ACDC.jpg" would become "/home/Music/ACDC/folder.jpg"

Is this possible? I really hope it is, because it would take me days, if not weeks, to manually copy and paste all of the files and then rename them one by one.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Move a file from windows directory to unix directory

Move a file from windows directory to unix directory, is this possible? if it is, can someone help me on this? Thanks! God bless! (1 Reply)
Discussion started by: kingpeejay
1 Replies

2. Shell Programming and Scripting

Move the latest or older File from one directory to another Directory

I Need help for one requirement, I want to move the latest/Older file in the folder to another file. File have the datetimestamp in postfix. Example: Source Directory : \a destination Directory : \a\b File1 : xy_MMDDYYYYHHMM.txt (xy_032120101456.txt) File2: xy_MMDDYYYYHHMM.txt... (1 Reply)
Discussion started by: pp_ayyanar
1 Replies

3. Shell Programming and Scripting

Script to move latest zip file to another directory

Hi folks, In my application there is a job running which create a .dat file along with it zip file also at unix box location /opt/app/cvf/temp1 so in temp1 directory I have one .dat file and its zip file also. Now since this job runs every day so if a job runs today there will be two files... (5 Replies)
Discussion started by: punpun66
5 Replies

4. UNIX for Dummies Questions & Answers

Rename files in a directory and move them

I have a directory e2e_ms_xfer/cent01 this contains the multiple files some of which will be named below with unique date time stamps e2e_ms_edd_nom_CCYYMMDD_HHMM.csv What I want to do is in a loop 1) Get the oldest file 2) Rename 3) Move it up one level from e2e_ms_xfer/cent01 to... (1 Reply)
Discussion started by: andymay
1 Replies

5. Shell Programming and Scripting

Move file in to directory- script

Hi In directory /mnt/upload I have about 100 000 files (*.png) that have been created during the last six months. Now I need to move them to right folders. eg: file created on 2014-10-10 move to directory /mnt/upload/20141010 file created on 2014-11-11 move to directory /mnt/upload/20141111... (6 Replies)
Discussion started by: primo102
6 Replies

6. Shell Programming and Scripting

How to rename (move) most recent files in directory?

I'm using cygwin32 on Windows. DN is an environment variable pointed at my download directory. This command works to move the single most recent file in my download directory to my current directory: mv "`perl -e '$p = $ARGV; opendir $h, $p or die "cannot opendir $p: $!"; @f = sort { -M $a... (2 Replies)
Discussion started by: siegfried
2 Replies

7. Shell Programming and Scripting

Rename specific file extension in directory with match to another file in bash

I have a specific set (all ending with .bam) of downloaded files in a directory /home/cmccabe/Desktop/NGS/API/2-15-2016. What I am trying to do is use a match to $2 in name to rename the downloaded files. To make things a more involved the date of the folder is unique and in the header of name... (1 Reply)
Discussion started by: cmccabe
1 Replies

8. Shell Programming and Scripting

Shell script cannot create directory and move the file to that directory

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)
Discussion started by: digioleg54
9 Replies

9. Shell Programming and Scripting

Move file from one directory and update the list file once moved.

Dears, I have a listfile contains list of files path. i need to read the line of the listfile mv the file to other directory and update the listfile by deleting the lines of the listfile. #!/bin/bash target=/fstest/INVESTIG/Sadiq/TEST_ARCH while read -r line || ]; do mv $line... (19 Replies)
Discussion started by: sadique.manzar
19 Replies

10. UNIX for Beginners Questions & Answers

Rename file in directory using contents within each file

In the below there are two generic .vcf files (genome.S1.vcf and genome.S2.vcf) in a directory. There wont always be two genaric files but I am trying to use bash to rename each of these generic files with specfic text (unique identifier) within in each .vcf. The text will always be different, but... (11 Replies)
Discussion started by: cmccabe
11 Replies
GIT-MV(1)							    Git Manual								 GIT-MV(1)

NAME
git-mv - Move or rename a file, a directory, or a symlink SYNOPSIS
git mv <options>... <args>... DESCRIPTION
This script is used to move or rename a file, directory or symlink. git mv [-v] [-f] [-n] [-k] <source> <destination> git mv [-v] [-f] [-n] [-k] <source> ... <destination directory> In the first form, it renames <source>, which must exist and be either a file, symlink or directory, to <destination>. In the second form, the last argument has to be an existing directory; the given sources will be moved into this directory. The index is updated after successful completion, but the change must still be committed. OPTIONS
-f, --force Force renaming or moving of a file even if the target exists -k Skip move or rename actions which would lead to an error condition. An error happens when a source is neither existing nor controlled by GIT, or when it would overwrite an existing file unless -f is given. -n, --dry-run Do nothing; only show what would happen -v, --verbose Report the names of files as they are moved. GIT
Part of the git(1) suite Git 1.7.10.4 11/24/2012 GIT-MV(1)
All times are GMT -4. The time now is 06:50 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy