Study Notes by Rahul Prabhudesai
This page is still in progress and new content will be added over time. Estimated completion is end of 2019, however, new content and/or edits will continue past completion.
1| Basic UNIX Commands
UNIX, like many operating systems contain a Command-Line Interface (CLI) which perform actions that are given through commands. Unlike some operating systems such as Windows, UNIX is case sensitive, and requires all commands to follow correct letter casing in order to execute.
Syntax for a command
$ command -option(s) argument(s) $ ls -l /tmp
List of basic UNIX commands
|Command & Option||Description|
|Manual (Help) for UNIX commands|
Display only the description from the manual page
|Displays information about the operating system.|
Shows the name of the hardware platform.
Prints the hostname of the current system.
Shows the name of the operating system.
Shows the current operating system release level.
|$ uptime||Shows how long the system has been up for since last boot|
|$ top||Displays tasks and system statuses in UNIX|
$ who am i
|Lists logged in user’s username, terminal no. and login time|
Prints logged in users and what they are doing
Shows usernames of people currently at the terminal
Displays username associated with current (effective) user
Prints information about system users
|Displays a calendar for the current month and year.|
Shows today’s date and current time
|$ clear||Clears the terminal window.|
|List files and directories|
List all files and directories including hidden
Lists in long format
|$ pwd||Print working directory shows current directory|
|$ passwd||Allows the password to be changed|
|Simply prints whatever it is given |
Prints characters in ASCII style big letters
|$ bc||A simple calculator|
|Shows an ordered list of all entered commands|
Clears the current session history
|$ mkdir||Makes a new directory with provided name|
|$ touch||Creates and opens a new empty ASCII text file|
|Removes (deletes) selected file|
Recursively deletes a directory and contained files
|Moves or renames files and directories|
Display prompt if a file in destination may be replaced
|Makes a copy of files or entire directories to the destination|
Recursively copies a directory and contained files
Display prompt if a file in destination may be overwritten
|$ cd||Change directory|
|Makes a shortcut of any command|
Prints the current values of all aliases
Removes the value for a specified alias
Removes all defines aliases
|$ file||View the file type|
|$ cat||View contents and write to a file|
|Modify access permissions on a file using symbolic or octal modes|
Change ownership and optionally the group ownership of a file
Recursively change ownership of a directory and contents
Change the group ownership of a file
|$ umask||Set default permissions for new files and directories using octal|
|Start the vi ASCII text editor|
Open a file in read only mode
Open in read only mode; require save to new location
Open or create file with showmode enabled
Commands with arguments
$ command argument(s) $ cal 7 2017
Entering multiple commands on a single line
The shell recognises a “;” semicolon as a command separator and executes commands from left to right once “Return” is pressed.
$ command -option(s) argument(s) ; command -option(s) argument(s) $ uname -rs ; cal
Using online documentation
The “man” command displays information about the specified command and options. Press “q” to quit the manual page.
$ man command $ man mkdir $ whatis command $ whatis mkdir
Using the echo and banner commands
The “echo” command simply prints whatever it is given. The “banner” command prints big characters in an ASCII style.
$ echo "character(s)" $ echo "Hello World!" $ banner "character(s)" $ banner ":D"
Using the date command with formatting
The date command shows the current date and time. This can be formatted using the following syntax:
$ date +format $ date +%d-%M-%Y
|Abbreviated weekday name|
Full weekday name
|24 hour time|
12 hour time
|Day of year|
Day of month
Using the change directory command
Users can change directory by using the “cd” command.
$ cd /destination $ cd /home/documents
|$ cd||Moves to the home directory|
|$ cd /||Moves current directory to the root directory|
|$ cd .||Moves to the current directory|
|$ cd ..||Moves into the parent directory|
Using the alias and unalias commands
The “alias” command allows users to make a shortcut for a command. The “unalias” command removes the value of an alias.
$ alias name="command" $ alias c="clear" $ alias ll="ls -l" $ unalias name $ unalias c
2| UNIX File System
The UNIX file system is a methodology for logically organising and storing large quantities of data. In UNIX, the smallest unit of storage is a file. The base of UNIX is comprised of files for even device drivers such as keyboard, mouse, display, etc. The smallest unit of storage is a file.
All files in the UNIX file system are organised into directories which are organised in a tree-like structure.
Files that contain data, text, or program instructions which are located within a directory file.
Symbol: “-” (files)
Used to represent real physical device with Input/Output (I/O) operations and also appear in a file system like any other file or directory.
Symbol: “c” (special files), “b” (block special files)
Files are stored in directories and are used to organise groups of files. This may contain various other types of files or directories.
Symbol: “d” (directories)
Symbolic links are used to reference another file. It is a text file comprising of the path to the file being referenced.
Symbol: “l” (links)
The top level of the UNIX file structure is known as the “root directory”, which is represented by the “/” (forward-slash) symbol. Subdirectories under root include bin, dev, etc, lib, mnt, tmp and usr, most of which contain system files.
Encoded files for storage and processing purposes.
Contains binary executables typically used for system administration or maintenance purposes.
Contains configuration files for all programs as well as startup and shutdown scripts.
Contains files for terminal devices and any USB devices attached to the system
Contains information about system processes
Contains files whose contents are expected to grow, ie. logs, database files, etc.
Contains temporary files created by the system and user which is deleted upon system reboot.
Contains users’ programs
Home for all users to store their data, ie. /home/carlos
Contains kernel components common to all platforms within a particular instruction set which are needed for booting the system.
Contains library files that support files in /bin and /sbin directories
|/opt||Optional Add-On Applications|
Contains add-on application from individual vendors
Directory used for mounting file systems. Commonly used to access external devices such as USBs and Hard Drives.
|/platform||Platform Definiton Files|
Contains platform definition files
Disk volumes are mounted under this directory
Absolute and Relative Paths
Absolute path names start from the root directory, whereas relative path names begin from the current directory and are therefore relative to that directory.
# Absolute Path Name $ /mnt/disk1/data/2019_pictures # Relative Path Name (Given that current directory is "/mnt/disk1/data/") $ 2019_pictures
Certain special files in UNIX contain system information, and therefore are designed to be invisible by default. These files are called “hidden” files and are denoted by the “.” (dot) prefix.
Generally in the Solaris environment, the file type is not indicated by the extension unless it was generated by an application. The file command enables administrators to determine the type.
# Using the file command $ file filename
The file command outputs one of the following:
- Text – ASCII, english and command text as well as executable shell scripts.
- Data – files created by programs.
- Executable/Binary – executable files which are commands or programs.
The cat command is the short form for catenate. It is used to create a file and write outputs from commands to it. Press “ctrl+c” on a new line to exit. The more common use of the command is to view the contents of a file. It is advised to not attempt to read binary files as it is known to cause the terminal window to freeze.
# Write to file $ cat > filename # View contents of files $ cat filename
3| File Permissions
Like any system, UNIX allows file access control, which enables users and administrators to define and control the permissions of files and directories. There are three levels of access permission which is the owner, group and others.
File Access Definitions
A single character defining the type of file, ie. “d”, “-“.
Symbols “r”, “w”, “x” and “-” outlining various permissions available to a file/directory.
|Permission||Definition for File||Definition for Directory|
|r (read)||The contents of the file can be read and copied.||File names within the directory are visible, however, various details may be hidden.|
|w (write)||The file can be modified and content can be written to it. Requires the read permission to function properly.||Files can be added or removed from directory. The execute permission must be enabled for proper functionality.|
|x (execute)||File can be executed and run as a process.||The user can traverse within and change to the directory and potential access to files and subdirectories.|
|– (no permission)||No read, write or execute permissions.||No read, write or execute permissions.|
Number of links within the file system which is pointing to the file or directory.
The user who created the file or directory.
A collection of users which can be given permissions as a whole.
The number of bytes used by the operating system to store the list of files in a directory.
The date which the file was last modified or written to. Alternatively, the “-u” option can be used to display the date it was last read or accessed.
The name of the file or directory.
Permission Option Definitions
Makes use of a combination of letters and symbols to add or remove permissions. It is also referred to as a relative mode.
An absolute or numeric mode which utilises a collection of numbers to represent file permissions.
|0||0 + 0 + 0||– – –||No Permissions|
|1||0 + 0 + 1||– – x||Execute Only|
|2||0 + 2 + 0||– w –||Write Only|
|3||0 + 2 + 1||– w x||Write and Execute|
|4||4 + 0 + 0||r – –||Read Only|
|5||4 + 0 + 1||r – x||Read and Execute|
|6||4 + 2 + 0||r w –||Read and Write|
|7||4 + 2 + 1||r w x||Read, Write and Execute|
Change Mode Command
Allows access permissions of files and directories to be modified using either symbolic or octal modes.
# Set permissions for a file $ chmod 754 myfile $ chmod u=rwx,g=rx,o=r myfile $ chmod ug+x myfile $ chmod o-wx myfile
Default User Mask
The umask command can be used to change and set a default user mask. This mask is set as an octal value comprised of 3 digits. The default umask is 022, with file permissions being 666 and directory or executable file, 777. The umask sets permissions by subtracting the umask from default permissions.
# Set User Mask $ umask 022
Set User ID
A special permission in UNIX allows ordinary users to execute programs as if it was done by the root user. It is useful for enabling system administration tasks to be performed without a requirement to gain direct access to the root account.
# Set user id $ chmod 4755 filename # setuid bit is set with 4000 in octal mode $ chmod u+s filename # lowercase "s" is added to user
Set Group ID
Group ID permissions is used in a similar manner to setting the user ID. This allows users in a certain group to have root execution permissions. This generally grants access to additional files.
# Set group id $ chmod 2755 filename # setgid bit is set with 2000 in octal mode $ chmod g+s filename # lowercase "s" is added to group
Sticky Bit Permission
The sticky bit permission prevents users from deleting files that they do not have ownership of in a shared directory. Generally, users with write permission for a file inherits the ability to delete that file, however, the sticky bit prevents deletion regardless of the file’s permission. Users without execute permissions to a file are not affected by sticky bit.
# Enable sticky bit on a file $ chmod 1755 filename # sticky bit is set with 1000 in octal mode $ chmod +t filename # lowercase "t" is added to group
4| Using Text Editors
Text editors are used to accomplish a variety of tasks ranging from writing shell scripts to customising the user’s work environment. A common use for them is for coding HTML web pages and computer programs. It is also used to modify system files.
The vi Editor
The vi or visual editor is an text editor to create or modify ASCII text files. ASCII is a format that consists of only characters and eliminates all formatting such as italics, underline, bold, etc.
This editor is very powerful as well as small in terms of system resource usage, and supports a large host of functions. The key distinguishing factor between vi and other editors is that unlike the name, there is nothing visual about it. It is a simple full screen window that allows characters to be written to a file without any mouse support.
The vi editor is a very crucial tool for system administrators as it may sometimes be the only available text editor. Furthermore, many remote server applications benefit from the availability and functionality of the vi editor.
# Starting up the improved visual editor $ vim # vi improved # Basic syntax of the vi command $ vi filename
The vi Modes
Command mode is the default vi mode. Performing a command enters the edit mode.
|Command Mode||The default mode for editing existing text. Commands are initiated from this mode, and pressing escape (esc) will enter this mode from other modes.|
|Entry (Input) Mode||Used to write new text. Using the “i” (insert), “a” (append) and “o” (open new line) commands will initiate entry mode. (Do not require return key to register command)|
|Last Line Mode||Used to save and quit vi editor. The colon (:) key will enter this mode, while colon+q (:q) followed by return will quit vi.|