Utsav
Utsav

Reputation: 5918

ssh to another server and list only the directories inside a directory

dev1.ab.com is the current server, I have to ssh to tes1.ab.com, move inside the path /spfs/tomcat/dir and list all the directories (no files) present there.

For this I am using the below command from the command line of dev1.ab.co

*ssh tes1.ab.com " ls -1d / /spfs/tomcat/dir "

but in output I am getting output the directories of home is /spfs/tomcat, I have also tried

*ssh tes1.ab.com " ls -lrt /spfs/tomcat/dir | ls -1d /"

*ssh tes1.ab.com " cd /spfs/tomcat/dir | ls -1d /"

and ended up with nearly same result.

can someone help me to write a command in command line of dev1.ab.com to ssh to tes1.ab.com and get the output as the list of directories present in /spfs/tomcat/dir directory.

Upvotes: 1

Views: 2874

Answers (2)

spirit
spirit

Reputation: 1

you could use the following

ssh tes1.ab.com 'ls -ld /spfs/tomcat/dir/*/'

to list all the directories alone inside /spfs/tomcat/dir

Upvotes: 0

pkuhar
pkuhar

Reputation: 601

Use find instead of ls.

ssh tes1.ab.com "find /my/folder -type d"

add -maxdepth 1 to list only the first level

Upvotes: 3

Related Questions