Commands tagged alias (81)

  • This uses some tricks I found while reading the bash man page to enumerate and display all the current environment variables, including those not listed by the 'env' command which according to the bash docs are more for internal use by BASH. The main trick is the way bash will list all environment variable names when performing expansion on ${!A*}. Then the eval builtin makes it work in a loop. I created a function for this and use it instead of env. (by aliasing env). This is the function that given any parameters lists the variables that start with it. So 'aae B' would list all env variables starting wit B. And 'aae {A..Z} {a..z}' would list all variables starting with any letter of the alphabet. And 'aae TERM' would list all variables starting with TERM. aae(){ local __a __i __z;for __a in "$@";do __z=\${!${__a}*};for __i in `eval echo "${__z}"`;do echo -e "$__i: ${!__i}";done;done; } And my printenv replacement is: alias env='aae {A..Z} {a..z} "_"|sort|cat -v 2>&1 | sed "s/\\^\\[/\\\\033/g"' From: http://www.askapache.com/linux-unix/bash_profile-functions-advanced-shell.html Show Sample Output


    2
    for _a in {A..Z} {a..z};do _z=\${!${_a}*};for _i in `eval echo "${_z}"`;do echo -e "$_i: ${!_i}";done;done|cat -Tsv
    AskApache · 2010-10-27 07:16:54 5
  • 5 helpful aliases for using the which utility, specifically for the GNU which (2.16 tested) that is included in coreutils. Which is run first for a command. Same as type builtin minus verbosity alias which='{ command alias; command declare -f; } | command which --read-functions --read-alias' Which (a)lias alias whicha='command alias | command which --read-alias' Which (f)unction alias whichf='command declare -f | command which --read-functions' Which e(x)ecutable file in PATH alias whichx='command which' Which (all) alias, function, builtin, and files in PATH alias whichall='{ command alias; command declare -f; } | command which --read-functions --read-alias -a' # From my .bash_profile http://www.askapache.com/linux-unix/bash_profile-functions-advanced-shell.html Show Sample Output


    2
    alias whichall='{ command alias; command declare -f; } | command which --read-functions --read-alias -a'
    AskApache · 2010-11-18 03:32:04 7
  • Run the alias command, then issue ps aux | tail and resize your terminal window (putty/console/hyperterm/xterm/etc) then issue the same command and you'll understand. ${LINES:-`tput lines 2>/dev/null||echo -n 12`} Insructs the shell that if LINES is not set or null to use the output from `tput lines` ( ncurses based terminal access ) to get the number of lines in your terminal. But furthermore, in case that doesn't work either, it will default to using the default of 80. The default for TAIL is to output the last 10 lines, this alias changes the default to output the last x lines instead, where x is the number of lines currently displayed on your terminal - 7. The -7 is there so that the top line displayed is the command you ran that used TAIL, ie the prompt. Depending on whether your PS1 and/or PROMPT_COMMAND output more than 1 line (mine is 3) you will want to increase from -2. So with my prompt being the following, I need -7, or - 5 if I only want to display the commandline at the top. ( http://www.askapache.com/linux/bash-power-prompt.html ) 275MB/748MB [7995:7993 - 0:186] 06:26:49 Thu Apr 08 [askapache@n1-backbone5:/dev/pts/0 +1] ~ In most shells the LINES variable is created automatically at login and updated when the terminal is resized (28 linux, 23/20 others for SIGWINCH) to contain the number of vertical lines that can fit in your terminal window. Because the alias doesn't hard-code the current LINES but relys on the $LINES variable, this is a dynamic alias that will always work on a tty device. Show Sample Output


    2
    alias tail='tail -n $((${LINES:-`tput lines 2>/dev/null||echo -n 80`} - 7))'
    AskApache · 2012-03-22 02:44:11 7
  • Change n directories up, without parameters change one up Show Sample Output


    2
    up () { if [ "${1/[^0-9]/}" == "$1" ]; then p=./; for i in $(seq 1 $1); do p=${p}../; done; cd $p; else echo 'usage: up N'; fi }
    unixmonkey34472 · 2012-04-19 08:16:34 15
  • This command attempts to attach to existing irssi session, if one exists, otherwise creates one. I use "irc" because I use different irc clients depending on what system I am working on. Consistency is queen.


    2
    alias irc="screen -D -R -S chatclient irssi"
    expelledboy · 2012-08-12 13:24:43 5
  • This alias is super-handy for me because it quickly shows the details of each file in the current directory. The output is nice because it is sortable, allowing you to expand this basic example to do something amazing like showing you a list of the newest files, the largest files, files with bad perms, etc.. A recursive alias would be: alias LSR='find -mount -printf "%.5m %10M %#9u:%-9g %#5U:%-5G %TF_%TR %CF_%CR %AF_%AR %#15s [%Y] %p\n" 2>/dev/null' From: http://www.askapache.com/linux/bash_profile-functions-advanced-shell.html Show Sample Output


    2
    alias LS='find -mount -maxdepth 1 -printf "%.5m %10M %#9u:%-9g %#5U:%-5G %TF_%TR %CF_%CR %AF_%AR %#15s [%Y] %p\n" 2>/dev/null'
    AskApache · 2013-02-06 17:54:14 6
  • Most distributions alias cp to 'cp -i', which means when you attempt to copy into a directory that already contains the file, cp will prompt to overwrite. A great default to have, but when you mean to overwrite thousands of files, you don't want to sit there hitting [y] then [enter] thousands of times. Enter the backslash. It runs the command unaliased, so as in the example, cp will happily overwrite existing files much in the way mv works. Show Sample Output


    2
    \[command]
    tyzbit · 2015-01-15 18:31:50 8
  • KDE apps expect certain variables to be set, and unfortunately pkexec doesn’t set them by default. So, by setting this alias, it becomes possible to run, e.g. “pkexec kate” or “pkexec dolphin” and it’ll actually run.


    2
    alias pkexec=“pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY KDE_SESSION_VERSION=5 KDE_FULL_SESSION=true”
    realkstrawn93 · 2023-04-13 05:37:36 308
  • * Add comment with # in your command * Later you can search that command on that comment with CTRL+R In the title command, you could search it later by invoking the command search tool by first typing CTRL+R and then typing "revert" Show Sample Output


    1
    svn up -r PREV # revert
    unixmonkey10719 · 2010-07-07 23:09:00 16
  • make, find and a lot of other programs can take a lot of time. And can do not. Supppose you write a long, complicated command and wonder if it will be done in 3 seconds or 20 minutes. Just add "R" (without quotes) suffix to it and you can do other things: zsh will inform you when you can see the results. You can replace zenity with other X Window dialogs program.


    1
    alias -g R=' &; jobs | tail -1 | read A0 A1 A2 cmd; echo "running $cmd"; fg "$cmd"; zenity --info --text "$cmd done"; unset A0 A1 A2 cmd'
    pipeliner · 2010-12-13 17:44:36 2
  • This is useful if you use a shell with a lot of other users. You will be able to run "topu" to see your running processes instead of the complete 'top -u username'. Read more on alias: http://man.cx/alias


    1
    echo "alias topu='top -u USERNAME'" >> ~/.bash_aliases && source .bashrc
    TheLugal · 2011-07-07 08:24:06 3
  • Put the function in your .bashrc and use "map [alias]" to create the alias you want. Just be careful to not override an existing alias. Show Sample Output


    1
    map() { if [ "$1" != "" ]; then alias $1="cd `pwd`"; fi }
    javidjamae · 2011-07-11 15:46:19 7
  • This alias is meant to append n (here is n=10) most recently used cd commands to the bottom of history file. This way you can easily change to one of previous visited directories simply by hitting 1-10 times arrow up key. Hint: You can make more aliases implying the same rule for any set of frequently used long and complex commands like: mkisof, rdesktop, gpg...


    1
    alias cdd="history -a && grep '^ *[0-9]* *cd ' ~/.bash_history| tail -10 >>~/.bash_history && history -r ~/.bash_history"
    knoppix5 · 2011-07-13 09:44:16 4
  • The command creates an alias called 'path', so it's useful to add it to your .profile or .bash_profile. The path command then prints the full path of any file, directory, or list of files given. Soft links will be resolved to their true location. This is especially useful if you use scp often to copy files across systems. Now rather then using pwd to get a directory, and then doing a separate cut and paste to get a file's name, you can just type 'path file' and get the full path in one operation. Show Sample Output


    1
    alias path="/usr/bin/perl -e 'use Cwd; foreach my \$file (@ARGV) {print Cwd::abs_path(\$file) .\"\n\" if(-e \$file);}'"
    espider1 · 2012-01-18 01:40:05 10
  • Alias a single character 'b' to move to parent directory. Put it into your .bashrc or .profile file. Using "cd .." is one of the most repetitive sequence of characters you'll in the command line. Bring it down to two keys 'b' and 'enter'. It stands for "back" Also useful to have multiple: alias b='cd ../' alias bb='cd ../../' alias bbb='cd ../../../' alias bbbb='cd ../../../../' Show Sample Output


    1
    alias b='cd ../'
    deshawnbw · 2012-04-01 06:04:45 5
  • Written for Mac OSX. When you are working in a project and want to open it on Github.com, just type "gh" and your default browser will open with the repo you are in. Works for submodules, and repo's that you don't own. You'll need to copy / paste this command into a gh.sh file, then create an alias in your bash or zsh profile to the gh.sh script. Detailed instructions here if you still need help: http://gist.github.com/1917716


    1
    git remote -v | grep fetch | sed 's/\(.*github.com\)[:|/]\(.*\).git (fetch)/\2/' | awk {'print "https://github.com/" $1'} | xargs open
    brockangelo · 2012-04-15 20:48:46 20
  • Sometimes I would like to see hidden files, prefix with a period, but some files or folders I never want to see (and really wish I could just remove all together). Show Sample Output


    1
    alias ls='if [[ -f .hidden ]]; then while read l; do opts+=(--hide="$l"); done < .hidden; fi; ls --color=auto "${opts[@]}"'
    expelledboy · 2012-08-12 13:10:23 5

  • 1
    telnet v4address.com
    unixmonkey39007 · 2012-08-22 19:54:27 7

  • 1
    function map() { [ -n "$1" ] && alias $1="cd `pwd`" || alias | grep "'cd "; }
    b1067606 · 2013-01-11 13:32:26 4
  • Is used like this: mkalias rmcache "rm -rfv app/cache/*"


    1
    mkalias () { echo "alias $1=\"$2\"" >> ~\.bash_aliases }
    xr09 · 2013-01-14 13:56:35 5

  • 1
    tmux new-session -A
    peterko · 2015-06-09 09:28:54 8
  • On laptops featuring hybrid graphics and using the free X drivers, the DRI_PRIME variable indicates which GPU to run on. This alias allows to utilize the faster discrete GPU without installing proprietary drivers. Show Sample Output


    1
    alias game='DRI_PRIME=1'
    lordtoran · 2019-02-08 04:26:34 172
  • Output the current time in Swatch “Internet Time”, aka .beats. There are 1000 .beats in a day, and @0 is at 00:00 Central European Standard Time. This was briefly a thing in the late 1990s. More details: https://2020.swatch.com/en_ca/internet-time/ The alias is rather quote heavy to protect the subshell, so the bare command is: echo '@'$(TZ=GMT-1 date +'(%-S + %-M * 60 + %-H * 3600) / 86.4'|bc) Show Sample Output


    1
    alias beats='echo '\''@'\''$(TZ=GMT-1 date +'\''(%-S + %-M * 60 + %-H * 3600) / 86.4'\''|bc)'
    scruss · 2021-05-27 18:42:21 186
  • parses the output of ifconfig to show only the configured ip address (in this case from interface eth0). the regexp is quick'n'dirty im sure it can be done in a better way. --> this alias does not show your "internet ip" when you're in a nat-environment Show Sample Output


    0
    alias showip="ifconfig eth0 | grep 'inet addr:' | sed 's/.*addr\:\(.*\) Bcast\:.*/\1/'"
    dizzgo · 2009-03-25 07:50:12 16
  • Coming back to a project directory after sometime elsewhere? Need to know what the most recently modified files are? This little function "t" is one of my most frequent commands. I have a tcsh alias for it also: alias t 'ls -ltch \!* | head -20' Show Sample Output


    0
    function t { ls -ltch $* | head -20 ; }
    totoro · 2009-03-25 20:05:52 8
  •  < 1 2 3 4 > 

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands


Check These Out

Which processes are listening on a specific port (e.g. port 80)
swap out "80" for your port of interest. Can use port number or named ports e.g. "http"

Rename files in batch

Download an Entire website with wget

Set laptop display brightness
Run as root. Path may vary depending on laptop model and video card (this was tested on an Acer laptop with ATI HD3200 video). $ cat /proc/acpi/video/VGA/LCD/brightness to discover the possible values for your display.

Get AWS temporary credentials ready to export based on a MFA virtual appliance
You might want to secure your AWS operations requiring to use a MFA token. But then to use API or tools, you need to pass credentials generated with a MFA token. This commands asks you for the MFA code and retrieves these credentials using AWS Cli. To print the exports, you can use: `awk '{ print "export AWS_ACCESS_KEY_ID=\"" $1 "\"\n" "export AWS_SECRET_ACCESS_KEY=\"" $2 "\"\n" "export AWS_SESSION_TOKEN=\"" $3 "\"" }'` You must adapt the command line to include: * $MFA_IDis ARN of the virtual MFA or serial number of the physical one * TTL for the credentials

a short counter
Maybe you know shorter ?

Log colorizer for OSX (ccze alternative)
Download colorizer by @raszi @ http://github.com/raszi/colorize

add all files not under version control to repository
This should handle whitespaces well and will not get confused if your filenames have "?" in them

back ssh from firewalled hosts
host B (you) redirects a modem port (62220) to his local ssh. host A is a remote machine (the ones that issues the ssh cmd). once connected port 5497 is in listening mode on host B. host B just do a ssh 127.0.0.1 -p 5497 -l user and reaches the remote host'ssh. This can be used also for vnc and so on.

Happy Days
AFAIR this is the wording ;)


Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: