Remove all brackets in filename

102

Solution 1

i found this one liner and this work :

for x in *[*; do mv -- "$x" "${x//[/}"; done

this should do the job , just replace left or right bracket each time yu execute this commandl

Solution 2

Solution posted by @juicebyah will only remove the initial bracket. If OP wants to remove both brackets, it is better to use sed in this way:

find . -type f -iname "*[*" | \
while IFS= read -r line; \
do mv "$line" "$(printf %s "$line" | sed -re 's/(\[|\])//g')"; done;
Share:
102

Related videos on Youtube

greg0ire
Author by

greg0ire

Updated on September 18, 2022

Comments

  • greg0ire
    greg0ire over 1 year

    I've been using a symfony1 plugin repository in a project repository, using git-subtree, but I can't always see my history.

    Basically, the plugin project has a composer.json file I merged the plugin under the plugins/MyPlugin subtree.

    When I do git log, I can see the history. However, when do git log -p plugins/MyPlugin/composer.json or git log plugins/MyPlugin/composer.json, I only see a merge commit. Why ?

    But maybe subtree isn't really the right tool. What I want to do is forget completely about the plugin repository and pretend that its commits actually happened in the project repository, modifying files in the plugins/MyPlugin directory.

    EDIT Ok, I solved my problem by rewriting the plugin history with a filter-branch, and merging the result in the project repository. Still the first question remains. For science.

  • Mathias Begert
    Mathias Begert almost 9 years
    you can lose the trailing /; so "${x//[}" instead of "${x//[/}"
  • juicebyah
    juicebyah almost 9 years
    nice! it works , remove all brackets in filename.
  • Gilles 'SO- stop being evil'
    Gilles 'SO- stop being evil' almost 9 years
    Make that "${x//[][]}" to replace both brackets. (Yes, it does look weird.)
  • cptMikky
    cptMikky about 8 years
    Are you using BASH or ZSH? Are you sure you've copied the code correctly?