problems with the linux command line

Asked by Arpad Balind

Hi ! I started to learn the linux programming, and related to the command line I have some problems.
1. What shall I type into the gnome-terminal to find a specific file in the whole filesystem that for example contains the word segment *mo*?

2. I would like to rename the content of some folders the following way: every letter should be lowercase and spaces, underscores would be replaced by hyphens, recursively.
I do not wish to rename manually, for example: 03_Little_Richard_Tutti_Frutti ---> 03-little-richard-tutti-frutti.
How can I realize it?

Question information

Language:
English Edit question
Status:
Answered
For:
Ubuntu bash Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
actionparsnip (andrew-woodhead666) said :
#1
Revision history for this message
Arpad Balind (arpad-balind38) said :
#2

Thank you! At the 2nd point I found a very good script, by I further need some extensions:

#!/bin/bash

 ls | while read src
  do
    dest="$(echo "$src" | tr ' ' "-" | tr "[:upper:]" "[:lower:]" )"
    if [ "$src" != "$dest" ]
    then
      if [ -f "$dest" ]
      then
        ls -l "$src" "$dest"
        echo "Can't rename \"$src\", \"$dest\" already exist"
      else
        echo "$src" "->" "$dest"
        mv "$src" "$dest"
      fi
    fi
  done

But this results some problems; for example
03 - Louis Amstrong When the Saints.mp3 --> 03---louis-amstrong-when-the-saints.mp3
Where and what do I insert to eliminate the string --- (triple hyphen) to a single hyphen? How can I eliminate commas, ampersands ?

Revision history for this message
mycae (mycae) said :
#3

Arpad:

use "sed"
http://www.grymoire.com/Unix/Sed.html

sed can manipulate any input string, and perform some kind of edit (with similar syntax to regexps) to generate an output string:

for example

$ echo "hello world" | sed 's/hello/goodbye/'
goodbye world

or

$ echo "hello world" | sed 's/[a-z]ello/goodbye/'
goodbye world

or

echo "hello world" | sed 's/[a-z]*/goodbye/'
goodbye world

Revision history for this message
Sam_ (and-sam) said :
#4
Revision history for this message
Midnight Matt (randygaffer) said :
#5

To reduce multiple consecutive occurrences of a character down to a single instance of that character, use the `tr` utility. For example:
$ echo '--------------' | tr -s '-'
$ -
The `-s` option is known as the `squeeze` option of the tr utility.

And to completely eliminate a character from a string, use the `tr` utility w\ the `-d` (delete) option.

$ echo '--------------' | tr -d '-'
$

Can you help with this problem?

Provide an answer of your own, or ask Arpad Balind for more information if necessary.

To post a message you must log in.