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

English Edit question
Ubuntu bash Edit question
No assignee Edit question
Last query:
Last reply:
Revision history for this message
actionparsnip (andrew-woodhead666) said :
Revision history for this message
Arpad Balind (arpad-balind38) said :

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


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

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 :


use "sed"

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


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


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

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

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.