Jump to content

List doubts


Recommended Posts

Hi I've read the man but haven't got luck sorting a list by different parameters like Date, Name, properties (rxw), node etc.

 

Also I want to know how can I list directories (folders) only. I've tried ls -d or ls --directories but didn't work, just got a /.. output.

Link to comment
Share on other sites

From memory, the only relevant option I know for ls is -t, which will sort by date/time. Sorting by name is the default. For other kinds of sorts, I think you'll have to pipe the ls (ls -l actually) output into the sort command.

 

To have the list of directories, there are two methods:

ls -la | grep '^d'

or

find . -type d -maxdepth 1 -print

 

Yves.

Link to comment
Share on other sites

From memory, the only relevant option I know for ls is -t, which will sort by date/time. Sorting by name is the default. For other kinds of sorts, I think you'll have to pipe the ls (ls -l actually) output into the sort command.

There's -S for size, -t for time (as you mentioned), -r for "reverse what would normally be returned (including -S, etc.)", -Y for sort-directories-first (not in mainline coreutils),

Sort entries alphabetically if none of -cftuSUXY nor --sort.

So I guess you take a look at man ls.

Directories only with said grep ^d

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...