Unix Power Tools Study Notes Ch2

// How to read manpages in Unix
 
more — a pager, which allows you to page through the results. 
 
man 
-s section
-k  equi to apropos command. this option searches database files for matches of a given keyword
 
Your system may have a config file for man named /etc/man.config
 
MANPATH    —environment variable
 
…………..
whatis
whatis cat 
equi to man -f on most systems.
 
whereis
finding where a command is located
 
-b only report the executable name
-m only report the location of the manual page
-s only search for source files
-u only issue a report if any of the requested info is missing
 
cd /usr/man/man1
egrep -i ‘colum|chop’ *
 
awk, cut both handle columns 
 
if a file is compressed, use grep -Z 
 
sed command adds the name to the start of every line grep outputs. 
 
less - see the output a screenful at a time and quit (with q) when you’re done. 
 
col -b removes the overstriking (for formatted manpages)
 
Each computer on a network needs a name. uname -n shows you this name. 
 
type sort (which version of sort am I using?)
type -all sort 
 
whence — similar to type
type and whence are built into shell
 
which —external command, it works everywhere. Because it isn’t built in shell, it can’t always ind out about aliases defined in your current shell.
 
ls -li `which man` `which apropos` `which whatis`
apropos, man and whatis are just one executable file that has three hard links. (in Darwin, they are separate entities; on my system, they are also separate)
 
………tty…………….
tty — a Unix device file that handles input and output for your terminal, window, etc. Each tty has its own filename. 
run tty command at shell tells which tty you are on. 
 
$ tty
/dev/tty01
you can tell other users to type write your-username tty01
 
a system file like /etc/ttys lists which ttys are used for that. 
 
……………who…………….
who — lists the users logged on to the system now. 
search the output of who with grep 
 
who | grep “^hal “       ….where is hal logged on? 
 
 
A tty is a native terminal device, the backend is either hardware or kernel emulated. A pty (pseudo terminal device) is a terminal device which is emulated by an other program (example: xterm , screen , or ssh are such programs). A pts is the slave part of a pty.
 
……..info……..
info is based on a hypertext link linkage between topic components.
info info

 

Unix Study Notes Comments(23) Mon, 02 Nov 2015 23:34:47 -0700

Unix Power Tools Study Notes Ch1

My personal study notes. Unix Power Tools (3rd Edition)
Ch1
 
POSIX — Portable Operating System Interface (IEEE standard)
 
A shell is a command interpreter. 
 
Programs can be strung together in “pipelines” in which the output of one program is used as the input of another
 
 
A vertical bar ( | ) represents pipe and means “take the output of the program on the left and feed it into the program on the right."
 
 
less -- read its standard input from a pipe and still interact with you at the keyboard. It does that by reading directly from your tty. 
 
exception (Emacs) — once it starts, the editor works independently of the shell, reading its input and output directly from the terminal. 
 
Traditionally, a command interpreter is called a “shell”, it’s just another program. 
 
………………….
 
The Mac uses a carriage return ASCII character 015 to mark the end of each line, while Unix uses a linefeed (ASCII 012). As a result, with Unix, the file looks like one long paragraph, with no ned in sight. 
 
tr can convert every occurrence of one character in a file to another:
 
tr ‘\015’ ‘\012’ <file.mac >file.unix
 
…………………...
a basic for loop
 
for x 
do
     echo "Converting $x"
     tr ‘\015’ ‘\012’ <“$x”  > “tmp.$x"
     mv “tmp.$x” “$x"
……………………...
The search path: a list of directories that the shell should look through for a command whose name matches what is typed. The search path isn’t built into the shell, you specify in your shell setup files. 
 
PATH —an environment variable
 
……………..
The kernel is the heart of the Unix OS itself. 
The kernel assigns memory to each of the programs that are running, partitions time fairly so that each program can get its job done, handles all I/O operations, etc. 
 
daemons— are the system’s “helpers”, they run continuously, or from time to time— small but important tasks like handling mail, running network communications, feeding data to your printer. 
 
ps x —— get a list of all processes running on your system
ps aux —— see everything that’s running, including the deamons (or ps -el)
 
to turn off a UNIX, first run shutdown
when turning on a Unix machine, it runs fsck (file system disk check) first
 
………………….
ls -a
lists files including those names start with a .
 
Unix OS doesn’t consider . in a file name
 
in Unix, rm * is very dangerous, it deletes everything under the current directory
in other OS, you need to say *.*  to refer to all files
…………………..
Wildcard 
? matches a single character
* matches zero or more characters
[character-list] matches any single character that appears in the list. 
[a-zA-Z] means any alphabetic English character
 
Wildcards never match / , which is both the name of the filesystem root, and the character used to separate directory names in a path. The only way to match is to escape it (\)
……………………….
 
hierarchical file system (tree structured)
A directory is a special kind of file that lists a bunch of other files. A directory can contain any number of files (try to keep it under 100 though). A directory can also contain other directories. 
At the top, is the directory called “root” , which has the special name / 
 
/home  home directory
/etc  has configuration files
 
pwd —print working directory (to find out your current directory)
path begins with /, it is an absolution path.
./textfile can also execute the file if it is given executable file permissions
 
………………………..
File Access Permissions
The user entry in the master password file /etc/passwd defines his “primary group membership"
The /etc/group file defines the groups that are available and can also assign other users to these groups as needed. 
 
Every file belongs one user and one group. 
As the file owner, you can use chgrp to change the file’s group. 
Use chown to change the file’s owner.
 
Nine mode bits
3 groups, owner, a member of the file’s group, or other <read, write or execute>
 
…………………….
In general, a process is a program that’s running. 
 
To become the superuser, you can either log in as root or use the su command 
 
……………..Files……………..
The structures of a file is defined by the program who uses it, not by the Unix OS. 
Unix programs abide by one convention. Text files uses a single newline character (linefeed) between lines of text, rather than the carriage return-linefeed combination used in Windows or the carriage returns used in the Macintosh. This difference may cause problems when you bring files from other OS over to Unix. Windows files will often be littered with carriage returns (Ctrl-M), which are necessary for that OS but superfluous for Unix. Mac text files will appear to be one long line with no breaks. Use Unix utilities to convert Mac and Windows files for Unix. 
 
……………….Scripting…………...
 
Perl, Python and Tcl.
Perl—regular expressions, working with files and other forms of I/O.
Python— more OO and data-manipulation features than the file-manipulation and regular-expression manipulation of Perl.
Tcl— popular with Linux systems. Tk toolkit (GUI library)
 
………………Unix Networking…………….
 
The internet — is a worldwide network of computers. 
WWW — World Wide Web is a set of information servers on the Internet. The servers are linked into a hypertext web of documents, graphics, sound and more. Your browser turn that hypertext into an easy-to-use Internet interface.
 
mail
ftp — one way to transfer files between your computer and another computer with TCP/IP.
 
UUCP —Unix-to-Unix Copy, a family of programs (uucp, uux, uulog, and others)
 
Usenet — a collection of thousands of computers worldwide that exchange files called news articles
 
telnet—This utility logs into a remote computer over a network (such as the Internet) using TCP/IP. You can work on the remote computer as if it were your local computer. telnet can log you into other OS from your Unix host and vice versa. 
 
rsh— “remote shell” to run a command on a remote system w/o needing to log in interactively. Often used to start the “X Window System” 
 
ssh— acts like rsh and rlogin, but it makes a secure encrypted connection to the remote computer. 
 
rcp — “remote cp"
scp — secure version of rcp 
 
NFS— not a user utility.  The Network FileSystem and related packages like NIS (Network Information Service) let system administrator mount remote computers’ filesystems onto your local computer. 
 
write — sends msg to another use’s screen. 
talk — it splits the screen into two pieces and let users type at the same time if they wish. 
irc— Internet Relay Chat allows multiple users to carry on multiple discussions across the Internet and other networks. 
 

 

Unix Study Notes Comments(8) Mon, 02 Nov 2015 23:34:59 -0700