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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...