Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options answers only not deleted user 4667

An alias is essentially nothing more than a keyboard shortcut, an abbreviation, a means of avoiding typing a long command sequence. This can save a great deal of typing at the command-line and avoid having to remember complex combinations of commands and options.

0 votes

Calling alias with other alias + parameters

You might try: grp() { local grep_pattern=$1 shift # remaining args are the command: "$@" | grep "$grep_pattern" | less } And invoke it like: grp nvidia pac -Q
glenn jackman's user avatar
11 votes

-bash: unalias: ls: not found

You should only attempt to unalias if it is actually an alias: Change unalias ls to [[ $(type -t ls) == "alias" ]] && unalias ls …
glenn jackman's user avatar
2 votes

How to create a function based on commands not defined yet?

There's no problem declaring a function containing unknown commands. It's not until you try to execute it that trouble occurs. $ unknown() { foo; bar; baz; } $ unknown bash: foo: command not found ba …
glenn jackman's user avatar
8 votes
Accepted

Writing bash function as one-line alias

As @AndreasWiese comments, you can't do this with an alias. Aliases tack on arguments space-separated, so you can't join them (in a simple way) to the aliased command. …
glenn jackman's user avatar
2 votes

A tricky recursive bash alias? install at first use

You can use a shell function: top() { if ! type htop &>/dev/null; then sudo apt-get install htop fi htop }
glenn jackman's user avatar
3 votes

Using a bash alias or function with environment variables on multiple lines

If you need environment variables, you can use the env command: alias staging_server='env \ MY_ENV1="http://example.com" \ MY_ENV2="http://example2.com" \ MY_ENV3="http://example3.com" \ MY_ENV4 …
glenn jackman's user avatar
2 votes

Bash Alias with Multiple Quotes

$ See 9.3 History Expansion in the manual Using this in an alias: the linked manual section says History expansion is performed immediately after a complete line is read, before the shell breaks it … Alias expansion is performed by this step (see Aliases). Given the above statements, I don't know if it's even possible to have history expansion occur in an alias. …
glenn jackman's user avatar
7 votes

How to set an alias for a specific file or directory?

You could create a function and write your command "backwards" apachelog() { "$@" /var/log/apache2/error_log } apachelog tail -50
glenn jackman's user avatar
0 votes

Bash - get file count

In addition to Chris's good advice to use a function, Don't parse ls Use stat to get statistics about files: lsfc() { ls -lq -- "$@" printf 'File count: %d\n' "$(stat -c '%F' "$@" | grep -cF ' …
glenn jackman's user avatar
2 votes
Accepted

Executing linux aliases from sqlplus

the ~/.bash_profile is only processed for a login shell. Aliases are only available in an interactive bash session. So, referencing Invoking Bash: !bash -lic sample
glenn jackman's user avatar
0 votes

How to convert an alias for bash to an alias for csh? -> Or to tcl

In Tcl I'd write proc psgrep {pattern} { return [join [lsearch -regexp -inline -all [split [exec ps -A] \n] $pattern] \n] } set output [psgrep {a|b}]
glenn jackman's user avatar
0 votes
Accepted

'expr: syntax error: unexpected argument' - result from alias

Aliases are almost always better written as functions. The tricky part here is you chain every command together with && to abort early -- I use set -e in a subshell here for the same effect. runhole( …
2 votes
Accepted

Cannot use awk in alias command chain

As requested: This is one reason why functions are better than aliases: you can avoid quoting hell. ttn() { tail -10000 /var/log/nginx/access.log | awk '{print $1}' | sort | uniq -c | sort -nr | head …
glenn jackman's user avatar
3 votes
Accepted

Bash: Alias not recognized in shell interpolation

The "bab" that gets executed after $(echo bab) will not be handled as an alias. Try using a function instead: unalias bab bab() { python "$@"; } $(echo bab) # launches a python shell …
glenn jackman's user avatar
2 votes
Accepted

Whitespaces in alias bashrc

dockerid() { docker ps -a \ | grep -o -E '^[a-z0-9]{12}' \ | awk '{printf "%s ",$0} END {print ""}' } Although the alias quoting hell goes away by replacing awk with paste alias dockerid=" …
glenn jackman's user avatar

15 30 50 per page