Linux - GeneralThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: open SUSE 11.0, Fedora 7 and Mandriva 2007
Posts: 1,662
Rep:
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:
-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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.