plhn
plhn

Reputation: 5273

shell command meaning(backslash and grep)

I mistyped |(bar) as \ (backslash)

locate abcdef \ grep 2

like this. Then bash start to find all files that include '2' in their name.
Why this happen?

Upvotes: 2

Views: 259

Answers (3)

Alfe
Alfe

Reputation: 59486

The backslash just escaped the space after it from being interpreted by the shell as a delimiter of arguments. So what you now called was the locate command with three arguments, the first being abcdef, the second being  grep (with a leading space), and the third being 2.

locate in such a case lists all the files which have at least one of the search terms in them.

Upvotes: 3

suhas
suhas

Reputation: 733

your command will locate the all files in the system which has 2 in its file name. Because \ is a globbing character, which disables the implicit replacement of NAME by *NAME*.

locate filename \ grep 2

this will neglect the filename and start searching for for file which has 2 in its filename

Upvotes: 0

anubhava
anubhava

Reputation: 785376

Your command:

locate abcdef \ grep 2

made rest of text after locate i.e. \ grep 2 as arguments for locate command hence it started processing locate command (grep didn't execute at all).

Upvotes: 5

Related Questions