Basic Unix Commands
pwd
This command name stands for "print working directory".
It displays on the terminal the absolute path name of the current (working) directory.
It is useful to locate where you are currently in the Unix tree.
cd
This command name stands for "change directory".
It changes your current working directory to the specified location.
Your home directory is referred to as "~" (tilde).
The current directory is referred to with a single dot ( ".").
The directory located one level up the current directory (also known as "parent directory") is referred to with two dots ("..").
The last visited directory is referred to with an hyphen ("-").
ls
This command stands for "list".
It displays the content of a directory.
By default, the content is listed in lexicographic order.
Command switches allows to list the directory's content with more or less detail and sorted according to different criteria.
The switch "a" lists all files and directories, even those starting with "." that are normally hidden.
The switch "l" lists the content in "long" format, including the total size (in blocks), mode (permission), the number of links, the owner, the size, the date of last modification, and the file or subdirectory name. Note that the first hyphen is replaced with a “d” if the item is a directory.
The switch "t" sorts the content of the directory by time modified (most recently modified first).
The switch "S" sorts the content of the directory by size (smaller first).
The switch "r" reverses the order of the sort.
The switch "R" recursively lists subdirectories encountered.
The switch "u" specifies the use of time of last access of the file, instead of last modification, for sorting the content.
The switch "U" specifies the use of time of file creation, instead of last modification, for sorting the content.
The switch "F" displays a slash ("/") immediately after a directory, an asterisk ("*") after an executable, an at sign ("@") after a symbolic link.
To view the commands available on luria, execute the following (note the space-separated list of directories to list):
mkdir
This command name stands for "make a directory".
It creates a new folder (or directory). If no path is specified, the new directory is created in the current directory.
The switch "-v" specifies a verbose mode: a message with the folder(s) created is printed on the screen.
cp
This command name stands for "copy".
It makes copies of files and directories to the specified location.
The switch "v" enables the verbose mode: messages describing the files copied are displayed on the screen.
The switch "i" enables the interactive mode: confirmation is requested before overwriting files.
Wildcards symbols such as "*" or "?" are commonly used to copy multiple files with a single command.
The symbol "*" stands for any number of alphanumeric characters.
The symbol "?" stands for a single alphanumeric character.
The following examples assume you have a directory named "unix_class" in your home directory:
mv
This command name stands for "move".
It moves (renames) files and directories.
Several switches are available to specify the behavior of this command, including "-i" (interactive mode) and "-v" (verbose).
rmdir
This command stands for "remove directory".
It deletes the specified directory.
The switch "-v" specifies a verbose mode: a message with the folder(s) deleted is printed on the screen.
Note that in general you cannot delete a directory that is not empty. The content of such directory has to be deleted before the directory itself can be deleted.
rm
This command name stands for "remove".
It deletes files and directories.
Several switches are available to specify the behavior of this command, including "-i" (interactive mode) and "-v" (verbose).
The "rm" command can be used in conjunction with wildcard symbols to delete multiple files at once. Extreme caution should be used, as action are not often reveresible. It is good practice either to use the interactive/verbose mode or use the command "ls" with the intended pattern, before invoking the command "rm".
The switch "-r" deletes the content of a directory recursively,
i.e. deletes the directory's files and subdirectories, including their content.
cat
This command name stands for "concatenate".
It concatenates the content of file(s) and prints it out.
The switch "-n" specifies to number each line, starting from 1.
The "cat" command is often used in conjuction with the pipe ("|") to view the content of long files.
The "cat" command can be used to copy and append the content of files using output redirection (">").
When used without argument, the "cat" command takes STDIN as default argument. You can use this behavior to type in brief information, rather than invoking a standard text editor.
less
This command is a "pager" that allows the user to view (but not modify) the contents of a text file one screen at a time.
The space-bar is used to advance to the next page.
The key "q" is used to "quit" the pager.
The switch "-n" allows to view the content of a file starting at the specified line.
head
This command displays the top part of a file.
By default, the first 10 lines of a file are displayed.
The switch "-n" specifies the number of lines to display.
The switch "-b" specifies the number of bytes to display.
tail
This command displays the bottom part of a file.
By default, the last 10 lines of a file are displayed.
The switch "-n" specifies the number of lines to display.
The switch "-b" specifies the number of bytes to display.
top
This command displays Linux tasks
The top program provides a dynamic real-time view of a running system
du
This command stands for Disk Usage
It estimates file space usage
df
This command stands for Disk Free
It reports file system disk space usage
Last updated