Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Move/copy files/folder in linux/solaris using only bash built-ins

There was a situation when somebody moved the whole rootdir into a subdir on a remote system, thus all the system tools like cp, mv, etc didn't work anymore. We had an active session though but couldn't find a way to copy/move the files back using only bash built-ins.

Do somebody know of a way to achieve this?

I even thought about copy the cp or mv binary in the currentdir with

while read -r; do echo $LINE; done

and then redirect this to a file, but it didn't work. Guess because of all the special non printable chars in a binary file that can't be copied/displayed using echo.

thanks.

like image 874
KullDox Avatar asked Apr 07 '10 18:04

KullDox


2 Answers

/newroot/lib/ld-linux.so.2 --library-path /newroot/lib \
    /newroot/bin/mv /newroot/* /

(Similar for Solaris, but I think the dynamic linker is named ld.so.1 or something along those lines.)

Or, if your shell is sh-like (not csh-like),

LD_LIBRARY_PATH=/newroot/lib /newroot/bin/mv /newroot/* /
like image 155
ephemient Avatar answered Sep 28 '22 08:09

ephemient


If you have prepared with sash pre-installed, then that is static and has a copy built-in (-cp).

Otherwise LD_LIBRARY_PATH=/copied/to/path/lib /copied/to/path/bin/cp might work?

I think it might have a problem with not having ld-so in the expected place.

like image 27
Douglas Leeder Avatar answered Sep 28 '22 08:09

Douglas Leeder