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
tracker-sparql(1)						   User Commands						 tracker-sparql(1)

NAME
tracker-sparql - Use SparQL to query the Tracker databases. SYNOPSIS
tracker-sparql [OPTION...] [-q QUERY] | [-f FILE] DESCRIPTION
tracker-sparql allows the caller to run an RDF query on the database. This can be done two ways. Either by providing a FILE with the query or by providing a string with the QUERY string. The FILE argument can be either a local path or a URI. It also does not have to be an absolute path. OPTIONS
-?, --help Show summary of options. -f, --file=FILE Use a FILE with SPARQL content to query or update. -q, --query=SPARQL Use a SPARQL string to query the database with. -u, --update This has to be used with --query. This tells tracker-sparql to use the SPARQL update extensions so it knows it isn't a regular data lookup request. So if your query is intended to change data in the database, this option is needed. -c, --list-classes Returns a list of classes which describe the ontology used for storing data. These classes are also used in queries. For example, http://www.w3.org/2000/01/rdf-schema#Resource is one of many classes which should be returned here. -x, --list-class-prefixes Returns a list of classes and their related prefixes. Prefixes are used to make querying a lot simpler and are much like an alias. For example, http://www.w3.org/2000/01/rdf-schema#Resource has the prefix rdfs so queries can be cut down to: "SELECT ?u WHERE { ?u a rdfs:Resource }" -p, --list-properties=CLASS Returns a list of properties which pertain to a class. You can use both formats here for the class, either the full name http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#Video or the shortened prefix name nfo:Video. This gives the following result: $ tracker-sparql -p nfo:Video Properties: 2 http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#frameRate http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#frameCount These properties nfo:frameRate and nfo:frameCount can be used in more complex queries (see --query). -n, --list-notifies=CLASS Returns a list of classes which are notified over D-Bus about any changes that occur in the database. CLASS does not have to be sup- plied here. This is optional and filters the results according to any argument supplied. With no CLASS, all classes are listed. -s, --search=TERM Returns a list of classes and properties which partially match TERM in the ontology. This is a case insensitive match, for example: $ tracker-sparql -s text Classes: 4 http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#TextDocument http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#PlainTextDocument http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#PaginatedTextDocument http://www.tracker-project.org/temp/nmm#SynchronizedText Properties: 5 http://www.tracker-project.org/ontologies/tracker#fulltextIndexed http://www.tracker-project.org/ontologies/tracker#fulltextNoLimit http://www.semanticdesktop.org/ontologies/2007/01/19/nie#plainTextContent http://www.semanticdesktop.org/ontologies/2007/03/22/nmo#plainTextMessageContent http://www.tracker-project.org/temp/scal#textLocation -V, --version Print version. EXAMPLES
List all classes $ tracker-sparql -q "SELECT ?cl WHERE { ?cl a rdfs:Class }" List all properties for the Resources class (see --list-properties) $ tracker-sparql -q "SELECT ?prop WHERE { ?prop a rdf:Property ; rdfs:domain <http://www.w3.org/2000/01/rdf-schema#Resource> }" List all class namespace prefixes $ tracker-sparql -q "SELECT ?prefix ?ns WHERE { ?ns a tracker:Namespace ; tracker:prefix ?prefix }" List all music files $ tracker-sparql -q "SELECT ?song WHERE { ?song a nmm:MusicPiece }" List all music albums $ tracker-sparql -q "SELECT ?album ?title COUNT(?song) AS songs SUM(?length) AS totallength WHERE { ?album a nmm:MusicAlbum ; nie:title ?title . ?song nmm:musicAlbum ?album ; nfo:duration ?length } GROUP BY ?album" List all music from a particular artist $ tracker-sparql -q "SELECT ?song ?title WHERE { ?song nmm:performer [ nmm:artistName 'Artist Name' ] ; nie:title ?title }" Set the played count for a song $ tracker-sparql -u -q "DELETE { <file:///home/user/Music/song.mp3> nie:usageCounter ?count } WHERE { <file:///home/user/Music/song.mp3> nie:usageCounter ?count } INSERT { <file:///home/user/Music/song.mp3> nie:usageCounter 42 }" List all image files $ tracker-sparql -q "SELECT ?image WHERE { ?image a nfo:Image }" List all image files with a specific tag $ tracker-sparql -q "SELECT ?image WHERE { ?image a nfo:Image ; nao:hasTag [ nao:prefLabel 'tag' ] }" List all image files created on a specific month and order by date $ tracker-sparql -q "SELECT ?image ?date WHERE { ?image a nfo:Image ; nie:contentCreated ?date . FILTER (?date >= '2008-07-01T00:00:00' && ?date < '2008-08-01T00:00:00') } ORDER BY ?date" SEE ALSO
tracker-store(1), tracker-info(1). http://nepomuk.semanticdesktop.org/ http://www.w3.org/TR/rdf-sparql-query/ GNU
July 2009 tracker-sparql(1)
All times are GMT -4. The time now is 08:44 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy