1
From this Question I know that I can run ls -d
to show the directory names only instead of their contents.
Short question:
How to do the same with sftp
.
Specific problem:
I have a script which should gather directories:
echo ls -1 '*/*/Folder*' | sftp -i /path/to/key user@host
If there is more than one folder matching, I receive a list of the folders:
path/to/Folder1
path/to/Folder2
[...]
If there is only one folder matching, I receive the contents of that folder:
path/to/Folder1/File1
path/to/Folder1/File2
[...]
But I'd like to see just this:
path/to/Folder1
Note:
- I cannot just use
ssh -c
as I don't have full access.
You could add
| cut -d / -f 2 | uniq
to your script to only get the uniques. – Mikael Kjær – 2017-11-08T09:38:34.107I need the full path, so that does not work. But good idea. This works:
| sed -e 's/\/[^\/]*$//' | uniq
because folders will always have a trailing/
and I have no folders below. It's somehow a dirty workaround though... Any better solution? – pLumo – 2017-11-08T09:42:11.540I think everything is going to be a workaround. At least I see nothing in the
– Mikael Kjær – 2017-11-08T09:53:04.203ls
included in sftp which can help you.