Linux Overview
Overview
Core unix is a collection of tiny commands, each of which performs a set, singular, and well-defined task. Creeping featurism can cripple and distort the purpose of a program
Think of most UNIX commands as if they were tools you pull from a tool bag. You don't find combination screwdriver-hammer tools, and you won't find hybrid and agglomerated commands like that in the core UNIX utility set.
Although, that that being said, Rube Goldberg would probably be running UNIX.
Core UNIX Commands
To search the man system for a string run man -k string.
Essential Sysadmin Tools
The for loop
The for loop is my favorite. I can take a list of files in a directory, or a list of words in a file, and loop through them, applying commands as I go. For example:for i in `ls *.csv` do echo $i sed "s/oldstring/newstring/g" $i > $i.new mv $i.new $i doneTo run the above either type it in at the command line or insert the commands into a file, say tmp.sh, and then run that file with the following command:
nohup sh ./tmp.sh > tmp.log 2>tmp.err &
The shell's file tests [ test file ]
See also: Script examples
Test True if -r file exists and is readable -w file exists and is writable -x file exists and is executable -f file exists and is a regular file -d file exists and is a directory -h file exists and is a symbolic link -d file exists and is a character special file -b file exists and is a block special file -s file exists and has a file size greater than 0
The shell's string tests
Test True if -z string file string's length is 0 -n string file string's length is not 0 str1 = str2 file strings are identical str1 != str2 file strings are not identical string file string is not null
Return Values
if grep $x $xfile >/dev/null; then echo "Found it" else echo "Not found" fi
Working Session: Dump data for a UNIX to AS400 migration
$ sh ./dumpas400.sh > dump.log 2>dump.err & $ ls -l dump* -rw-rw-rw- 1 lawadm lawson 4955 Mar 19 17:50 dump.err -rw-rw-rw- 1 lawadm lawson 95 Mar 19 17:50 dump.log -rwxrwxrwx 1 lawadm lawson 750 Mar 19 17:47 dump.sh $ tail dump.err Dumping GLACCTREL ... 75 Records Dumping GLADDRESS ... 10 Records Dumping GLCHART ... 6 Records Dumping GLCHARTDTL ... 3$ 0 $ tail dump.log GLADDRESS GLCHART GLCHARTDTL GLCHARTSUM GLCODES GLCOMPREL GLICHART GLINTCO GLITRANS GLMASTER