| Previous | Table of Contents | Next |
sort - Sort-Merge Files
$sort [ –cmu ] [ –ofile ] [ –yk ] [ –zn ] [ –dfiMnr] [ –btc ]
[ +pos1 –pos2 ]] [ files ]
Description:
The sort command sorts lines from files.
Options:
| –b | ignore leading tabs and spaces | |
| –c | check that the input is in sorted order | |
| –d | sort in dictionary order; only letters, digits, and white-space are significant in comparisons | |
| –f | sort upper and lower case letters together | |
| –i | ignore non-printable characters | |
| –m | merge already sorted files | |
| –M | sort as months. The first three non-blank characters are converted to upper case and compared. (implies –b) | |
| –n | sort by numerical value; blanks, minus signs, and decimal points can also be given (implies –b) | |
| –ofile | send output to file (default standard output) | |
| –r | reverse the sorting order | |
| –tc | set the field separator to c | |
| –u | display only one occurrence of duplicate lines | |
| –y[k] | use k kilobytes of memory to sort (default max) | |
| –zn | use n bytes of buffer for long lines | |
| files | read standard input if files is – or no files given | |
| +pos1 [ –pos2] | sort from pos1 to pos2. If pos2 is not specified, sort from pos1 to the end of line. The format for pos1 and pos2 is: m[.n] [bdfinr] | |
| m | m fields from start of line (default 0) | |
| n | n characters from start of field (default 0) | |
| bdfinr | option applies to the specified key only | |
tr - Translate Characters
$tr [ –cds ] [ string1 ] [ string2 ]
Description:
The tr command copies standard input to output and translates characters from string1 to characters in string2.
Options:
| –c | translate characters not in string1 |
| –d | delete characters in string1 from input |
| –s | truncate repeated characters from string2 |
Strings:
| [a–z] | specifies a range of characters from a to z |
| [c*n] | specifies n repetitions of c. If the first digit in n is 0, n interpreted as octal. (default decimal) |
uniq - Report Duplicate Lines
$uniq [ –udc [ +n ] [ –n ] ] [ file1 [ file2 ] ]
Description:
The uniq command removes duplicate adjacent lines from file1 and places the output in file2.
Options:
| –c | display a count of duplicate lines also |
| –d | display only duplicate lines once |
| –u | display only unique lines from the original file |
| –n | skip first n fields from start of line |
| +n | skip first n characters from the start of field |
wc - Count Characters, Lines and Words
$wc [ –clw ] [ files ]
Description:
The wc command counts the characters, lines, or words in the specified files. A total count for all files is kept.
Options:
| –c | display number of characters (default all options) |
| –l | display number of lines |
| –w | display number of words |
| files | read standard input if no files are specified |
# Execute multiple commands on one line
% pwd ; ls tmp ; echo "Hello world"
# Run the find command in the background
% find . -name tmp.out -print &
# Connect the output of who to grep
% who | grep fred
# Talk to fred if he is logged on
% ( who | grep fred ) && talk fred
# Send ls output to ls.out
% ls > ls.out
# Send find standard output and standard error to find.out
% find / -atime +90 -print >& find.out
# Append output of ls to ls.out; do not check if ls.out exists
% ls >>! ls.out
# Send invite.txt to dick, jane, and spot
% mail dick jane spot < invite.txt
# List file names that begin with z
% ls z*
# List two, three, and four character file names
% ls {??, ???, ????}
# List file names that begin with a, b, or c
% ls [a-c]*
# List the files in sam's home directory
% ls ~sam
# Create an alias for the ls –lR command
% alias lsl "ls -lR"
# Reexecute last command
% !!
# Reexecute the last more command
% !more
# Reexecute the last command, changing adm to sys
% ^sys^adm
# Reexecute last find command, changing tmp to core
% !find:*:s/tmp/core
# Set NU to the number of users that are logged on
% set NU=`who | wc -l`
# Set TOTAL to the sum of 4 + 3
% @ TOTAL=4 + 3
# Set LBIN to /usr/lbin
% set LBIN=/usr/lbin
# Unset variable LBIN
% unset LBIN
# Add /usr/lbin to the path variable
% set path=($path /usr/lbin)
# Disable filename substitution
% set noglob
# Display $HOME set to /home/anatole
% echo '$HOME set to' $HOME
# Display the number of positional parameters
% echo "There are $#argv positional parameters"
# Display the value of positional parameter 2
% echo $argv[2]
# Display the number of words in path
% echo $#path
# Bring background job 3 into the foreground
% fg %3
# Stop the find job
% stop %find
# Display all information about current jobs
% jobs -l
# Terminate job 5
% kill %5
# Increment variable X
% @ X=X++
# Set variable X to 20 modulo 5
% @ X=20 % 5
# Set diagnostic mode
% csh -x
# Run the dbscript in noexec mode
% csh -n dbscript
# Display the current directory stack
% dirs
# Put /usr/spool/uucppublic on the directory stack and cd to it
% pushd /usr/spool/uucppublic
# Check for new mail every 2 minutes
% set mail=(120 ~/newmail)
# Set prompt to the command number and current directory
% set prompt=!`pwd`
# Check if VAR is set to null
% if ($?VAR) echo "VAR set ok"
# Check if VAR is set to ABC
% if ($VAR == "ABC" ) echo "VAR set to ABC"
# Check if xfile is empty
% if (-z xfile ) echo "xfile is empty"
# Check if tmp is a directory
% if ( -d tmp ) echo "tmp is a directory"
# Check if file is readable and writable
% if (-r file && -w file ) echo "file ok"
# Set a trap to ignore interrupts
% onintr -
# Set the file size creation limit to 10 Mbytes
% limit filesize 10m
# Remove the limitation on the cputime resource
% unlimit cputime
# Read and execute the commands in .runlog
% source .runlog
# Disable core dumps
% limit coredumpsize 0m
# Display the last 10 commands
% history -r 10
# Add group write permission to the file creation mask
% umask 013
# Display the first and third fields from file
% awk '{print $1, $3}' file
# Display the first seven characters of each line in tfile
% cut –c1–7 tfile
# Display the first and third fields from the /etc/passwd file
% cut –f1,3 –d":" /etc/passwd
# Display lines in names that begin with A, B, C, or Z
% egrep '[A–C,Z]*' names
# Display lines from dict that contain four character words
% egrep '....' dict
# Display password entries for users with the Korn shell
% grep ":/bin/ksh$' /etc/passwd
# Display number of lines in ufile that contain unix; ignore case
% grep –c 'unix' ufile
# Display the lengths of field 1 from file
% nawk '{TMP=length($1); print $TMP}' file
# Display the first ten lines of tfile
% nawk '{for (i=1; i<10; i++) printf "%s\n", \ getline}' tfile
# List the contents of the current directory in three columns
% ls | paste d" " – – –
# Display file with all occurrences of The substituted with A
% sed 's/The/A/g' file
# Display your user name only
% id | sed 's/).*//' | sed 's/.*(//'
# Display file with lines that contain unix deleted
% sed '/unix/d' file
# Display the first 50 lines of file
% sed 50q file
# Sort the /etc/passwd file by group id
% sort -t":" -n +3 -4 /etc/passwd
# Translate lower case letters in file to upper case
% cat file | tr a-z A-Z
# Display adjacent duplicate lines in file
% uniq –d file
# Display the numbers of characters and words in file
% wc –l file
# Display the number of .c files in the current directory
% ls *.c | wc -l
| Previous | Table of Contents | Next |