Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

find folders in a directory, without listing the parent directory

Tags:

Having trouble listing the contents of a folder I'm not in, while excluding the actual folder name itself.

ex:

root@vps [~]# find ~/test -type d /root/test /root/test/test1 

However I want it to only display /test1, as the example.

Thoughts?

like image 839
cbcp Avatar asked Nov 14 '12 18:11

cbcp


People also ask

How do I search only directories in a specific directory?

You can use combination of ls command, find command, and grep command to list directory names only. You can use the find command too.

Which directory does not have a parent directory?

The top-most directory in such a filesystem, which does not have a parent of its own, is called the root directory.

How do I get a list of folders in a folder?

You can use the DIR command by itself (just type “dir” at the Command Prompt) to list the files and folders in the current directory.

How do I get a list of all folders and subfolders?

Substitute dir /A:D. /B /S > FolderList. txt to produce a list of all folders and all subfolders of the directory. WARNING: This can take a while if you have a large directory.


1 Answers

There's nothing wrong with a simple

find ~/test -mindepth 1 

Similarly, this will have the same effect:

find ~/test/* 

as it matches everything contained within ~/test/ but not ~/test itself.

As an aside, you'll almost certainly find that find will complain about the -mindepth n option being after any other switches, as ordering is normally important but the -(min|max)depth n switches affect overall behaviour.

like image 93
sanmiguel Avatar answered Oct 21 '22 14:10

sanmiguel