Directory only lists various methods

(1) Use ls -d: $ ls -d * /

(2) in conjunction with grep ls -F: $ ls -F | grep "/ $"

(3) in conjunction with grep ls -l: $ ls -l | grep "^ d"

(4) 使用find:$ find . -type d -maxdepth 1 -print

 

working principle

When using ls -F option, all the items back output will be more of a character that represents the file type, such as @, *, | and so on. Corresponding directory is / character. We use grep to filter only those marked as end of line / $ output items.

The first character of each line represents the ls -l output file type. File type character directory is d. Therefore, we filtered starting with the d-line grep. ^ Is the beginning of the line mark.

When you can use the find command to specify parameters for -type d and maxdepth set to 1, it is because we do not need to continue to search down subdirectories.

Guess you like

Origin www.cnblogs.com/lfjn/p/11400955.html