Suppose you have 11 marbles, 4 of which are red, the rest being blue. The marbles are indistinguishable, apart from colour. How many different ways are there to arrange the marbles in a line? And how many ways are there to arrange them so that no two red marbles are adjacent? There are simple mathematical solutions to these questions, but it's also possible to generate and count all possibilities directly on the command line, using little more than brace expansion, grep and wc! The answer to the question posed above is that there are 330 ways of arranging the marbles in a line, 70 of which have no two red marbles adjacent. See the sample output. To follow the call to marbles 11 4: after c=''; for i in $(seq $1); do c+='{b,r}'; done;, $c equals {b,r}{b,r}{b,r}{b,r}{b,r}{b,r}{b,r}{b,r}{b,r}{b,r}{b,r} After x=$(eval echo $c), and brace expansion, $x equals bbbbbbbbbbb bbbbbbbbbbr ... rrrrrrrrrrb rrrrrrrrrrr, which is all 2^11 = 2048 strings of 11 b's and r's. After p=''; for i in $(seq $2); do p+='b*r'; done;, $p equals b*rb*rb*rb*r Next, after y=$(grep -wo "${p}b*" Finally, grep -vc 'rr' Show Sample Output
Only a few characters of the previous command are necessary.
I don't like TABs in sources files because in case of mixture of TABs and spaces they looks in different editors. Even worse mixing TABs and spaces could be a problem when you use Python.
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.
Yeah, there are many ways to do that. Doing with sed by using a for loop is my favourite, because these are two basic things in all *nix environments. Sed by default does not allow to save the output in the same files so we'll use mv to do that in batch along with the sed. Show Sample Output
Use this command to view information regarding RSTP (802.1W). Show Sample Output
Count your source and header file's line numbers For example for java change the command like this find . -name '*.java' -exec cat {} \;|wc -l Show Sample Output
The popular fortune program telling by a cow (see sample). - fortune - cowsay Show Sample Output
Note that this will not work with files with spaces or characters that need to be escaped. Feel free to leave any comments to improve upon this command, and I'll add it in. Thanks! Show Sample Output
Personally I think line wrap in default df command is annoying for scripting & seeing. So I overwrite it. Maybe more work should be done if wrapped line is over 2... Show Sample Output
Matrix Screen HPUX
if Argument list too long
This is a safest variation for "sitepass function" that includes a SALT over a long loop for sha512sum hash Show Sample Output
I have often file like this 01 - file.file 02 - file.file 03 - file.file I rename all with this command for f in * ; do mv -- "$f" "${f/[0-9][0-9] \- /}" ; done then it looks like this file.file file.file file.file etc
./encode.sh [ h264 | xvid | theora | mpeg4 ] Show Sample Output
This is the quick and dirty alternative ;) The whole file will be emptied, this is equal to /dev/null > ~/.ssh/known_hosts
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.
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
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: