LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-24-2010, 03:52 PM   #1
arun17reddy
LQ Newbie
 
Registered: May 2010
Posts: 9

Rep: Reputation: 0
How to find commands starting with a given letter like for example 's'?


thank you
 
Old 05-24-2010, 03:55 PM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Are you OK with only the s* files in the directories listed in $PATH?
 
Old 05-24-2010, 04:29 PM   #3
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,811
Blog Entries: 1

Rep: Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191
That's an interesting one.
You can type 's' and then type TAB for auto-completion. It will be give you all commands available in your path. Mind you, the list will be different when done as root (due to different $PATH).
 
Old 05-24-2010, 04:39 PM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Code:
ls /usr/bin | grep '^s'
(repeat for other directories)

To search every "bin" directory----Untested:
Code:
for dir in $(ls -R / | grep 'bin$'); do ls $dir | grep '^s'; done
 
Old 05-25-2010, 03:57 AM   #5
salasi
Senior Member
 
Registered: Jul 2007
Location: Directly above centre of the earth, UK
Distribution: SuSE, plus some hopping
Posts: 4,052

Rep: Reputation: 881Reputation: 881Reputation: 881Reputation: 881Reputation: 881Reputation: 881Reputation: 881
You might like this:

Quote:
man -k * | grep -i ^s
a few limitations:
  • it will list anything that has a man page, and give a brief description of the 'command' - while the one line description may be an advantage (it would be to me), but you didn't ask for that
  • most distros have a man page for everything - does yours (I'm guessing that some of the very 'small' distos may not)?
  • the things for which there are man pages goes a bit further than normal user commands and includes system calls; this is not a problem for me, you may not like it though
  • tried it on a bare-ish Ubuntu box and a rather heavily installed SuSE laptop; it was noticeably slower on the SuSE box, presumably due to the amount of 'stuff' concerned, and therefore the amount of stuff that goes through the filter, but be aware that YMMV.
 
Old 05-25-2010, 06:26 AM   #6
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720
Code:
#!/bin/sh
IFS=':'
for dir in $PATH
do
	ls "$dir" | grep "$1"
done
If we were to call this script "grepcommands" and give it executable permissions, we could do this:

Code:
./grepcommands '^s'
I tested it here and it worked!
 
Old 05-25-2010, 06:31 AM   #7
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720
New and improved:

Code:
 
#!/bin/sh

if [ $# != 1 ]
then
	echo 'Usage: '"$0"' [extended-regexp]'
	exit 1
fi

IFS=':'
for dir in $PATH
do
	ls "$dir" | grep --extended-regexp "$1"
done
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Where to find commands? spotterke Linux - Newbie 4 09-11-2008 05:34 PM
Command to list files starting with uppercase letter djfog Linux - Newbie 5 07-04-2008 06:30 AM
slackware commands (stopping samba from starting automatically, etc) fyr3 Slackware 6 06-24-2007 09:21 PM
find commands shawniecas Linux - Newbie 4 06-14-2007 12:25 PM
Script to move directories based on first letter to a new directory of that letter tworkemon Linux - Newbie 8 01-30-2007 08:18 PM


All times are GMT -5. The time now is 07:05 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration