Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Rename a folder called '\n'

  • 11-07-2008 01:35PM
    #1
    Registered Users, Registered Users 2 Posts: 2,011 ✭✭✭


    For some reason and I don't know how, but a user has renamed a folder to '\n'.

    So when you ls -l it just has a '?', but when you do an ls -lb it comes up as '\n'.

    Any ideas how I could rename this folder? I've tried

    mv '\n' newfoldername

    Any help appreciated.


Comments

  • Registered Users, Registered Users 2 Posts: 2,011 ✭✭✭colm_c


    Tried those

    Getting an error:
    mv: cannot stat `n': No such file or directory
    mv: cannot stat `\\n': No such file or directory


  • Closed Accounts Posts: 66 ✭✭Danimalito


    hmm.. you can probably do something like this (assuming bash shell)

    % for i in *; do printf "rename $(ls -db $i) ? [y/N] "; read a; [ "$a" == "y" ] && mv -- $i targetdir;done


  • Registered Users, Registered Users 2 Posts: 2,011 ✭✭✭colm_c


    Not working either.

    I might have to look at a backup and restore from that.


  • Closed Accounts Posts: 12 Aquafresh


    When you say: "the folder name is '\n'"
    I think what you really mean is: "the folder name is $THE_NEWLINE_CHAR" (if you get me)

    '\n' is just an escape sequence used in C etc. for inserting a newline character (line feed, 0x0a) in a string. i.e. the string
    "asf\n\nasfhkasf\n" in actuality (i.e. if viewed in a debugger etc.) is:
    "asf$(0x0a)$(0x0a)nasfhkasf$(0x0a)

    so basically your shell is interpreting the directory name (0x0a) as '\n' and printing that for you. To delete/rename/remove the dir you just need to say 'mv $(0x0a) foo'

    In zsh (emacs mode) I can do this by saying:
    mv 'C-q
    ' foo

    (this prints like:
    [root@bbbox]/root# mv '
    quote> ' foo
    )



    in bash:
    mv 'C-vC-j' foo

    (this prints like:
    [root@bbbox ~]# mv '
    > ' foo
    )

    C-q means press control and q, C-v means press control and v.

    Hope this helps


  • Registered Users, Registered Users 2 Posts: 2,011 ✭✭✭colm_c


    Aquafresh wrote: »
    When you say: "the folder name is '\n'"
    I think what you really mean is: "the folder name is $THE_NEWLINE_CHAR" (if you get me)

    '\n' is just an escape sequence used in C etc. for inserting a newline character (line feed, 0x0a) in a string. i.e. the string
    "asf\n\nasfhkasf\n" in actuality (i.e. if viewed in a debugger etc.) is:
    "asf$(0x0a)$(0x0a)nasfhkasf$(0x0a)

    so basically your shell is interpreting the directory name (0x0a) as '\n' and printing that for you. To delete/rename/remove the dir you just need to say 'mv $(0x0a) foo'

    In zsh (emacs mode) I can do this by saying:
    mv 'C-q
    ' foo

    (this prints like:
    [root@bbbox]/root# mv '
    quote> ' foo
    )



    in bash:
    mv 'C-vC-j' foo

    (this prints like:
    [root@bbbox ~]# mv '
    > ' foo
    )

    C-q means press control and q, C-v means press control and v.

    Hope this helps

    You sir are a legend.

    Worked a treat.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 37,485 ✭✭✭✭Khannie


    impressed tbh.


  • Registered Users, Registered Users 2 Posts: 1,562 ✭✭✭cance


    Khannie wrote: »
    impressed tbh.

    agreed, and that he's been registered for 10 years and only posted 8 times... that is legendary lurking.


  • Registered Users, Registered Users 2 Posts: 37,485 ✭✭✭✭Khannie


    cance wrote: »
    that is legendary lurking.

    HAHAHA. :D


Advertisement