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

List .log files open by a pid
Uses lsof to display the full path of ".log" files opened by a specified PID.

Lists the supported memory types and how much your board can support.

generate iso

Reset terminal that has been buggered by binary input or similar

Find default gateway

mail with attachment
An easy one but nice to keep in mind.

list block devices
Shows all block devices in a tree with descruptions of what they are.

Getting the last argument from the previous command

Search gpg keys from commandline

Select and Edit a File in the Current Directory
This command displays a simple menu of file names in the current directory. After the user made a choice, the command invokes the default editor to edit that file. * Without the break statement, the select command will loop forever * Setting the PS3 prompt is optional * If the user types an invalid choice (such as the letter q), then the variable $f will become an empty string. * For more information, look up the bash's select command


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: