惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

宝玉的分享
宝玉的分享
NISL@THU
NISL@THU
E
Exploit-DB.com RSS Feed
L
LINUX DO - 热门话题
L
Lohrmann on Cybersecurity
K
Kaspersky official blog
Project Zero
Project Zero
Cisco Talos Blog
Cisco Talos Blog
T
The Exploit Database - CXSecurity.com
P
Palo Alto Networks Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
Threatpost
S
Schneier on Security
G
GRAHAM CLULEY
The Hacker News
The Hacker News
T
Threat Research - Cisco Blogs
Scott Helme
Scott Helme
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Privacy & Cybersecurity Law Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
Cyberwarzone
Cyberwarzone
C
CERT Recently Published Vulnerability Notes
T
Tor Project blog
AWS News Blog
AWS News Blog
Simon Willison's Weblog
Simon Willison's Weblog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
爱范儿
爱范儿
P
Privacy International News Feed
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
S
Securelist
G
Google Developers Blog
The Last Watchdog
The Last Watchdog
Google Online Security Blog
Google Online Security Blog
美团技术团队
F
Fortinet All Blogs
小众软件
小众软件
Recorded Future
Recorded Future
V
Visual Studio Blog
B
Blog RSS Feed
H
Help Net Security
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Google DeepMind News
Google DeepMind News
Blog — PlanetScale
Blog — PlanetScale
博客园 - 聂微东
Stack Overflow Blog
Stack Overflow Blog
Martin Fowler
Martin Fowler
Latest news
Latest news
Spread Privacy
Spread Privacy
H
Heimdal Security Blog

博客园 - tony

The fastest way going abroad... Love is meeting the requirments, too... Fight back and hold back... Section 14: The UNIX File System Section 13: Interactive Use of the Shell Section 11: The Execution Environment Section 10: Editing Text with EMACS Section 9: Interaction and Job Control Section 8: Process Control and Multitasking Section 7: Pipelines and Filters Section 6: Redirecting Input and Output Section 5: Working with Files and Directories Section 4: The UNIX Shell Section 3: Logging In and Logging Out Section 2: Accessing a UNIX System Section 1: What Is UNIX? An overview about our Martch work... Obesession... Oh,,,CHANEL...
Section 12: Customizing the UNIX Shell
tony · 2005-03-31 · via 博客园 - tony

The UNIX shell is a actually a user program that the kernel runs for you when you log in. There is usually more than one shell available on most UNIX systems. The most common shells available on UNIX systems are the Bourne Shell (sh), the C Shell (csh) and the Korn shell (ksh). Here is a summary of features available on these three shells, adapted from the Hewlett Packard "Beginner's Guide to HPUX."

Feature Function sh csh ksh
Job control Allows processes to be
run in the background
No Yes Yes
History substitution Allows previous commands to be
saved, edited, and reused
No Yes Yes
File name completion Allows automatic completion of
partially typed file name
No Yes Yes
Command line editing Allows the use of an editor to
modify the command line text
No No Yes
Command aliasing Allows the user to rename
commands
No Yes Yes

Choosing your shell

It is possible to invoke any available shell from within another shell. To start a new shell, you can simply type the name of the shell you want to run, ksh, csh, or sh.

It is also possible to set the default startup shell for all your future sessions. The default shell for your account is stored in the system database /etc/passwd, along with the other information about your account. To change your default shell, use the chsh command The cshs command requires one argument, the name of the shell you want as your default. To change tour default shell to the C shell, you could enter the command

chsh /bin/csh

On ISU's HP-UX system, the available shells are /bin/sh, /bin/posix/sh, and /bin/csh. The default shell for accounts is /bin/posix/sh, which is, for all practical purposes, the same as ksh.

Default file access permissions

Whenever you create a file or directory in a UNIX filesystem, the newly created file or directory is stamped with a default set of permissions. That default set of permissions is stored in a variable called the umask. You can change the value of umask to suit your preferences. To see the current value of the umask variable, enter the shell command:

umask

The umask is stored as an octal (base 8) number, that defines which permissions to deny. As you recall, three kinds of file permissions (read, write, and execute) are given for each of three classes of users (owner, group, and others). Each of the nine permissions is specified as a zero (allow access), or a one (deny access).

To set your umask to deny write permission to group and others, use the command

umask 022

To deny all access to group and others, use the command

umask 077

Some versions of UNIX provide a more user-friendly way of specifying your umask. In HP-UX sh-posix (or ksh), you are allowed to specify the access permissions in manner of the chmod command. The command

umask u=rwx,g=r,o=r

would set the umask to deny write and execute permissions to the group, and to others. That kind of command syntax will not work in HP-UX's C shell or Bourne shell. The HP-UX posix shell also allows the use of the command

umask -S

to print your umask setting in a more readable fashion.

Customizing with user login scripts

The remainder of this section describes some of the ways you can initialize ksh, by presenting the default user login scripts provided to users of ISU's CWIS machine. The scripts have been annotated with descriptions of the purpose of each set of commands.

The .profile file

#!/bin/posix/sh

#******************************************************************************
# Run the script .shrc in every subshell.
#******************************************************************************
ENV="$HOME/.shrc";export ENV

#******************************************************************************
# Leave a sign of last login in user's home directory
# Remove this line if you don't want such records left.
# All logins are logged elsewhere, anyway.
#******************************************************************************
touch $HOME/.lastlogin
chmod 600 $HOME/.lastlogin

#******************************************************************************
# THREE TYPES OF TERMINAL-CHOOSING MECHANISMS ARE PRESENTED BELOW. ONLY
# ONE SHOULD BE USED. AUTOMATIC DETECTION OF TERMINAL TYPE IS THE DEFAULT.
#******************************************************************************

#******************************************************************************
# Uncomment the following line (i.e. remove # at the beginning of line)
# to make it so you're prompted for terminal type at login (rather than 
# having term type hard-coded or having the system automatically detect
# your terminal type). Replace 'vt220' with another term type if you want a 
# different default terminal type presented with the user prompt.
#******************************************************************************
# eval ` tset -s -Q -m ":?vt220" `

#******************************************************************************
# Uncomment the following line (i.e. remove # at beginning of line)
# if you want to hard-code a terminal type. 
# Replace 'vt220' with any desired terminal type. Use this option only if
# you are always using the same type of terminal, and if the system doesn't
# seem to properly detect your terminal type.
#******************************************************************************
# TERM=vt220

#******************************************************************************
# If you chose either of the above terminal-choosing options, comment out
# the following section from 'if' to 'fi' (insert a # at the beginning of
# each line). Otherwise, the default terminal handling for terminal access
# is to have the system attempt to detect your terminal type.
#******************************************************************************
if [ "${TERM}X" = "X" ]
then 
  TERM=`ttytype`
  case $TERM in
    *2382* | *2392* | *2393* | *2394* |  *2397* | *2621*  )  TERM="hp" ;; 
    *2621* | *2622* | *2623* | *2624* |  *2625* | *2626*  )  TERM="hp" ;;
    *2627* | *2628* | *2640* | *2641* |  *2644* | *2645*  )  TERM="hp" ;;
    *2647* | *2648* | *2649* | *150*  | *70092* | *70094* )  TERM="hp" ;;
  esac
fi

#*****************************************************************************
# Leave this line alone: it applies for all terminal-setting options
#*****************************************************************************
export TERM

#******************************************************************************
# Set up the terminal:
#******************************************************************************
stty hupcl ixon ixoff ienqak -parity
stty erase "^H" kill "^U" intr "^C" eof "^D" susp "^Z"
tabs

#*****************************************************************************
# Display little menu of options
#*****************************************************************************
/usr/local/bin/menu


The .shrc file

#!/bin/posix/sh

#*****************************************************************************
# Set default permissions so that you can read and write all files, and that
# others can't. Changing this can potentially mess up the security of your 
# account, so make sure you know what you're doing before changing this.
#*****************************************************************************
umask 077 

#******************************************************************************
# set paths: PATH tells the shell where to look for programs/commands when
# you type command or program names. MANPATH tells the shell where to look
# for unix 'man' pages. NNTPSERVER tells newsreaders to get usenet news from
# the cwis computer.
#******************************************************************************
PATH=$HOME/bin:.:/bin/posix:/bin:/usr/bin:/usr/contrib/bin:/usr/local/bin:/usr/bin/X11:/usr/local/bin/X11:/usr/contrib/bin/X11:/share/gen/bin:/share/X11/bin

MANPATH=/usr/man:/usr/local/man:/usr/contrib/man:/share/gen/man:/share/X11/man

NNTPSERVER=localhost

#******************************************************************************
# Set up the shell environment variables: 
# HOST and GROUPNAME get set for old cwis menus.
# If you want an editor other than pico (like vi or emacs) to be your default 
#     editor, replace pico with the name of your preferred editor.
# HISTSIZE determines how many of your previous commands are retained for 
#     recalling. 
# The line with PAGER determines the default pager to use for reading through
#     documents one page at a time. 
# The line with LESS makes it so informative keystroke prompts are put at the
#     bottom of the screen when using the less pager.
# LPDES determines which printer queue your print jobs submitted with the lp 
#     command go to. This line is changed by the 'printers' program, so try 
#     not to radically alter this line. You can manually change the queue name
#     here if you want to.
#******************************************************************************
export HOST=`hostname`
export GROUPNAME=`groups -p $LOGNAME`
EDITOR=pico;export EDITOR
HISTSIZE=200;export HISTSIZE
PAGER="less";export PAGER
LESS='-c -P spacebar\:page ahead b\:page back /\:search ahead \?\:search back h\:help q\:quit';export LESS
LPDEST=laser_q2;export LPDEST

#*****************************************************************************
# Treat unset parameters as an error when substituting.
# Don't mess with this unless you're a guru.
#*****************************************************************************
set +u

#*****************************************************************************
# Make it so your terminal is not open to talk requests and placement of 
# comments on your screen by other users. Change this line to 'mesg y' if
# you want to be open to talk requests by default. Otherwise, you can type
# 'mesg y' within a session to temporarily open yourself for talk requests.
#*****************************************************************************
mesg n

#*****************************************************************************
# Set up shell for vi-style command line editing (i.e. recalling commands with
# ESC-k, and using vi editor keystrokes to edit command lines).) If you prefer,
# you can replace 'vi' with 'emacs' for emacs-style command line editing (i.e.
# recalling commands with control-P, and using emacs editor keystrokes to edit
# the command line.
#*****************************************************************************
set -o vi

#*****************************************************************************
# Define user prompt to show hostname and current directory.
# This can be changed to anything.
# Change it to 
#
#    PS1 = 'GET TO WORK, BOZO!! ' 
#
# if you want the command prompt to repeatedly insult you.
#*****************************************************************************
PS1='cwis:$PWD
$ '

#****************************************************************************
# Create custom commands. All can be removed/altered *except* 'printers.
# Feel free to create your own custom commands.
# The command 'printers' is necessary for the proper functioning of the cwis
#   printer-choosing utility. The 'printers' program changes the line that 
#   sets default printer queue in this file, and this file gets "run" again 
#   to load the new value into the user environment.
# The command 'more' is altered to call the more capable 'less' pager. Disable
#   this alias if you want to use the 'more' pager.
# The command 'ls' is set up to identify executable
#    files with an * and directories with a /. Remove this alias if you want
#    the ls command to behave normally, i.e. without the * and /.    
# The command 'edit' is set up to call default editor (see EDITOR=... above).
# The command 'oldmenu' brings up the old cwis menus.
# The command 'logout' calls the unix command 'exit' to log out.
# The command 'webperms' sets up file permissions to be world-readable, for
#     web publishing.
# The command 'regperms' returns file permissions to readable by user only.
#****************************************************************************
alias printers="/share/gen/bin/printers;. $HOME/.shrc"
alias more="less"
alias ls="ls -F"
alias dir="ls -F"
alias edit="$EDITOR"
alias oldmenu=". /usr/local/bin/cwis2"
alias logout="exit"
alias quit="exit"
alias bye="exit"
alias log="exit"
alias webperms="umask 022;chmod -R a+r $HOME/public_html"
alias regperms="umask 077"