Commands tagged parameter (4)

  • If you have used bash for any scripting, you've used the date command alot. It's perfect for using as a way to create filename's dynamically within aliases,functions, and commands like below.. This is actually an update to my first alias, since a few commenters (below) had good observations on what was wrong with my first command. # creating a date-based ssh-key for ssh-keygen -f ~/.ssh/`date +git-$USER@$HOSTNAME-%m-%d-%g` -C '' # /home/gpl/.ssh/ # create a tar+gzip backup of the current directory tar -czf $(date +$HOME/.backups/%m-%d-%g-%R-`sed -u 's/\//#/g' <<< $PWD`.tgz) . # tar -czf /home/gpl/.backups/04-22-10-01:13-#home#gpl#.rr#src.tgz . I personally find myself having to reference date --help quite a bit as a result. So this nice alias saves me a lot of time. This is one bdash mofo. Works in sh and bash (posix), but will likely need to be changed for other shells due to the parameter substitution going on.. Just extend the sed command, I prefer sed to pretty much everything anyways.. but it's always preferable to put in the extra effort to go for as much builtin use as you can. Otherwise it's not a top one-liner, it's a lazyboy recliner. Here's the old version: alias dateh='date --help|sed "/^ *%%/,/^ *%Z/!d;s/ \+/ /g"|while read l;do date "+ %${l/% */}_${l/% */}_${l#* }";done|column -s_ -t' This trick from my [ bash_profile ] Show Sample Output

    alias dateh='date --help|sed -n "/^ *%%/,/^ *%Z/p"|while read l;do F=${l/% */}; date +%$F:"|'"'"'${F//%n/ }'"'"'|${l#* }";done|sed "s/\ *|\ */|/g" |column -s "|" -t'
    AskApache · 2010-04-21 01:22:18 5
  • Reuse the last parameter of the previous command line Show Sample Output

    Neo23x0 · 2010-11-27 14:24:14 0
  • Can be used for command line parameters too. If you have a more complicated way of entering values (validation, GUI, ...), then write a function i.e. EnterValue() that echoes the value and then you can write: param=${param:-$(EnterValue)}

    param=${param:-$(read -p "Enter parameter: "; echo "$REPLY")}
    frans · 2011-09-08 20:48:31 0
  • Then exit from the shell. exit some time need to exit twice exit exit Now the OS will boot with the new parameters.

    echo "root=/dev/sda7" > /proc/param.conf
    totti · 2011-09-27 18:06:53 0

What's this? 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

Look at your data as a greymap image.
Keep width to a power of 2 to see patterns emerge. 512 is good. So is 4096 for huge maps. PNM headers are super basic.

List only executables installed by a debian package
Safe for whitespaces in names.

Tail -f at your own pace
The -s option allows you to specify the update interval

Change every instance of OLD to NEW in file FILE
Very quick way to change a word in a file. I use it all the time to change variable names in my PHP scripts (sed -i 's/$oldvar/$newvar/g' index.php)

Benchmark SQL Query
Benchmark a SQL query against MySQL Server. The example runs the query 10 times, and you get the average runtime in the output. To ensure that the query does not get cached, use `RESET QUERY CACHE;` on top in the query file.

Get IPv4 of eth0 for use with scripts
I've been using it in a script to build from scratch proxy servers.

Limit the cpu usage of a process
Similar to `cpulimit`, although `prlimit` can be found shipped with recent util-linux. Example: limit CPU consumption to 10% for a math problem which ordinarily takes up 100% CPU: Before: $ bc -l

Get your commandlinefu points (upvotes - downvotes)
This will calculate the your commandlinefu votes (upvotes - downvotes). Hopefully this will boost my commandlinefu points.

Convert CSV to JSON
Replace 'csv_file.csv' with your filename.

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

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.


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: