List directories only:
ls -d */
or
ls -l | grep ^d
Sample output:
[root@mroot@mXserver ]# ls -d */
archive/ 2015/ water/ linux5/ divine/
archive2/ diff/ sea/ unix7/ divine/
Sample output:
[root@mXserver ]# ls -l | grep ^d
drwxr-xr-x 5 root root 0 Oct 19 13:10 archive
drwxrwxrwx 2 root 98 0 Nov 6 2013 archive2
drwxr-xr-x 3 root 98 0 Oct 19 12:59 2015
drwxrwxrwx 2 root 98 0 Jun 3 2014 diff
drwxr-xr-x 4 root 98 0 Oct 22 13:15 sea
drwxr-xr-x 3 root 98 0 Oct 22 13:18 water
drwxr-xr-x 3 root 98 0 Oct 22 11:23 linux5
drwxr-xr-x 3 root 98 0 Oct 19 16:53 unix7
drwxr-xr-x 3 root 98 0 Oct 19 16:32 divine
drwxr-xr-x 3 root 98 0 Oct 19 15:11 divine
To list files only:
ls -l | grep ^-
To dig further: man ls
Thoughts to ponder:
^ = regex expression for anything that starts or begins with
^d = will return all directories since ls output all directories begins with "d"
^- = will return all files only since files listing with ls begins with "-"
Of course there's a lot of ways to do it, your mileage may vary. But for Linux starters that would be a good start to remember those commands.
Cheers..Till next time..
Comments
Post a Comment