LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-08-2014, 01:15 PM   #1
Boomhenk
LQ Newbie
 
Registered: Jun 2014
Posts: 1

Rep: Reputation: Disabled
Linux commandline add map structure as prefix to files.


Hello,

I am trying to get the grasp of linux commandline, but this problem I just can't solve.

I would like to merge multiple folders, possibly containing files that may cause duplicate names, into one. To prevent dupes, I would like to have part of the map structure prepended to the file names. At least, that seemed the most obvious solution. So I would like:

./map1/a.dat ~> ./map1_a.dat
./map1/b.dat ~> ./map1_b.dat
./map2/a.dat ~> ./map2_a.dat (no duplicate filename )
and trivially: ./a.dat -> ./a.dat

and so on, for all maps within ./ .
How should i go about this?

~

Boomhenk

Last edited by Boomhenk; 06-08-2014 at 02:07 PM.
 
Old 06-09-2014, 10:22 AM   #2
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,714

Rep: Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280
I will direct you to the "find" command first. This will list the files (as a path name). Be sure to only look for regular files.

Next, the output of that will be files like ./map/a.dat. (you can avoid the leading ./ if you specify map as the directory to process).

This can be piped to a loop to process each name - replacing the "/" with a "_", you now have the original name, and the replacement; at which point you can use the mv <orginalname> <replacementname>...

If you use the mv command, the directory tree processed will be empty of anything except other directories.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
what is the structure of LILO map file? mhdjavanmardi Linux - General 2 05-17-2012 04:34 AM
Add your local knowledge to the map with Google Map Maker for the United States mjolnir General 4 05-04-2011 05:27 PM
C++ graph / map data structure Galib Programming 3 10-17-2010 09:50 PM
Rename files and add prefix SevenMedia Linux - Newbie 6 01-16-2008 08:04 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:20 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration