Commands tagged expand (6)

  • Since bash 4.0, you can use ** to recursively expand to all files in the current directory. This behaviour is disabled by default, this command enables it (you'd best put it in your .profile). See the sample output for clarification. In my opinion this is much better than creating hacks with find and xargs when you want to pass files to an application. Show Sample Output


    11
    shopt -s globstar
    Alanceil · 2009-05-05 16:02:44 8
  • Tested with bash v4.1.5 on ubuntu 10.10 Limitations: as written above, only works for programs with no file extention (i.e 'proggy', but not 'proggy.sh') because \eb maps to readine function backward-word rather then shell-backward-word (which is unbinded by default on ubuntu), and correspondingly for \ef. if you're willing to have Ctrl-f and Ctrl-g taken up too , you can insert the following lines into ~/.inputrc, in which case invoking Ctrl-e will do the right thing both for "proggy" and "proggy.sh". -- cut here -- \C-f:shell-backward-word \C-g:shell-forward-word "\C-e":"\C-f`which \C-g`\e\C-e" -- cut here -- Show Sample Output


    0
    bind '"\C-e":"\eb `which \ef`\e\C-e"'
    jennings6k · 2011-01-26 16:11:52 9
  • Start an interactive program with perl code expansion. Everything between #[ ] is evaluated as perl code. #[ ] tags must not be nested (it wouldn't make sense anyway). Show Sample Output


    0
    plexpand() { mkfifo /tmp/plxpnd; $@ </tmp/plxpnd & perl -p -e '$|=1; s/#\[(.*)\]/eval($1)/ge' >/tmp/plxpnd; rm /tmp/plxpnd; }
    hellcode · 2016-05-10 04:49:35 9
  • With this command you can use shell variables inside sed scripts. This is useful if the script MUST remain in an external file, otherwise you can simply use an inline -e argument to sed.


    -1
    expanded_script=$(eval "echo \"$(cat ${sed_script_file})\"") && sed -e "${expanded_script}" your_input_file
    giuseppe_rota · 2009-05-07 14:21:14 5
  • Change the number to change the number of spaces. Leaving it out defaults to 8. Leaving out the filename defaults to stdin. And to do it in reverse, you can use the unexpand command.


    -1
    expand -t 2 <filename>
    camocrazed · 2010-07-13 23:04:57 3
  • Recursively find php files and replace tab characters with spaces. Options: "\*.php" -- replace this with the files you wish to find "expand" -- replace tabs with spaces (use "unexpand" to replace spaces with tabs) "-t4" -- tabs represent 4 spaces Note: The IFS="" in the middle is to prevent 'read' from eating leading/trailing whitespace in filenames.


    -4
    find . -type f -name \*.php | while IFS="" read i; do expand -t4 "$i" > "$i-"; mv "$i-" "$i"; done
    flatcap · 2011-04-08 12:53:14 50

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

get delicious bookmarks on your shell (text version :-))
a variation of avi4now's command - thanks by the way!

Rename files in batch

Project your desktop using xrandr
HDMI-1 is the interface in the example, which can be obtained just by typing xrandr and surfing through the output. There are a hell lot of configurations that can be done but I prefer auto because it works in most cases. $ Lifesaver

Change/Modify timestamp interactively

Change Random Wallpaper on Gnome 3
Change Random Wallpaper on Gnome 3

notify yourself when a long-running command which has ALREADY STARTED is finished
If you want to be notified when a long-running command is finished, but you have already started it: CTRL+Z $ fg; echo "finished" | sendmail me@example.com I use a script to post a tweet, which sends me a txt: $ fg; echo "finished" | tweet

Terminal - Show directories in the PATH, one per line with sed and bash3.X `here string'

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

make pgsql backup and gzip it

Make a statistic about the lines of code
use find to grep all .c files from the target directory, cat them into one stream, then piped to wc to count the lines


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: