
I hope you are familiar with the find command.
#Mac terminal ftp view ls of local directory how to
Here's how to use the find command to list only the subdirectories: find directory_path -maxdepth 1 -type d Use find command to list only directories You can use grep to filter the contents that start with d: ls -l | grep '^d'īut this gives you a lot more fields than just the directory names: Documents]$ ls -l | grep '^d' If you long list the contents, you can identify the directories because start with d. You can always rely on the good old grep command for filtering the output for specific content. */ to display hidden directories, but it only displays hidden directories. 1 abhishek abhishek 44 Nov 7 18:22 Documents/my_dir/ĭid you notice that it doesn't list the hidden directory? That's one shortcoming of this method. 1 abhishek abhishek 16 Nov 7 18:22 Documents/another_dir/ĭrwxrwxr-x. Here's an example where I move out of the Documents directory and then list only the directories inside Documents directory: ~]$ ls -ld Documents/*/ĭrwxrwxr-x. In this situation, you can use */ at the end of the path of the directory with ls -d: ls -d Path/To/Dir/*/ What if you are not in the same directory? The above command works in the current directory. List only subdirectories in a specific directory 1 abhishek abhishek 44 Nov 7 18:22 my_dir 1 abhishek abhishek 16 Nov 7 18:22 another_dirĭrwxrwxr-x. If you do not want the trailing slash (/) at the end of the directory names, you can use the cut command to cut it out: Documents]$ ls -ld */ | cut -f1 -d'/'ĭrwxrwxr-x. 1 abhishek abhishek 44 Nov 7 18:22 my_dir/ 1 abhishek abhishek 16 Nov 7 18:22 another_dir/ĭrwxrwxr-x. You may combine it with long listing option -l and most other options: Documents]$ ls -ld */ĭrwxrwxr-x. This picture depicts the difference pretty well. With *, you list all the content (including contents of the subdirectories) and the / restricts the pattern to directories. The -d option list directories not its contents (which includes file, directories etc). Why */? Because without it, ls -d will only return the directory name. Here's the output it shows: Documents]$ ls -d */

To list only the subdirectories, use the -d option with ls command like this: ls -d */ It is always good to do it with the familiar ls command because this is the command you use for displaying the content of a directory.

Here's the content of the directory I am going to use in the examples here: Use ls command to list directories only Listing only the directories is no different:ĭon't worry. Like anything in Linux, there are several ways to accomplish the same task. The resulting filename can then be altered by the remote server if sunique is on.The ls command in Linux is used for listing the contents of any directory.īy default, it lists all the contents, be it a file or a directory or a link or a named pipe.īut what if you want to list only the directories? How do you that? For mput commands and put commands with unspecified remote file names, the remote filename is the local filename, which can be altered by a ntrans or nmap setting. The resulting filename can then be altered if runique is on.ĥ. For mget commands and get commands with unspecified local file names, the local filename is the remote filename, which can be altered by a case, ntrans, or nmap setting.

put), only the first filename generated by the 'globbing' operation is used.Ĥ. If the ftp command expects a single local file (e.g. Failing the above checks, if `globbing' is enabled, local file names are expanded according to the rules used in the csh(1) c.f. A particularly useful example of this mechanism is: `dir ' |more'.ģ. If the shell command includes spaces, the argument must be quoted e.g. ftp then forks a shell, using popen(3) with the argument supplied, and reads (writes) from the stdout (stdin). If the first character of the file name is `|', the remainder of the argument is interpreted as a shell command. If the file name `-' is specified, the stdin (for reading) or stdout (for writing) is used.Ģ. Files specified as arguments to ftp commands are processed according to the following rules.ġ.
