There are many things that all programmers should know, but I am particularly interested in the Unix/Linux commands that we should all know. For accomplishing tasks that we may come up against at some point such as refactoring, reporting, network updates etc.
The reason I am curious is because having previously worked as a software tester at a software company while I am studying my degree, I noticed that all of developers (who were developing Windows software) had 2 computers.
To their left was their Windows XP development machine, and to the right was a Linux box. I think it was Ubuntu. Anyway they told me that they used it because it provided powerful unix operations that Windows couldn't do in their development process.
This makes me curious to know, as a software engineer what do you believe are some of the most powerful scripts/commands/uses that you can perform on a Unix/Linux operating system that every programmer should know for solving real world tasks that may not necessarily relate to writing code?
We all know what sed, awk and grep do. I am interested in some actual Unix/Linux scripting pieces that have solved a difficult problem for you, so that other programmers may benefit. Please provide your story and source.
I am sure there are numerous examples like this that people keep in their 'Scripts' folder.
Update: People seem to be misinterpreting the question. I am not asking for the names of individual unix commands, rather UNIX code snippets that have solved a problem for you.
Best answers from the Community
Traverse a directory tree and print out paths to any files that match a regular expression:
find . -exec grep -l -e 'myregex' {} \; >> outfile.txt
Invoke the default editor(Nano/ViM)
(works on most Unix systems including Mac OS X) Default editor is whatever your "EDITOR" environment variable is set to. ie: export EDITOR=/usr/bin/pico which is located at ~/.profile under Mac OS X.
Ctrl+x Ctrl+e
List all running network connections (including which app they belong to)
lsof -i -nP
Clear the Terminal's search history (Another of my favourites)
history -c
The fact you can use -name and -iname multiple times in a find command was an eye opener to me.
[findplaysong.sh]
The tr command is the most under-appreciated command in Unix:
Best answers from the Community
Traverse a directory tree and print out paths to any files that match a regular expression:
Invoke the default editor(Nano/ViM)
List all running network connections (including which app they belong to)
Clear the Terminal's search history (Another of my favourites)
Repeat your previous command in bash using
!!
. I oftentimes runchown otheruser: -R /home/otheruser
and forget to use sudo. If you forget sudo, using !! is a little easier than arrow-up and then home.I'm also not a fan of automatically resolved hostnames and names for ports, so I keep an alias for iptables mapped to
iptables -nL --line-numbers
. I'm not even sure why the line numbers are hidden by default.Finally, if you want to check if a process is listening on a port as it should, bound to the right address you can run
Then you can grep the process name or port number (-n gives you numeric).
I also love to have the aid of colors in the terminal. I like to add this to my bashrc to remind me whether I'm root without even having to read it. This actually helped me a lot, I never forget sudo anymore.
Those are all very simple commands, but I use them a lot. Most of them even deserved an alias on my machines.
You can do anything with this...
gcc
When things work on one server but are broken on another the following lets you compare all the related libraries:
Compare this list with the one between the machines and you can isolate differences quickly.