Commands by mph (1)

  • If you've ever wanted to change a text files contents without having to create an intermediate file. This is it. Ex is a part of vim. The command as given will delete ALL lines containing "delete this line" from the file. More Examples: print '%s/'this is a line'/'that is not the same line'/g\nwq' | ex file.txt will substitute the first string with the second string. print '3a\n'Inserted Line'\n.\n\nwq' | ex file.txt will insert the given line after line 3. CAVEAT, Some distro's like the print command, others like echo with this command. Also note there are NO error messages on failure, at least that I've ever seen. Ex can also be quite fussy as to how it takes strings, parameters, etc... I use at&t's ksh syntax may very with other shells.


    0
    print 'g/'delete this line'/delete\nwq' | ex file.txt
    mph · 2009-07-20 19:15:29 7

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

Selecting a random file/folder of a folder
Also looks in subfolders

Find removed files still in use via /proc
Oracle DBA remove some logfiles which are still open by the database and he is complaining the space has not been reclaimed? Use the above command to find out what PID needs to be stopped. Or alternatively recover the file via: $ cp /proc/pid/fd/filehandle /new/file.txt

ping with timestamp

Look for IPv4 address in files.
It finds a SNMP OID too :-(

Install pip with Proxy
Installs pip packages defining a proxy

Find removed files still in use via /proc
Oracle DBA remove some logfiles which are still open by the database and he is complaining the space has not been reclaimed? Use the above command to find out what PID needs to be stopped. Or alternatively recover the file via: $ cp /proc/pid/fd/filehandle /new/file.txt

Find usb device
I often use it to find recently added ou removed device, or using find in /dev, or anything similar. Just run the command, plug the device, and wait to see him and only him

Changing the terminal title to the last shell command
Found the same command for zsh in http://www.davidpashley.com/articles/xterm-titles-with-bash.html - changed it a bit so that the behaviour is the same

Find usb device in realtime
Using this command you can track a moment when usb device was attached.

Take screenshot through SSH
When connected to a box via ssh you can do a quick screenshot of that box using this command. After that you can rscp it over to your box and look at it.


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: