2

I have the following command which works:

ls -la | awk '$5 > 2'

I'm trying to alias the entire thing. If I try a naive way:

alias ll "ls -la | awk '$5 > 2'"

It doesn't work.

If I try to escape the dollar sign, I get only a part of the command and ll is now ls -la | awk $5

What should I do in order to define this alias the way I want it to be?

asaf92
  • 292
  • 3
  • 14

2 Answers2

1

Just use a shell function if your alias is more complicated than a simple command:

lz () {
    ls -la | awk '$5 > 2'
}

... or find a command that is simpler and fits as an alias:

alias lz='find . -maxdepth 1 -size +2c -ls'

The bash manual contains the statement

For almost every purpose, aliases are superseded by shell functions.

Related: Why *not* parse `ls`?

Kusalananda
  • 333,661
0

escape, equal

$ alias ll="ls -la | awk '\$5 > 2'"
$ alias|grep ll                                       
ll='ls -la | awk '\''$5 > 2'\'
Ipor Sircer
  • 14,546
  • 1
  • 27
  • 39