Useful Terminal Commands
Every other person who uses or has used Linux or UNIX has written an article on useful commands. I want one too.
Launch the Terminal application by using Spotlight. If you’re using some flavor of Linux and you can’t find the terminal, you should seek another operating system. To save you the reading, I’ll list a few commands in order of their probable discovery and usefulness.
* I’ll give you just one warning: anything you do or change is permanent here. If you move or remove a directory which has files in it, they will not come back. The Terminal is powerful and with great power comes great danger.
Commands are entered at the prompt and typically accept delimiters/options and arguments. Any possible commands will be listed in blue.
man is probably the most useful command. It accepts the name of any command as it’s argument. Try manning man by typing man man. Read through the manual page. I recommend manning every command listed and experimenting with different options in order to better understand them.
pwd displays the current working directory, which is the directory which you are currently in.
ls lists the contents of the current directory. Consider ls -a -h -l ./, which lists the current directory, referred to by the dot and slash ./, with the format list -a for all, -h for human readable and -l for list. The same command can be accomplished in shorthand by typing ls -ahl. I find it important to know the origins of a command as well as the shorthand.
clear is a useful command for people who can’t stand clutter.
cd stands for change directory. You can cd into any directory in your current working directory or by typing cd and the name of the directory or folder. If you cd without any arguments, you will return to your home directory, which you can then use pwd to determine. If you wish to change to a specific directory, follow the command with the name of the directory exactly as it would appear from the root, which is /. Change to your root directory with cd /. You are now at the “beginning” of your file system. Navigate to /Volumes/Macintosh/Users/ and list the directory (ls). You’re in the directory one higher above your user directory. Navigate to your user directory from here. You will notice that /Volumes/Macintosh/Users/”User Name” is exactly the same directory as /Users/”User Name”. While in this directory, type pwd -P in order to show the “symbolic name” of the directory. The operating system utilizes a bit of trickery in order to make certain directories easier to access. If you would like to navigate backwards or upwards in a directory to the “parent directory,” use cd ..; that’s change directory dot dot. You can concatenate these commands as well. Consider cd ../..; that’s change directory dot dot slash dot dot.
mv stands for move. move can be used to move and rename files. If you wish to rename a file or directory, the first argument will be the old name and the second the new name. Consider: mv oldName newName. If the second argument is a directory, it will relocate the directory into the directory provided.
rm stands for remove. This deletes files permanently. You can remove directories with the option -r. You may also consider rmdir to remove directories.
mkdir stands for make directory.
touch can be used to create text files by giving the file name as the argument. Consider touch testfile.txt. touch has another primary purpose, which man should clear up.
vim is a powerful text editor. nano is a much simpler text editor. Man both of them and determine the differences for yourself.