Commands by jonty (6)

  • If you spend all day editing in vi then switching your fingers to Emacs mode just for the command line can be difficult. Use set -o vi in your bash shell and enjoy the power of a real editor.


    1
    set -o vi; ls -l jnuk<ESC>bCjunk
    jonty · 2009-02-05 22:58:51 48
  • Einstein's razor: As simple as possible, but not simpler. On the destination machine netcat listens on any port (1234 in the example) and sends anything it receives into a file or pipe. On the source machine a separate netcat takes input from a file or pipe and sends it over the network to the listener. This is great between machines on a LAN where you don't care about authentication, encryption, or compression and I would recommend it for being simpler than anything else in this situation. Over the internet you should use something with better security.


    3
    (on destination machine) nc -l 1234 > whatever; (on source machine) nc destination 1234 < whatever;
    jonty · 2009-02-05 21:35:08 16
  • At some point you want to know what packets are flowing on your network. Use tcpdump for this. The man page is obtuse, to say the least, so here are some simple commands to get you started. -n means show IP numbers and don't try to translate them to names. -l means write a line as soon as it is ready. -i eth0 means trace the packets flowing through the first ethernet interface. src or dst w.x.y.z traces only packets going to or from IP address w.x.y.z. port 80 traces only packets for HTTP. proto udp traces only packets for UDP protocol. Once you are happy with each option combine them with 'and' 'or' 'not' to get the effects you want.


    2
    tcpdump -nli eth0; tcpdump -nli eth0 src or dst w.x.y.z; tcpdump -nli eth0 port 80; tcpdump -nli eth0 proto udp
    jonty · 2009-02-05 17:41:55 16
  • If you are already running screen then you often want to start a command in a fresh window. You use this alias by typing 's whatever' from your command line and 'whatever' starts running in a new window. Good with interactive commands like info, vim, and nethack.


    19
    alias s='screen -X screen'; s top; s vi; s man ls;
    jonty · 2009-02-05 13:47:14 38
  • Fool date by setting the timezone out by 24 hours and you get yesterday's date. Try TZ=XYZ-24 to get tomorrow's date. I live in TZ=GMT0BST so you might need to shift the number 24 by the hours in your timezone.


    1
    TZ=XYZ24 date
    jonty · 2009-02-05 13:27:14 25
  • I find this handy for linking all the bin files in a package to /usr/bin or all the man files to /usr/share/man. You can replace * with */* to operate on all the files in subdirectories.


    0
    cd /this/directory; for f in *; do ln -s `pwd`/$f /that/directory; done
    jonty · 2009-02-05 13:21:16 47

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

See The MAN page for the last command
This works in bash. The "!!:0" limits the argument to man to be only the first word of the last command. "!!:1" would be the second, etc.

Get fully qualified domain names (FQDNs) for IP address with failure and multiple detection

How to search for files and open all of them in tabbed vim editor.
Opening several files at once in Vim can be very easy in connection with find command.

SHA256 signature sum check of file
get the SHA256 sum signatur for a file

Search some text from all files inside a directory

Kills a process that is locking a file.
Useful when you're trying to unmount a volume and other sticky situations where a rogue process is annoying the hell out of you.

Convert seconds to [DD:][HH:]MM:SS
Converts any number of seconds into days, hours, minutes and seconds. sec2dhms() { declare -i SS="$1" D=$(( SS / 86400 )) H=$(( SS % 86400 / 3600 )) M=$(( SS % 3600 / 60 )) S=$(( SS % 60 )) [ "$D" -gt 0 ] && echo -n "${D}:" [ "$H" -gt 0 ] && printf "%02g:" "$H" printf "%02g:%02g\n" "$M" "$S" }

Get your external IP address
Request all information about my IP address in json format

Rename files in batch

run command on a group of nodes in parallel
The pee command is in the moreutils package.


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: