Improved ‘ls’ functionality in your terminal

A couple of weeks ago I wrote a post about using your bash_profile to create custom git commands to improve your workflow. Here are some more aliases I’ve found useful.

These are written for a Mac environment, but the same functionality should be possible in Windows and Linux.

Improved ls

ls is the command that lists all files at the current location. Sometimes it can be useful to display extra information, or sort the list. For example, if you want to display the size of each item, you can use

du stands for “disk usage”; it’s already an improved ls, in that it’s ls with extra information, but it needs to be massaged a bit to be useful. In its base state, it traverses every directory and reports each item in the directory; -s * groups directories. -h converts the sizes to bytes (without that, it is in units of 512 bytes).

We can also sort them by size:

And we can add a total to the end with -c:

Certainly could be useful. So if we want to add this to our bash_profile, we could write it as:

cd; ls

cd is the command for changing directories; ls is, as we said before, the command for listing. Often you want to do both.

Recall from the last post that when we want to take arguments from the user (in this case the directory we’re cding into), we use function syntax rather than alias.

Why don’t we combine this with our improved ls?

Let me know your favorite bash aliases below.

Weakly Pseudonymous Software Engineer