Tag Info

43

You can press Ctrl-Alt-e to perform the readline function shell-expand-line which will do alias, history and word expansions. Note that on some keyboards Meta is not Alt. You might need to press Esc then Ctrl-e The functions alias-expand-line and history-and-alias-expand-line are not bound by default, but you can bind them by adding lines similar to the ...

33

The Bash documentation states "For almost every purpose, shell functions are preferred over aliases." Here is a shell function that replaces ls and causes output to be piped to more if the argument consists of (only) -la. ls() { if [[ $@ == "-la" ]]; then command ls -la | more else command ls "$@" fi } As a one-liner: ls() { ...

30

It is rather easy to setup permanent aliases in the Windows command prompt using the @DOSKEY command and HKCU\Software\Microsoft\Command Processor Autorun option. Quick step-by-step guide: Create a new batch file, call it Alias.bat. Copy/paste the text below. TIP: I recommend creating a C:\Bin folder for all your command line tools. Open the register ...

19

Simply use the command alias which prints out all definitions in a format bash can read in again: $alias alias second='again' alias test='hello' So to recover, simply use$ alias > .bash_aliases

18

From the alias man page: The first word of each simple command, if unquoted, is checked to see if it has an alias. If so, that word is replaced by the text of the alias. The alias name and the replacement text may contain any valid shell input, including shell metacharacters, with the exception that the alias name may not contain ='. ...

16

Just to be clear, I'm basing this on the assumption that you really do want http://local.example.com to load the literal web page http://localhost/path/to/example.com. In other words, this will only work for this machine. If, on the other hand, you're trying to serve web pages to the outside world using your Mac OS X machine, then that's a different ...

15

Vim 'ignores' your aliases because your shell is not in a 'mood' to parse your .bash_profile/.bashrc (you did not specify, where your aliases are defined) because it is not started as a login/interactive shell (read here to find out more about what is read when and for what reason). So, you have several options: Put the code you use in your pdflatex alias ...

12

This is only possible if the two DHCP clients use different MAC addresses. Which means they cannot run both on the same physical network interface, which has a single MAC address. The solution is Linux's virtual MAC-VLAN network interfaces. MAC-VLAN interfaces are virtual network interfaces backed by a physical interface, but using with a different MAC ...

10

Just redirect the output. unalias rm mv cp >/dev/null 2>/dev/null

9

Aliases have no parameters, try function instead cd() { builtin cd "$1" ; ls ; } 9 Put a backslash before the first character.$ alias ls="echo foo" $ls foo$ \ls bin Desktop Documents ...

9

You can probably create an alias for that. Assuming you are using Bash, create a .bash_aliases file in your Home directory, if it already doesn't exist. Then, add a line with the following to the file: alias apt='sudo apt-get' Now close the shell and reopen it again. Now you can install any new package with the syntax apt install <package-name>. ...

8

Aliases are not inherited. That's why they are traditionally set in bashrc and not profile. Source your script.sh from your .bashrc or the system-wide one instead.

7

From man bash: For almost every purpose, aliases are superseded by shell functions. So make it a shell function. function cmakerel { if expr match "$PWD" '.*bld.*' >/dev/null ; then cmake -D.... else echo "Wrong directory!" fi } It's a regular expression you can adjust to your needs. 7 It'd be easier to make a function: cdd () { cd$1 ls } Of course, you can name the function whatever you like. Put it in your .bashrc or .profile or whatever it is on your system.

7

Console2 is only a wrapper around hidden Win32 console windows and does not provide extended line editing functionality. You can create aliases in Win32 consoles: doskey d=dir $* Unlike Unix sh, you have to explicitly specify$* to append given arguments (ex. d C:\). You can also use $T to separate commands. Also unlike Unix, aliases are implemented at ... 7 Although this question is over a year old and already answered, the following solution is simpler and avoids editing the registry: In Console2, go to Edit > Settings. Change the "Shell:" field to the following: C:\Windows\system32\cmd.exe /K "C:\Path\to\aliases.cmd" Now restart Console2 and you're done. To possibly save you some time, here's a simple ... 7 1) unalias dog 2) This will remove the lastmost directory from your path: PATH=${PATH%:*}. Repeat it as needed for however many bad entries you've got.

7

Your mac is probably using bash as shell, so you need to type alias la='ls -la' instead of alias la 'ls -la'

7

I think it needs to be: alias la='ls -la' (note there are no spaces around the equal sign.)

7

A slightly improved approach taken from Dennis' answer: function ls() { case $* in -la* ) shift 1; command ls -la "$@" | more ;; * ) command ls "$@" ;; esac } Or the one-liner: function ls() { case$* in -la* ) shift 1; command ls -la "$@" | more ;; * ) command ls "$@" ;; esac } This allows for further options/arguments to be appended after ...

7

This is what your PATH environment variable is for. Arrange your PATH environment variable so that both locations are on the path, AND in the order you want them to to be checked. So in your example, /usr/local/bin should be earlier in the PATH than /usr/local/bin/scripts. Most systems will probably have /usr/local/bin already in the system path, so ...

7

You should put it under: /etc/bash.bashrc to be available to all users.

7

You need the ~/.ssh/config file ForwardX11 or ForwardX11Trusted options. Specifically, if you want to add -X to every invocation of ssh, put something like this in your config file: ForwardX11 yes If you want to use if only for certain hosts, you need to set up a host specification for each host: Host <hostname> ForwardX11 yes Check out the ...

6

You can't. By running your script you execute a new shell. Aliases will not be seen by the parent process. The only way as pointed out is using source so that the current shell processes your script file (without starting a new process).

6

You can use command to circumvent the normal bash function lookup. command rm Non-destructive example: $alias which='which -s'$ function which { echo "which $@?" ; }$ which which which -s which? $command which which /usr/bin/which Alternatively, call it using env (executing the first program with the given name on the$PATH, or by specifying the ...

6

No, you can't. As the bash manual states: There is no mechanism for using arguments in the replacement text, as in csh'. If arguments are needed, a shell function should be used (*note Shell Functions::). Functions are the right thing for this, and can be as easy to write as an alias. In this case, it could be function g () { grep --color=always ...

6

For your case, network is 192.168.1.0, which means your ip address is in the network range, 192.168.1.0 to 192.168.1.255 You can always get your network base address easily by doing ip & mask, where & is logical AND.

6

I'm a little green on Linux, so I'm unsure exactly why it doesn't work. But you can use a function instead. In .profile/.bashrc create a new function: downloads() { grep date '+%d/%b/%Y' access.logs | egrep 2765330645ae47d292c9ceac725d744e.py |awk '{print $1,$4, $5,$7, $8,$9, \$10}' | sort |uniq -c -w15 |sort -n; } That works exactly as an alias.

6

Open AppleScript Editor. Paste in the following code: tell application "Finder" to shut down Click File » Save, save it to the Desktop, selecting File Format: Application. If you've saved it as the correct format, the icon should look like this:

Only top voted, non community-wiki answers of a minimum length are eligible