LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   A strange command (https://www.linuxquestions.org/questions/linux-general-1/a-strange-command-256053/)

Gins 11-17-2004 12:18 PM

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?

belorion 11-17-2004 01:01 PM

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.

druuna 11-17-2004 01:04 PM

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.

XsuX 11-17-2004 01:04 PM

grrr, beat me to it.

Manish 11-17-2004 01:05 PM

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.

Gins 11-17-2004 01:11 PM

Thanks everybody for the contribution.

Gins 11-17-2004 01:13 PM

What makes the difference if I simply replace the grep with egrep?

I can't figure out the difference.

druuna 11-17-2004 01:19 PM

Again, man grep (or man egrep) tells you what you want to know.

Medievalist 11-17-2004 01:41 PM

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


All times are GMT -5. The time now is 01:22 PM.