Category Archives: Shell

List listening ports and applicationli

netstat -ano | egrep 'Proto|LISTEN'

  • -a Show the state of all sockets, including passive sockets used by server processes
  • -n Show network addresses as numbers
  • -o Show process Id

netstat -ano | grep 8080

Show which application is using that port:

netstat -anb | grep -A 1 "8080"

  • -b Display executable listening on port
  • grep
  • -A option is to display the preceding line after greps returned result

SED command line utility – split string (& grep)

SED is a useful Unix command line tool I use for simple text replacement.

Here’s an example to see the directories included in your Windows PATH environment variable.  (I use MinGW for a Unix-like Shell in Windows)

echo $PATH

displays all directories on one line separated by semicolons.

With sed, we can list each directory on its own line.

echo $PATH | sed 's/:/\n/g'

First we echo $PATH, then pipe the output to the sed command to do our string replacement. The /g modifier will substitute ALL matches, not just the first.

Now each directory is listed on a separate line.

Additionally, if you are looking for a specific directory, for example you want to see which SVN installation is included in your PATH, you can use the grep command.

echo $PATH | sed -e 's/:/\n/g' | grep -i 'svn'

Once again we pipe the output from sed and use grep to show only directories that include SVN. The -i option is to ignore case (if your folder name includes the text “Svn”, “SVN”, etc.)

Adding unversioned files from Linux command line

Add all unversioned files from the command line using regular expressions.

svn status | grep '^?' | cut -c9- | sed -rn 's/^(.*)$/\"\1\"/p' | xargs svn add

svn status | grep '^?'
lists only un-versioned files.

cut -c9-
grabs only filename and path by cutting up to the 9th column removing the ? symbol and whitespace

sed -rn 's/^(.*)$/\"\1\"/p'
surrounds the filename with “double quotes” in case there are any spaces or your command prompt has an issue with the slashes being used in the path.

xargs svn add
executes svn add for each file.