1753779 Members
7816 Online
108799 Solutions
New Discussion юеВ

commandline

 
Avery_1
Advisor

commandline

1.what is the commandline to print all the hidden files in the current working directory sorted in reverse alphabetical order?

2.what is the command line to print the usernames that have active processes running on the system.The commandline should print the user names only once(no repetition).

thanks in advance....
hey
4 REPLIES 4
Khalid A. Al-Tayaran
Valued Contributor

Re: commandline


Hi,

1-
ls -ahl (on RedHat)

2-

ps -euf | more
ps -eu | more

Jerome Henry
Honored Contributor

Re: commandline

Whow !
You were tough with Khalid, who did give you the corract answer :-))
'ls' is command for listing current directory, and you had arguments with '-' to precise the command :
-a says to show also hidden files, starting with . (you didn't precise if you needed to see only those file, so we assume that you want to see them all)
-h is not necessary, but asks that sizes are printed in human readable format (kb, mb instead of bytes only)
-l uses long listing format.
He left behind 'r', which completes your need by printing those files in reverse order. Your answer comes to :
ls -alr
If you want only hidden files to be sorted, then you have to go a little further, on sorting only those files by the 'grep' command :
'ls -alr | grep .'
Same as before, sorting only what include that hidden code, '.'.

Same for second command : I would use a slight variation :
ps command of course, to list processes running.
I would add :
-a to list them all (even those not belonging to you)
-u to sort by user
-x to select processes without controlling ttys.
I would use for your confort a redirection to 'sort', to have them once (no repetition), with -d for example to get them in alphabetical order.
Your command becomes :
'ps -aux | sort -d'.

Note that you can precise on 'ps' '--user' to select by effective user name or ID.
RGDS
J
You can lean only on what resists you...
Charles Coombs
Occasional Advisor

Re: commandline

Avery,
A general piece of advice regarding unix commands. Try using man, it is a beautiful thing and one of the things that can get you adjusted to linux command line (presumably you are getting wheened off windoze).

e.g. type this at command prompt:

man ls

Tells you everything you needed. Between man and an understanding of pipes, |, the world is your oyster.

peace.
Run-of-the-mill dumbfounded J2EE developer.
Khalid A. Al-Tayaran
Valued Contributor

Re: commandline



Hi,

// No Points Please //

Thanks Jerome.... Good detailed answer.