customizing linux environment tutorial 4 engr 3950u / csci 3020u operating systems instructor: dr....

12
Customizing Linux Environment Tutorial 4 ENGR 3950U / CSCI 3020U Operating Systems Instructor: Dr. Kamran Sartipi

Upload: reynard-boone

Post on 05-Jan-2016

222 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: Customizing Linux Environment Tutorial 4 ENGR 3950U / CSCI 3020U Operating Systems Instructor: Dr. Kamran Sartipi

Customizing Linux Environment

Tutorial 4 ENGR 3950U / CSCI 3020U

Operating Systems

Instructor: Dr. Kamran Sartipi

Page 2: Customizing Linux Environment Tutorial 4 ENGR 3950U / CSCI 3020U Operating Systems Instructor: Dr. Kamran Sartipi

Customizing Shell

Making it more user-friendly Adjusting it to your specific needs

There are jobs you repeat everyday Complicated tasks Commands you always forget

Page 3: Customizing Linux Environment Tutorial 4 ENGR 3950U / CSCI 3020U Operating Systems Instructor: Dr. Kamran Sartipi

Important files BASH

/etc/bashrcSystem wide functions and aliases

/etc/profilesSystem wide environment and start-up programs

~/.bash_profile ~/.bash_login ~/.profile ~/.bashrc

Page 4: Customizing Linux Environment Tutorial 4 ENGR 3950U / CSCI 3020U Operating Systems Instructor: Dr. Kamran Sartipi

BASH Invocation Order We have: login shell and interactive shell Login shells:On login:if /etc/profile exists, source it.if ~/.bash_profile exists, source it, else if ~/.bash_login exists, source it, else if ~/.profile exists, source it.On exit:if ~/.bash_logout exists, source it.

Non-login interactive shells:On startup:if ~/.bashrc exists, source it.

Page 5: Customizing Linux Environment Tutorial 4 ENGR 3950U / CSCI 3020U Operating Systems Instructor: Dr. Kamran Sartipi

Alias Create an alias, aliases allow a string to be substituted

for a word when it is used as the first word of a simple command.

SYNTAX:alias [-p] [name[=value] ...] unalias [-a] [name ... ]

If arguments are supplied, an alias is defined for each name whose value is given.

If no value is given, `alias' will print the current value of the alias.

Page 6: Customizing Linux Environment Tutorial 4 ENGR 3950U / CSCI 3020U Operating Systems Instructor: Dr. Kamran Sartipi

Alias Examples

alias nic 'nice +12 emacs -i -r -geometry 80x61+207+31 &‘

alias gh 'ghostview &‘ alias mca='mc -a‘ alias fnd 'find . -name "\!*" -print‘ alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde‘

alias l.='ls -d .* --color=tty' alias ll='ls -l --color=tty' alias ls='ls --color=tty'

Page 7: Customizing Linux Environment Tutorial 4 ENGR 3950U / CSCI 3020U Operating Systems Instructor: Dr. Kamran Sartipi

Export Export Set an environment variable. Mark each name to be

passed to child processes in the environment.

SYNTAX export [-fn] [-p] [name[=value]] OPTIONS -f The names refer to shell functions; otherwise the names refer to shell variables -n No longer mark each name for export. -p Display output in a form that may be reused as input.

If no names are supplied, or if the `-p' option is given, a list of exported names is displayed.

Page 8: Customizing Linux Environment Tutorial 4 ENGR 3950U / CSCI 3020U Operating Systems Instructor: Dr. Kamran Sartipi

Export Example

If we want to modify PATH inside a shell script and have the effect preserved when we return to the shell

PATH=$PATH:$HOME/binexport PATH

Page 9: Customizing Linux Environment Tutorial 4 ENGR 3950U / CSCI 3020U Operating Systems Instructor: Dr. Kamran Sartipi

Umask

umaskUser's file creation mask. Set the shell process's file creation mask to mode.

SYNTAX umask [-p] [-S] [mode] OPTIONS

mode File creation mask -S Print the mask in symbolic format -p Output in a form that may be reused as input

The current value of the mask will be printed if mode is omitted,

If mode begins with a digit, it is interpreted as an octal number; if not, it is interpreted as a symbolic mode mask similar to that accepted by the chmod command.

Page 10: Customizing Linux Environment Tutorial 4 ENGR 3950U / CSCI 3020U Operating Systems Instructor: Dr. Kamran Sartipi

Umask Examples

umask 02 # Full group access, deny write to others.

umask 66 # Deny read and write to group and others.

umask 77 # Deny everything to everyone.

umask 26 # Deny group write, deny read and write to others.

Page 11: Customizing Linux Environment Tutorial 4 ENGR 3950U / CSCI 3020U Operating Systems Instructor: Dr. Kamran Sartipi

Command Prompt

Similar to Dos prompt it can be customized

Examples: set prompt="[$USER] <$HOSTNAME \!> “

In Bash the $PS1 is used as the environment variable for the prompt syntax

Page 12: Customizing Linux Environment Tutorial 4 ENGR 3950U / CSCI 3020U Operating Systems Instructor: Dr. Kamran Sartipi

Miscellaneous

if ( -r ${HOME}/.aliases ) source ${HOME}/.aliases

Sourcing .aliases file if it exists.