Commands by intuited (4)

  • Doesn't display the matching line. If you want that behaviour, you need to add "print && " before the 'exit'.


    0
    <command> | perl -pe '/<regex/ && exit;'
    intuited · 2009-12-22 15:05:49 3
  • "Copying" things to the X clipboard doesn't normally create a copy. Rather the data to be 'copied' is referenced. This means that if the application that you 'copied' stuff from is closed, that data is lost. If the application that you 'copied' from is suspended with CTRL-Z, there could be some issues if you try to paste it into something. This command will create a copy of referenced data and have xclip be the provider of it, so you can then go ahead and close the app that contains the original information. Caveat: I'm not sure if this is binary-safe (though i would expect it to be), and don't know what would happen if you used it to clip a 20 meg gimp image. This technique becomes more convenient if you set it up as an action in a clipboard manager (eg klipper, parcellite). Some of these applets can take automatic action based on a variety of parameters, so you could probably just get it to always own the clipped data whenever data is clipped.


    4
    xclip -o -selection clipboard | xclip -selection clipboard
    intuited · 2009-12-21 19:02:43 4
  • Manpages, command summaries, and pretty much everything else usually have the information you're most likely to want at the beginning. Seeing just the last 40 or so lines of options from a command that has 100 is not super useful, and having to scroll up each time you want to glance at something is spastic. Run this and then do something like p do vi --help and you'll get the first screen(-mostly-)full of vi's usage info and options list Then use p d to page down, and p u to page up. To see the current page again: p r Also useful for situations like p do aptitude search ~dsmorgasbord p next #p sudo aptitude -r install libwickedawesome-perl-snoochieboochies p next p sudo aptitude -r install libwickedawesome-perl-snoochieboochies snazztasticorama-dev-v0.&#8734; where you're using readline up-arrow, HOME, END, etc., to quickly recall commented commands. For the unaware, that option to aptitude search will bring up all of the packages whose descriptions contain the string "smorgasbord". Depending on your distro, there could potentially be hundreds of them.


    0
    p() { l=$LINES; case $1 in do) shift; IFS=$'\n' _pg=( $("$@") ) && _pgn=0 && p r;; r) echo "${_pg[*]:_pgn:$((l-4))}";; d) (( _pgn+=l-4 )); (( _pgn=_pgn>=${#_pg[@]}?${#_pg[@]}-l+4:_pgn )); p r;; u) (( _pgn=_pgn<=l-4?0:_pgn-$l-4 )); p r;; esac; }
    intuited · 2009-12-18 23:35:53 10
  • Assuming that $script contains the filename of a script you'd like to post as part of a comment on this site, this will prefix each line with '$' and pipe it into the X selection. From there just put the cursor in the right place in the comments box and middle-click. Should work pretty much anywhere with xclip installed. On debian-ish systems this is installed as part of the package "xclip".


    2
    sed 's/^/$ /' "$script" | xclip
    intuited · 2009-09-13 11:21:54 31

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 block level layout

awk date convert
Convert readable date/time with `date` command

Alias TAIL for automatic smart output
Run the alias command, then issue $ps aux | tail and resize your terminal window (putty/console/hyperterm/xterm/etc) then issue the same command and you'll understand. $ ${LINES:-`tput lines 2>/dev/null||echo -n 12`} Insructs the shell that if LINES is not set or null to use the output from `tput lines` ( ncurses based terminal access ) to get the number of lines in your terminal. But furthermore, in case that doesn't work either, it will default to using the default of 80. The default for TAIL is to output the last 10 lines, this alias changes the default to output the last x lines instead, where x is the number of lines currently displayed on your terminal - 7. The -7 is there so that the top line displayed is the command you ran that used TAIL, ie the prompt. Depending on whether your PS1 and/or PROMPT_COMMAND output more than 1 line (mine is 3) you will want to increase from -2. So with my prompt being the following, I need -7, or - 5 if I only want to display the commandline at the top. ( http://www.askapache.com/linux/bash-power-prompt.html ) 275MB/748MB [7995:7993 - 0:186] 06:26:49 Thu Apr 08 [askapache@n1-backbone5:/dev/pts/0 +1] ~ $ In most shells the LINES variable is created automatically at login and updated when the terminal is resized (28 linux, 23/20 others for SIGWINCH) to contain the number of vertical lines that can fit in your terminal window. Because the alias doesn't hard-code the current LINES but relys on the $LINES variable, this is a dynamic alias that will always work on a tty device.

generate a unique and secure password for every website that you login to
usage: sitepass MaStErPaSsWoRd example.com description: An admittedly excessive amount of hashing, but this will give you a pretty secure password, It also eliminates repeated characters and deletes itself from your command history. tr '!-~' 'P-~!-O' # this bit is rot47, kinda like rot13 but more nerdy rev # this avoids the first few bytes of gzip payload, and the magic bytes.

Route outbound SMTP connections through a addtional IP address rather than your primary

View all images
So you are in directory with loads of pictures laying around and you need to quickly scan through them all

Renaming a file without overwiting an existing file name
Sometimes in a hurry you may move or copy a file using an already existent file name. If you aliased the cp and mv command with the -i option you are prompted for a confirmation before overwriting but if your aliases aren't there you will loose the target file! The -b option will force the mv command to check if the destination file already exists and if it is already there a backup copy with an ending ~ is created.

Extract the MBR ID of a device
Useful when you want to know the mbrid of a device - for the purpose of making it bootable. Certain hybridiso distros, for eg the OpenSUSE live ISO uses the mbrid to find the live media. Use this command to find out the mbrid of your USB drive and then edit the /grub/mbrid file to match it.

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

Find files that were modified by a given command
Traces the system calls of a program. See http://linuxhelp.blogspot.com/2006/05/strace-very-powerful-troubleshooting.html for more information.


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: