Make Any Linux Directory an ISO File
November 13, 2008 | Leave a Comment
#mkisofs -V LABEL -r DIRECTORY | gzip > cdrom.iso.gz
Very useful grep example
August 16, 2008 | Leave a Comment
This is a super useful grep example that I’m posting so I can remember. To search for a string in all files in a directory, do the following:
find . -exec grep “your string here” ‘{}’ \; -print
Unix commands rock.
Bash Tips
November 27, 2007 | Leave a Comment
1. Lost bash history
If you have a terminal open and are typing commands, then open another one and use that for a while, the new terminal won’t remember any of the commands typed in the first one. In addition, closing the first terminal, and then the second will overwrite any of the commands typed in the first terminal. Doubly annoying!
This happens because the bash history is only saved when you close the terminal, not after each command. To fix it:
Edit your .bashrc (for beginners, any file starting with a . is hidden - they contain user preferences.)nano ~/.bashrc
No need for a sudo here Ubuntuers, this is your own file, not a system setting. I like nano, but it’s up to you, choose gedit, kate, mousepad, vi or emacs as you wish.
add the linesshopt -s histappend
PROMPT_COMMAND=’history -a’
And save. (control - O to write out. ^ means control in nano and other software, so the bottom of the editor does actually make sense to beginners! ^X to exit.)
This makes bash append history instead of overwriting it, and makes it so that each time the prompt is shown it writes out all the history.
2. Stupid spelling mistakes
Add
shopt -s cdspell
to your .bashrc again. This will make sure that spelling mistakes such as ect instead of etc are ignored.
3. Duplicate entries in bash history
I often type cd .. multiple times in a row, when I then press UP to go back to earlier commands I don’t want to be reminded of my earlier inelegant excursions around the file system.
Add
export HISTCONTROL="ignoredups"
to .bashrc again.
Even better, add
export HISTIGNORE="&:ls:[bf]g:exit"
This will ignore duplicates, as well as ls, bg, fg and exit as well, making for a cleaner bash history.
4. Multiple line commands split up in history
Add
shopt -s cmdhist
to .bashrc, this will change multiple line commands into single lines for easy editing.
5. A couple of neat extras suggested by commenters
Press control R in bash, then start typing and you can search through your past commands much easier than just pressing UP 300 times…
Alternatively, use
history | grep "foo"
to search through your history - “foo” is the thing you are searching for. (Thanks to Ally)
cd -
goes to the last directory you were in - useful if you want to go somewhere to change something, then need to quickly flip back again.
Pressing Esc . brings up the last object you referred to. For instance, if you had just typed cat /etc/apt/sources.list , then typing rm then pressing esc . would auto complete to rm /etc/apt/sources.list
Multiple subdomains in your home web server
September 8, 2007 | Leave a Comment
Subdomains are a great way to split up different kinds of content - like your default homepage, your blog, and your music collection. To set it up, you have to edit httpd.conf (the Apache configuration file.)
What you need to do is set up the different hosts (they’re called “Virtual Hosts”) and tell Apache which directories match. For example, if I wanted myname.example.com to map to a homepage and blog.myname.example.com to map to my blog and jukebox.myname.example.com to map to my music collection, I’d add the following to httpd.conf:
<VirtualHost *> DocumentRoot /Library/WebServer/example.com ServerName myname.example.com </VirtualHost> <VirtualHost *> DocumentRoot /Library/WebServer/blog.example.com ServerName blog.myname.example.com </VirtualHost> <VirtualHost *> DocumentRoot /Users/ET/Music/iTunes ServerName jukebox.myname.example.com </VirtualHost>
There my DocumentRoot is the file path to the folder that holds the sites’ files. (on a windows box it would be C:\ )
A word to the wise: back up your working httpd.conf file first before you start editing it.


6.For getting the last object referred to, another way to do (that’s slightly quicker/easier to type than ESC + .) is:
Alt + . (I find it a lot easier to hit alt + . as to get escape requires moving hands quite a bit from the home row)
By far the coolest bash trick, (that I only learnt about last year) is repeating multiple parts of the commant with curly brackets {}. Ie, if you are in home and need to quickly make a backup copy of /etc/apache2/httpd.conf (to pick a file at random), instead of typing
cp /etc/apache2/httpd.conf /etc/apache2/httpd.conf.bakyou can type
cp /etc/apache2/httpd.conf{,.bak}I use that trick a *lot*.
7.when trying to track down a file(s) that are hogging up disk space, I use:
for each in `ls -1`;do du -sh $each;done
528M cache
39M lib
8.0K local
32K lock
262M log
16K lost+found
4.0K mail
and then cd and follow the big directories to the big files