Before I get into that, let me introduce what UNIX is. If you have a Mac with OS X, more than likely you also have UNIX , an operating system developed in the 1960s. Or should I say a version of UNIX that OS X uses. The default UNIX shell in Mac OS X 10.3 or later is Bash. To clarify, the shell is a program that takes your commands from the keyboard and gives them to the operating system to perform.UNIX is ran in a program called Terminal (also included with all versions of OS X). It is located in the Utilities folder within the Applications folder. When launched, it provides a line user interface to control UNIX. If you haven’t used the Terminal, I recommend you should since it is a great skill to have if you want to increase your productivity.
Now, think of Aliases as shortcuts in UNIX to perform commands that otherwise would take to long to type each time (you could always click the up arrow key but that could be dangerous). Think of command + s (or ctrl + s for Windows users) for saving or command + v for paste. Again, these shortcuts are used to cut down on time wasted using the mouse and navigating to the command itself. All about productivity. There will be commonly used commands in UNIX that can become very specific, thus you should shorten those commands. Of course, you can’t override an existing command so use something that you can remember (or have a cheat sheet on your monitor).
There are a few ways to add aliases but I am assuming you will want to have your aliases every time you use UNIX. So, let’s create a permanent file that UNIX will reference your aliases from so that you may use them anytime. The file itself will always be .aliases (a hidden file hence the dot at the beginning). The file will be located in the home directory (you will see a ~ after the :). From here, enter vi (acronym for visual editor; think of it as a text editor for UNIX; another note, vi and UNIX are both case-sensitive so capital) and then .aliases. At the bottom of the page you will see the words new file at the bottom (if not, don’t worry – just means you have an existing .aliases file). vi has two command modes: command and insert. When you enter vi, you will be in command mode; meaning the keys on the keyboard do some sort of command. Insert mode is just that – using the keyboard to insert characters. To enter insert mode, press i and you will see at the bottom of the terminal window INSERT.
Now for my list.
alias lt='ls -lt’alias ltr='ls -ltr’ alias lat='ls -lat’ alias ltr4='ls -ltr|tail -4’ alias ltr8='ls -ltr|tail -8’ alias ltr22='ls -ltr|tail -22’ alias ltm='ls -lt|more’ alias ltrm='ls -ltr|more' alias latr='ls -latr' alias ltd='ls -lt|grep "^d"' alias ltdch='ls -lt|grep "^d"|grep ch' alias c='tput clear' alias findx='find . -print' alias findxm='find . -print|more'
Let me explain what the commands do.
alias lt=’ls -lt’ – list directory contents one line at a time
alias ltr=’ls -ltr’ – list directory contents in longlist format with timestamp (month day 24hr time) in reverse order. A time stamp comes in handy sometimes.
alias lat=’ls -lat’ – controls the amount and order of information being displayed.
alias ltr4=’ls -ltr|tail -4’ – output last 4 lines of a file or directory. When you have hundreds of lines (yeah, I’m complaining about hundreds) of code in a file, this saves time from searching with the mouse.
alias ltr8=’ls -ltr|tail -8’ – output last 8 lines
alias ltr22=’ls -ltr|tail -22’ – output last 22 lines
alias ltm=’ls -lt|more’ – Almost the same as alias lt but command “more” outputs the contents of a file one screen at a time. You’ll see a percentage at the bottom of the terminal window indicating how much you have scrolled through the file. I just like this command for ease. Don’t like to scroll.
alias ltrm=’ls -ltr|more’ – Like alias ltr but with the more command.
alias latr=’ls -latr’ – like alias ptr but the latest modified files are listed last (this is nice when you have your files you modified next to the command prompt).
alias ltd=’ls -lt|grep “^d”’ – This one needs a longer description. So when you long list a directory, the first thing you see are these weird identifiers that UNIX uses to determine whether something in a directory is a folder ((drwxr-xr-x) or a file (-rw-r–r—). So, for this alias, I list the directory contents in long list format and print the lines that begin with d (the folders). Grep is like a pattern finder and ^ (caret) means the beginning of a line.
alias findx=’find . -print’ – display the paths of all the files in the current directory and subdirectories.
alias findxm=’find . -print|more’ – like alias finds but display the paths one screen at a time.
And that’s it. I’ll have to get some screenshots up and visually show the commands in action. In the mean time, feel free to tell me what aliases you use in UNIX.