Wednesday, November 26, 2008

Terminal Commands (Introduction) Part 1

Introduction to *nix Commands

ls [folder] - lists the content of current folder unless another folder is passed as an argument

cd [folder] - changes directory to supplied folder. Other arguments can be "~" (home folder of user running command) and ".." (move up one directory), both these must be entered without the quotes.

man [command] - will display the manual page for any command supplied that offers manual pages. Will offer in-depth explanation of every flag and argument possible with the supplied command.

rm [flags] [directory or filename] - Commonly used to delete files or folders. To delete a non-empty folder the -r (recursive) flag must be supplied.

su [username] - switches user to supplied username. If no username is supplied it will default to root.

sudo [command] - runs the supplied command as super user (sudo = super user do). This will require a password for an admin account, however, it will cache (store) the password for a short time after the first use. This cached password will not be available anywhere but the original terminal shell in which it was first supplied.

locate [term] - is used to locate files that contain the term supplied. Requires "sudo updatedb" to be run to update the locate database.

grep [term] - program that will search supplied input for term supplied (is often used with piped [see below for explanation] input)

cp [flag] [file] [destination] - copies specified file to destination (or directory if the -R (recursive) flag is supplied)

ln -s [original location] [symbolic link] - creates a symbolic link (such as a shortcut in windows) to files, folders, or programs.

echo [content] - used to echo content (enclosed within quotation marks) to the screen, can be diverted to a file using the ">>" characters and then the path to the file, including the file name. (e.g. echo "test123">>Desktop/test123.txt)

cat [filename] - used to output the content of the file to the terminal (again, can be diverted to a file or to the grep command using aforementioned methods).

mkdir [directory name] - Creates a new directory in the current folder, unless a full file path is supplied for the new directory.

pwd - Is a command that prints the working directory (e.g. if you run it in /home/username/ it will return /home/username/)

Programs are usually installed to either /bin/ or /usr/bin, and almost all programs offer manpages, allowing you to use any program you need to just by knowing ls and man. These commands should exist in all *nix environments (mac, linux, unix), however, there may be slight alterations to how they must be entered.

1. A pipe is the character "|" and is used to divert output of a previous command into yet another command (e.g. 'ls|grep "home"')

No comments: