Find & Replace commands in Konsole

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
Veerstryngh Thynner

Find & Replace commands in Konsole

Post by Veerstryngh Thynner »

Hello all,

Several large virtual musical instrument libraries in my possession can't currently be played in Mint. Hence, the original file extensions need to be altered to formats Mint recognizes.

For example: suppose that the original file extension is '.blub' (totally made-up, of course), but the application is only capable of reading '.quack'. Now, I've been trying to change '.blub' to '.quack' manually, over last weekend - and that's just too time-intensive, to my taste. So I imagine some quicker way with Konsole.

It's just those original file extensions I want Konsole to detect and alter - textually ONLY. But here's the rub: I haven't got a clue which command to use.

Suggestions welcome, of course.

Veerstryngh Thynner
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
xenopeek
Level 25
Level 25
Posts: 29609
Joined: Wed Jul 06, 2011 3:58 am

Re: Find & Replace commands in Konsole

Post by xenopeek »

With your example, this would be the basic command to do that:

find ~ -name '*.blub' -type f -exec rename -v 's/\.blub$/.quack/' {} \;

You can copy and paste the command on http://explainshell.com/ to get a explanation of the commands and options used. In short, this searches for files with the .blub extension in your home directory and executes a rename command on them. The rename command matches .blub at the end of the filename and replaces it with .quack.
Image
Veerstryngh Thynner

Re: Find & Replace commands in Konsole

Post by Veerstryngh Thynner »

Thanks very much!

VT
User avatar
Flemur
Level 20
Level 20
Posts: 10096
Joined: Mon Aug 20, 2012 9:41 pm
Location: Potemkin Village

Re: Find & Replace commands in Konsole

Post by Flemur »

You might also be able to bulk-change the extensions with you file manager ('tis easy with thunar); select several files and see what comes up with a rt-click.
Please edit your original post title to include [SOLVED] if/when it is solved!
Your data and OS are backed up....right?
lmuserx4849

Re: Find & Replace commands in Konsole

Post by lmuserx4849 »

Veerstryngh Thynner wrote: For example: suppose that the original file extension is '.blub' (totally made-up, of course), but the application is only capable of reading '.quack'. Now, I've been trying to change '.blub' to '.quack' manually, over last weekend - and that's just too time-intensive, to my taste. So I imagine some quicker way with Konsole.

Code: Select all

for f in ./*.blub; do mv -- "$f" "${f%.blub}.quack"; done;
man bash --- Checkout parameter expansion. Lots of fun with #, ##, %, %%.
Good book --- The Linux Command Line @ http://linuxcommand.org/tlcl.php --- Checkout his Writing Shell Scripts
Anything else --- Greg Wooledge's Bash FAQ @ http://mywiki.wooledge.org/BashFAQ and maybe stackoverflow.com with tag of [bash]
phd21
Level 20
Level 20
Posts: 10104
Joined: Thu Jan 09, 2014 9:42 pm
Location: Florida

Re: Find & Replace commands in Konsole

Post by phd21 »

Hi Veerstryngh Thynner,

I just read your post and the good replies to it. Here are my thoughts on this as well,

There are numerous ways to easily rename files in bulk. You might be able to do this in your file manager depending on which Linux Mint edition you use, and there are utilities (some GUI) in the Software Manager or Synaptic Package Manager (SPM) that can help with this too, search for "rename". I know you can easily do this with KDE and the Dolphin file manager. Other renaming programs include: mrename, krename, pyrenamer, gwenrename, etc... Some also have specific functions: autorenamer can sort a lot of files into a particular sort order, others are really good for specific types of files like music, photos, etc...

But, do you really want to rename file extensions? That will not always work, because renaming a file does not change its file structure, so the program you want to use may still not work. You might consider renaming one file to test (check) that.

Linux File Renamer Utility
http://www.daanav.com/linux-file-renamer-utility/

pyRenamer: Easy Mass File Renaming in Linux (Gnome)
http://www.webupd8.org/2010/01/pyrename ... ng-in.html

Some Help With Nemo’s Bulk Renaming
http://community.linuxmint.com/tutorial/view/1935

linux mint rename multiple files
https://www.google.com/?gws_rd=ssl#q=li ... iple+files


It would help to have more specific system setup information, see FYI below. It would also help to be more specific on what application(s) you are using and exactly what type of file(s) and their extensions.

FYI: Certain programs, like Amarok music player can easily convert one music file format to another within the application itself, like ".wav" to ".mp3". And, there are numerous conversion programs, and online websites, available to convert most any kind of file into another file format, if you search for them.

And, you might be able to install another program that can read and use your "virtual musical instrument libraries", and or convert them into other usable formats for another program. Maybe "LMMS", "Ardour3", "rosegarden", "muse" & "musescore" in the Software Manager or Synaptic Package Manager (SPM). Search "sound synth" in respositories.

Linux programs that work like "Finale", that you can install and use that may be able to read, use, and or convert the "virtual musical instrument libraries" that you have, see link below.
http://forums.linuxmint.com/viewtopic.p ... it=+finale

The "LinuxSampler" project was founded in 2002 with the goal to produce a free, streaming capable open source pure software audio sampler with high stability, efficiency and very low latency, providing professional grade features, comparable to both hardware and commercial Windows/Mac software samplers and to introduce new features not yet available by any other sampler in the world.
http://www.linuxsampler.org/about.html

"LinuxSampler" downloads - see "ubuntu" section
http://www.linuxsampler.org/downloads.html

Free virtual musical instrument libraries
https://www.google.com/search?q=virtual ... +libraries

The Complete List of Free (sound) Sample Libraries - "flamestudios" has a lot of downloads & interesting information on using Linux and various programs related to this topic (see,"Useful Links", "other stuff").
http://earmonk.com/free-sample-libraries/

FlameStudios.org - music instrument sound site
http://www.flamestudios.org/free/GigaSamples

FYI: It would help everyone here to have more information about your system's setup: like what edition and version of Linux Mint are you using, Cinnamon, Mate, KDE (my favorite), or Xfce; version 17, 17.1, 17.2, or What?; 32-bit or 64-bit? Some more information about your hardware would be useful as well. You can get this information from top of your system menu's Welcome screen, System Information program(s), and the best is by typing in "inxi -Fxz" from a console terminal prompt, which you can then copy and paste back here. This information helps anyone here in this forum to be able to answer any questions you may have better :), thanks. You can even add this information (abbreviated) to your signature using the control panel link in the above left of this forum screen; then when you post a question or reply to one, that info will automatically be there, ex: see mine and others below their posts.
Phd21: Mint 20 Cinnamon & KDE Neon 64-bit Awesome OS's, Dell Inspiron I5 7000 (7573, quad core i5-8250U ) 2 in 1 touch screen
lmuserx4849

Re: Find & Replace commands in Konsole

Post by lmuserx4849 »

...
There are numerous ways to easily rename files in bulk. ...
...
But, do you really want to rename file extensions? ...
Most excellent points.

Note on file extensions: MIME Types Explained: Why Linux and Mac OS X Don’t Need File Extensions

Maybe it isn't the name that should be changed, but what applications are invoked. In KDE,
  1. System Settings -> File Associations, or
  2. File Manager Dolphin -> right click one of the files -> select Open With -> Other, select the application, and check the box "Remember application association for this file type."
Note on finding an executable application, one way is to open a console (KDE Konsole) and type: type -a THE_PGM_NAME.
phd21
Level 20
Level 20
Posts: 10104
Joined: Thu Jan 09, 2014 9:42 pm
Location: Florida

Re: Find & Replace commands in Konsole

Post by phd21 »

Hi Veerstryngh Thynner, and anyone else,

1.) I wanted to be clearer about renaming file extensions, this is not a good idea. If you need, or want, to get certain file types to work in another application(s), the best way is to convert them into the appropriate file type for that application (if it is even possible), or to use another similar application that can use the existing file types without even converting them.

2. As user "lmuserx4849" pointed out, you can choose which applications open certain types of files, when you right click them; and in KDE you can even prioritize those applications.

2.a.) If you right click a file, select "open with", then "other", you can then pick an application that you prefer to open and use for this file type. Of course, you would have to have the application installed first.

2.b.) If you right click a file, click, "properties", then click "file type options", then you will have a lot more choices, including application priority preferences.

3. I just checked out "Krename", and "pyrename". I personally think "Krename" is better and can easily rename files and their extensions (file types) in numerous ways too. It can also do a whole lot more that I did not previously know that it could do. "Pyrename" has some good file name renaming functions too, but I did not see how it could change file extensions.

Hope this helps ...
Phd21: Mint 20 Cinnamon & KDE Neon 64-bit Awesome OS's, Dell Inspiron I5 7000 (7573, quad core i5-8250U ) 2 in 1 touch screen
lmuserx4849

Re: Find & Replace commands in Konsole

Post by lmuserx4849 »

...best way is to convert them into the appropriate file type...
Absolutely right. :-)

It would be like thinking you converted a mp3 to ogg by renaming, but it's stil a mp3 file. The file command will display the type.

Audio files look at audacity, mplayer, ffmpeg.

Sometimes you have to look at the previous software for an export or the current software for an import, as-in, import this file and convert it.

What's the file extension? How were/are you trying to play them or what application? This is more of an application question and less a general script/bash question. The specifics of musical instrument libraries is beyond me.
Locked

Return to “Scripts & Bash”