Score:1

easiest way to delete backslash from file name

ar flag

I have a list of files similar to the following and I need to delete the backslash:

\jskadn.txt
\jsandkjasn5.txt

I tried running the following command, but it doesn't work :

rename " \\*.txt" "*.txt"
hr flag
What version / implementation of `rename` are you trying to use here?
PythonUser avatar
ar flag
@steeldriver v 1.13
hr flag
@PythonUser I was more interested in whether it's the perl based file-rename or the util-linux implementation - the version number suggests the former but the syntax of your attempt suggests the latter
Score:3
hr flag
  • With the Perl-based file-rename:

    $ rename --version
    /usr/bin/rename using File::Rename version 1.10
    

    then using a sed-style regular expression s/pattern/replacement/:

    $ rename -vn 's/\\//' \\*.txt
    rename(\jsandkjasn5.txt, jsandkjasn5.txt)
    rename(\jskadn.txt, jskadn.txt)
    
  • With util-linux rename (which takes simple pattern replacement arguments):

    $ rename.ul --version
    rename.ul from util-linux 2.34
    

    then:

    $ rename.ul -vn '\' '' \\*.txt
    `\jsandkjasn5.txt' -> `jsandkjasn5.txt'
    `\jskadn.txt' -> `jskadn.txt'
    

    (you can use \\ in place of '\' if you prefer). Remove the -n (no-op) switch once you are convinced they are doing the right thing.

  • For completeness, using mmv:

    $ mmv -n '\\*' '#1'
    \jsandkjasn5.txt -> jsandkjasn5.txt
    \jskadn.txt -> jskadn.txt
    
  • Or a simple shell loop:

    $ for f in \\*.txt; do echo mv "$f" "${f#?}"; done
    mv \jsandkjasn5.txt jsandkjasn5.txt
    mv \jskadn.txt jskadn.txt
    

    (remove the echo in this case).

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.