Commands by GeckoDH (7)

  • The command `cat file >> file` failes with the following error message: cat: file: input file is output file `tee` is a nice workaround without using any temporary files. Show Sample Output


    0
    cat file | tee >> file
    GeckoDH · 2009-07-30 07:34:03 7
  • Per default, linux/unix shells are configured with a width of 80 characters. If you like to edit a phrase or string on a line with more than 80 characters it might take long to go there (for example a line with 1000 characters and you like to edit the 98th word which is character 598-603). Maybe you might wish to use 78 characters, because if you forward the text via mail and the text will be quoted (2 extra characters at the beginning to the line "> "), you use 80 characters, otherwise 82, which are lame.


    3
    fold -w 78 -s file-to-wrap
    GeckoDH · 2009-05-19 19:33:10 5
  • Ater person A starts his screen-session with `screen`, person B can attach to the srceen of person A with `screen -x`. Good to know, if you need or give support from/to others.


    13
    screen -x
    GeckoDH · 2009-05-19 19:10:52 8
  • You only have to fill in your administrative account and password, and the router FQDN! I recommand to execute this command not over the internet, because there is no encryption (the username and password will be transmitted in plaintext!)


    3
    curl -d 'username=root&password=your-good-password' "http://router/cgi-bin/luci/admin/system/backup?backup=kthxbye" > `date +%Y%d%m`_config_backup.tgz
    GeckoDH · 2009-05-19 11:32:30 7
  • VARNAMES='ID FORENAME LASTNAME ADDRESS CITY PHONE MOBILE MAIL ...' cat customer.csv | while read LINE ; do COUNT=1 for VAR in $VARNAMES ; do eval "${VAR}=`echo $LINE | /usr/bin/awk {'print $'$COUNT''}`" let COUNT=COUNT+1 done done Maybe you have a CSV-File with addresses, where you have to process each contact (one per line, write each value to own variable). Of course you can define every variable, but this way is more simple and faster (to write). VARNAMES includes the variable names. Pay attention: the number of names in VARNAMES have to be the same than in the CSV-file the fields. If the CSV is not seperated with ";", you can set the seperator after the awk-binary with -F"_" for example.


    -1
    VARNAMES='ID FORENAME LASTNAME ADDRESS CITY PHONE MOBILE MAIL' ; cat customer.csv | while read LINE ; do COUNT=1 ; for VAR in $VARNAMES ; do eval "${VAR}=`echo $LINE | /usr/bin/awk {'print $'$COUNT''}`" ; let COUNT=COUNT+1 ; done ; done
    GeckoDH · 2009-05-19 11:23:00 4
  • PRIVATEKEY - Of course the full path to the private key \n HOST - The host where to get the backup \n SOURCE - The directory you wish to backup \n DESTINATION - The destination for the backup on your local machine


    1
    ssh -i $PRIVATEKEY $HOST -C 'cd $SOURCE; tar -cz --numeric-owner .' | tee $DESTINATION/backup.tgz | tar -tz
    GeckoDH · 2009-05-18 20:36:45 4
  • Important to know: a valid date will return 0, otherwise 1!


    2
    date -d2009-05-18 > /dev/null 2>&1 ; echo $?
    GeckoDH · 2009-05-18 20:30:05 4

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: