LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-14-2020, 12:01 PM   #1
wallphoenix
LQ Newbie
 
Registered: Apr 2020
Posts: 2

Rep: Reputation: Disabled
Question Need help with script to copy files from hfs+ (read-only) to ntfs (some chars not allowed)...


I have some recovered files on an hfs+ drive (which is journaled, so I can only mount it read-only), that I need to copy to an ntfs drive so they can be accessed from a friend's windows machine. Unfortunately, there are a number of files with characters in the filenames that are allowed in hfs+, but not windows, so I need to batch rename them before they can be written to the ntfs drive, but without writing on the read-only drive.

My current thought is to use rename's -n option, which prints a list of files that will be renamed to stdout, and use that list with copy to change the name of each of those files.

Can someone help me out with what commands might be needed to send info from that list to copy for the right file in each case? Or is there a better/safer way to do this?

Thanks!
 
Old 04-14-2020, 01:28 PM   #2
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
https://www.cyberciti.biz/faq/linux-rename-file/
 
Old 04-14-2020, 08:57 PM   #3
wallphoenix
LQ Newbie
 
Registered: Apr 2020
Posts: 2

Original Poster
Rep: Reputation: Disabled
The mv command deletes the original file, though, doesn't it? So I can't use mv because the originating filesystem is read-only. I can't use rename alone because it doesn't move the files and I can't rename the files before I copy or move them because, again, the originating filesystem can only be mounted read-only. Or am I missing something there?

Can I combine
Code:
grep <findRegex> | xargs -I '{}' cp '{}' /destinationfolder
with
Code:
rename -n <renameRegex> | xargs -I '{}' cp sourceFile /destinationFolder/'{}'
somehow?
 
Old 04-14-2020, 09:02 PM   #4
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
I know nothing about hfs+, but reasoning suggest that if you copy to a different location, then the original is only being read on the source, and the write is being done elsewhere, therefor it suggest that it is possible to just read then write to a different location giving the file a different (compatible) filename.

testing will revile the truth of this matter.

yes delete removes the original file, so copy is the thing you'll want to do. It is late here, I'd have to test the commands to get it to work myself.

something like
https://unix.stackexchange.com/quest...function-linux

Last edited by BW-userx; 04-14-2020 at 09:06 PM.
 
Old 04-15-2020, 02:08 AM   #5
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,336
Blog Entries: 3

Rep: Reputation: 3731Reputation: 3731Reputation: 3731Reputation: 3731Reputation: 3731Reputation: 3731Reputation: 3731Reputation: 3731Reputation: 3731Reputation: 3731Reputation: 3731
The you can have find call a shell and work with in that. Or if that is too compex then you can have it call a shell script. Here is just a shell which replaces the vowels:

Code:
find . \ 
        -maxdepth 1 \ 
        -type f \ 
        -execdir sh -c " \
                echo cp {} \$(echo \"{}\" \
                | perl -p -e 's|[aeiou]|X|g; \
                              s|^\./|/new/path/|' ) \
        " \;
I've used perl because that gives the most flexibility but a sed script would work too in many situtations.

It would be nice to patch rename to be able to use cp also.
 
Old 04-15-2020, 04:12 AM   #6
JJJCR
Senior Member
 
Registered: Apr 2010
Posts: 2,162

Rep: Reputation: 449Reputation: 449Reputation: 449Reputation: 449Reputation: 449
Lightbulb

Quote:
Originally Posted by wallphoenix View Post
The mv command deletes the original file, though, doesn't it? So I can't use mv because the originating filesystem is read-only. I can't use rename alone because it doesn't move the files and I can't rename the files before I copy or move them because, again, the originating filesystem can only be mounted read-only. Or am I missing something there?

Can I combine
Code:
grep <findRegex> | xargs -I '{}' cp '{}' /destinationfolder
with
Code:
rename -n <renameRegex> | xargs -I '{}' cp sourceFile /destinationFolder/'{}'
somehow?
try this:
grep -E ':[[:alnum:]]+:' | xargs -I '{}' cp '{}' /destinationfolder
 
  


Reply



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
[SOLVED] sed: replace regexp w/ variable #s of chars with the same # of (diff.) chars? kmkocot Linux - Newbie 6 11-18-2011 05:36 AM
Convert DVD image from HFS+ to Hybrid HFS/ISO Dark_Elf Linux - Software 0 10-24-2007 12:42 PM
hfs: unable to find HFS+ superblock VFS: Can't find ext3 filesystem on dev sdb. macroron Linux - Hardware 3 11-20-2006 09:50 PM
Error mounting HFS+ volume: unable to find HFS+ superblock applewax Linux - General 3 05-31-2006 08:45 AM
How do i create HFS, HFS+ and RockRidge CD's? moore757 Linux - Software 2 06-19-2005 10:13 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:42 PM.

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
Open Source Consulting | Domain Registration