unix - accidentally moved everything under root to /old - Solaris 10

If you no longer have a shell running as root, you'll have to reboot into rescue media. Anything will do as long as it's capable of mounting the root filesystem read-write.

If you can still run commands as root, everything's copacetic. Set the environment variable LD_LIBRARY_PATH to point to the directories containing libraries used by the basic system tools. That's at least /usr/lib on a 32-bit Solaris, /usr/lib/64 on a 64-bit Solaris, possibly other directories (I don't have access to Solaris 10 now to check). To run an executable, prefix it with the runtime linker: /usr/lib/ld.so.1 (for a 32-bit executable) or /usr/lib/64/ld.so.1 (for a 64-bit executable) — now moved to /old. Thus you should be able to recover with something like:

LD_LIBRARY_PATH=/old/usr/lib
export LD_LIBRARY_PATH
/old/usr/lib/ld.so.1 /old/usr/bin/mv /old/* /

There is no way to create a directory or copy binary files with just shell builtin commands (although Gilles describes a smart potential workaround in his reply).

You best option is to boot Solaris on a external media (dvd, usb stick), mount or import the file system(s), and fix the mess with something like:

  • Boot a Solaris installation disk and select to run a shell.

  • Mount the old root (and all other file systems if any) under some directory like /mnt or /a. The Solaris boot disk might help you doing that when it detects existing file systems.

  • put the files back to their original location with this command (assuming all is mounted under /mnt):

    cd /mnt/old
    find . -depth | cpio -pdlmPV@ /mnt
    
  • Reboot your system

    init 6
    

If you are using ZFS and a recent snapshot exists, backing up the /old directory elsewhere then reverting to the last snapshot might be also an option.