Moving / copying files / folders to linux / solaris using only bash built-in modules

There was a situation where someone moved the entire rootdir to subdir on a remote system, so all system tools like cp, mv, etc., no longer worked. We had an active session, but could not find a way to copy / move files using only bash built-in modules.

Does anyone know how to achieve this?

I even thought about copying a cp or mv binary to currentdir using

while read -r; do echo $LINE; done 

and then redirect this to a file, but that did not work. Guess because of all the special non-printable characters in the binary that cannot be copied / displayed with an echo.

thanks.

+6
linux bash solaris
source share
6 answers
 /newroot/lib/ld-linux.so.2 --library-path /newroot/lib \ /newroot/bin/mv /newroot/* / 

(Similar for Solaris, but I believe the dynamic linker is called ld.so.1 or something like that.)

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

 LD_LIBRARY_PATH=/newroot/lib /newroot/bin/mv /newroot/* / 
+10
source share

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

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

I think there might be a problem with the lack of ld-so in the expected location.

+5
source share

Here's a reasonable ghetto replacement for cp . You will need echo -E if the file ends with a new line (for example, most text files), echo -nE if it is not (like most binary files).

 echo -nE "`< in.file`" > out.file 
+3
source share
 /subdir/bin/mv /subdir / 

or am i missing something in your explanation?

0
source share

If you have access to another computer, one of them is to download and compile the Busybox binary. This will be a single binary file containing most of the common tools needed to restore your system. This may not work if your system is removed.

0
source share

Old thread, but got the same dumb error. / lib 64 was removed in / lib 64.bak and everything stopped working.

This was an x86_64 installation, so there was no effective solution:

 # /lib64.bak/ld-linux.so.2 --library-path /lib64.bak/ /bin/mv /lib64.bak/ /lib64 /bin/mv: error while loading shared libraries: /bin/mv: wrong ELF class: ELFCLASS64 

In this case, you need to use another ld-linux:

 # /lib64.bak/ld-linux-x86-64.so.2 --library-path /lib64.bak/ /bin/mv /lib64.bak/ /lib64 

Now the system is saved. Thank you ephemer!

0
source share

All Articles