LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   PWD and TREE dir structure dump restore (https://www.linuxquestions.org/questions/linux-server-73/pwd-and-tree-dir-structure-dump-restore-709575/)

debajit_kataki 03-06-2009 03:56 AM

PWD and TREE dir structure dump restore
 
I have two questions.

(1) When i change to a soft linked directory, i actually land up in a new location, but PWD command still shows, not the exact folder location but the soft link source folder only. How to see the actula present working Directory.

(2) I have a server, where i need to to take Dir Tree structure dump, only, as data is not of much important, but also, in time of scarctity, i will have to to immediately create all those dir struvcture as per the Tree command output. How would i be able to do it fast, as i have some thousand of (sub)(sub)(dir).


Regards
DEBU

ilikejam 03-06-2009 04:59 AM

Hi.

1) Use '/bin/pwd' instead of 'pwd' to get the real pathname.

2) Have a look at the 'install' command, and 'mkdir -p'. install will copy a file, and create all the parent directories as needed, mkdir -p will do the same sort of thing, but with directories.

Dave

ilikejam 03-06-2009 05:11 AM

You could also do something like
# find /path/to/tree -type d > dirlist
to get a list of the directories.
Then
# for dir in `cat dirlist`; do mkdir "$dir"; done
to recreate them.

Dave

Reuti 03-07-2009 09:20 AM

Quote:

Originally Posted by debajit_kataki (Post 3466683)
I have two questions.

(1) When i change to a soft linked directory, i actually land up in a new location, but PWD command still shows, not the exact folder location but the soft link source folder only. How to see the actula present working Directory.

$ pwd -P

will show the physical path.

Quote:

Originally Posted by debajit_kataki (Post 3466683)

(2) I have a server, where i need to to take Dir Tree structure dump, only, as data is not of much important, but also, in time of scarctity, i will have to to immediately create all those dir struvcture as per the Tree command output. How would i be able to do it fast, as i have some thousand of (sub)(sub)(dir).

The find command ilikejam mentions is perfect, but I saw situations where the command line got too long as the whole content of the directory listing will make one long shell line. It might be necsessary to call mkdir in smaller chunks (and keep the directory listing relative, i.e. avoiding the leading / to be included):

$ cd new_target_directory
$ (cd old_source_directory; find . -mindepth 1 -type d) | xargs -n 50 mkdir


-- Reuti

debajit_kataki 03-11-2009 09:01 AM

Thanks Dave and Reuti. The solution really helped me.

~Best Regrads
Debu


All times are GMT -5. The time now is 02:50 PM.