Linux / Unix / OS X CLI Recipes

Change your command prompt

You can make your command-prompt actually useful, by setting the PS1 environment variable. For example:

export PS1="[\u:\[\e[35m\]\w\[\e[m\]]\\$ "

Which gives you a command prompt with your username (\u) and current directory (\w) within brackets:

[eron:~/src/abstrys-web/source]$

That, by the way, is my favorite prompt. You might want different information in your command prompt, and you can!

The bash manual provides a list of the switches you can use to set PS1.

Here's a nice Web application that lets you visually craft your command-prompt:

Open the default application for a given file type

The xdg-open command opens a file that you supply it, using your preferred application for opening that file type. For example, to open an HTML file in my web browser, I use:

xdg-open myweb/index.html

You can find out more by typing:

man xdg-open

List files only, or directories only

To get a list of files only, or directories only, use the -type parameter of the find command:

find . -type f

Chmod files based on type

Use chmod to change the permissions of files or directories only by operating on the output of find. For example:

chmod 644 `find . -type f`
chmod 755 `find . -type d`