LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 11-17-2004, 12:18 PM   #1
Gins
Senior Member
 
Registered: Jul 2004
Location: Germany
Distribution: open SUSE 11.0, Fedora 7 and Mandriva 2007
Posts: 1,662

Rep: Reputation: 47
A strange command


I would like to know the meaning of the following ls command.

ls -F /etc | grep ""@"'


I know grep command uses to find some text strings. Please correct me if my understanding is wrong.

It is looking for @ sign in the etc folder. I don't know what F is doing. What is the F switch here?
-----------------------------------------------------------------------------
I tried it and got the following strange output.
[heden@h216n2fls301o1037 heden]$ ls -F /etc | grep ""@"'
>
-------------------------------------------------------------------------------------
Please tell me what the command is doing?
 
Old 11-17-2004, 01:01 PM   #2
belorion
Member
 
Registered: Aug 2003
Distribution: Slackware 10.0
Posts: 124

Rep: Reputation: 16
If you do a "man ls", and scroll down, you would see:

Quote:
-F Marks directories with a trailing slash (/), doors
with a trailing greater-than sign (>), executable
files with a trailing asterisk (*), FIFOs with a
trailing vertical bar (|), symbolic links with a
trailing at-sign (@), and AF_UNIX address family sock-
ets with a trailing equals sign (=).
In other words, that command is asking for a list of all symbolic links within the /etc directory.
 
Old 11-17-2004, 01:04 PM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Did you do a man ls?

The -F switch is there. Depending on the version of man ls, you get a (not so) elaborate explenation of what it is this switch does.

-F Display a slash (`/') immediately after each pathname that is a
directory, an asterisk (`*') after each that is executable, an at
sign (`@') after each symbolic link, an equals sign (`=') after
each socket, a percent sign (`%') after each whiteout, and a ver-
tical bar (`|') after each that is a FIFO.


ls -F /etc | grep "@" looks for symbolic links in the /etc directory.

BTW: It should be grep "@", grep @ or grep '@'.

Hope this helps.
 
Old 11-17-2004, 01:04 PM   #4
XsuX
Member
 
Registered: Oct 2004
Location: US
Distribution: Fedora Core 1
Posts: 43

Rep: Reputation: 15
grrr, beat me to it.
 
Old 11-17-2004, 01:05 PM   #5
Manish
Member
 
Registered: Feb 2002
Distribution: Debian / Debian-based
Posts: 58

Rep: Reputation: 15
Quote:
Originally posted by belorion
If you do a "man ls", and scroll down, you would see:



In other words, that command is asking for a list of all symbolic links within the /etc directory.
That extra " " around the @ will prevent that from happening.

Gins would need to use grep '@' instead of grep '"@"' I guess.
 
Old 11-17-2004, 01:11 PM   #6
Gins
Senior Member
 
Registered: Jul 2004
Location: Germany
Distribution: open SUSE 11.0, Fedora 7 and Mandriva 2007
Posts: 1,662

Original Poster
Rep: Reputation: 47
Thanks everybody for the contribution.
 
Old 11-17-2004, 01:13 PM   #7
Gins
Senior Member
 
Registered: Jul 2004
Location: Germany
Distribution: open SUSE 11.0, Fedora 7 and Mandriva 2007
Posts: 1,662

Original Poster
Rep: Reputation: 47
What makes the difference if I simply replace the grep with egrep?

I can't figure out the difference.
 
Old 11-17-2004, 01:19 PM   #8
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Again, man grep (or man egrep) tells you what you want to know.
 
Old 11-17-2004, 01:41 PM   #9
Medievalist
Member
 
Registered: Aug 2003
Distribution: Dead Rat
Posts: 191

Rep: Reputation: 56
Except it doesn't work.

The command

ls -F /etc | grep '@'

which as Belorion has explained is probably an attempt to "list of all symbolic links within the /etc directory" will also return the names of all files with an @ character in their names... which is probably not intentional.

You could anchor the grep pattern with a trailing dollarsign, this would return only files with names ending with a @ character, but that just reduces the number of possible bad returns, it doesn't eliminate them.

This does the same job, without the false positives:

ls -l /etc | awk '/^l/ {print $9}'

If you'd like to see not just the links, but also what they point to, you can do this:

ls -l /etc |awk '/^l/ {print $9 $10 $11}'

which will print out the link name->name linked.

Awk is a powerful tool, GNU awk exceptionally so. It's also pretty easy to learn.

--Charlie
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Strange ip from the result of tracert command mrpc_cambodia Linux - Networking 4 01-25-2005 06:49 AM
Strange IP coming from Last -i Command 69_rs_ss Linux - Security 10 12-31-2004 03:14 PM
fopen command not wroking in C strange alix123 Programming 2 11-16-2004 10:48 AM
ls -R command is working strange xailer Linux - Newbie 4 11-25-2003 07:22 PM
strange command prompt salparadise Linux - Newbie 4 01-21-2003 03:28 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 03:10 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
Open Source Consulting | Domain Registration