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

Colorized grep in less
Get your colorized grep output in less(1). This involves two things: forcing grep to output colors even though it's not going to a terminal and telling less to handle those properly.

Replace spaces in filename
This command will replace spaces in filename with underscore, for all file in directory that contain spaces.

a function to find the fastest DNS server
http://public-dns.info gives a list of online dns servers. you need to change the country in url (br in this url) with your country code. this command need some time to ping all IP in list.

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"

Indent a one-liner.
Bash builtin type also indents the function.

Purge configuration files of removed packages on debian based systems
Purge all configuration files of removed packages

List the most recent dates in reverse-chronological order

Export a directory to all clients via NFSv4, read/write.
This exports a directory to the world in read/write mode. It is useful for quick, temporary NFS exports. Consider restricting the clients to a subnet or to specific hosts for security reasons (the client can be specified before the colon). On the client: mount -t nfs4 hostname:/ /mountpoint To terminate all of the exports (after unmounting on the client): exportfs -u -a Leave out the fsid=0 option if you don't want NFSv4. This works under recent versions of Linux.

Get File Names from touch commands
retrieve file names back from touch commands for them

Hide the name of a process listed in the `ps` output
$ exec -a $NAME $COMMAND $ARGS `your_cmd -erase_all_files` is the real process, but harmless-looking getty appears in the process table. Never actually had a need to do this, but interesting nonetheless... Tested in bash, dash. $ -a $NAME "pass NAME as the zeroth argument to COMMAND", i.e. customise the name of the process (as commonly seen with `ps`)


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: