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? |
If you do a "man ls", and scroll down, you would see:
Quote:
|
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. |
grrr, beat me to it.
|
Quote:
Gins would need to use grep '@' instead of grep '"@"' I guess. |
Thanks everybody for the contribution.
|
What makes the difference if I simply replace the grep with egrep?
I can't figure out the difference. |
Again, man grep (or man egrep) tells you what you want to know.
|
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. |