ls only files or directories examples in linuxOctober 16, 2019Test dir linux ls only directoryFirst way➜ ls -d */-d Directories are listed as plain files (not searched recursively). */ is a pattern that matches all of the subdirectories in the current directory (* would match all files and subdirectories; the / restricts it to directories). Reference：https://stackoverflow.com/questions/14352290/listing-only-directories-using-ls-in-bash-an-examination Second way: using linux ls and linux grep command ➜ ls -l | grep "^d"Third way：using linux find command➜ find . -type d -maxdepth 1linux ls only filesFirst way➜ ls -l | grep -v "^[d|l]" ➜ ls -l | grep "^-"Second way: using linux find command➜ find ./ -type f -maxdepth 1Related posts:linux grep regex examples grep show lines before and after linux grep command – grep multiple patterns linux grep command – grep only show match linux grep command – grep not include, grep reverse match How to count using the grep command in Linux/Unix linux grep process by name/by id and kill example, and grep -v example grep multiple words/patterns/strings, and/or condition, use -e or regex How to sort by size, type, time, name using linux ls command tail command tutorial in linux/unix with examples and use cases Tags:ls, ls dir, ls filesAdd a Comment Cancel replyYour email address will not be published. Required fields are marked *Comment Save my name, email, and website in this browser for the next time I comment.