Beruflich Dokumente
Kultur Dokumente
file
A file containing the calculations/functions to perform. May be piped from standard input
-v, --version Print the version number and copyright and quit.
bc is a language that supports arbitrary precision numbers with interactive execution of statements. bc starts by processing code from all the files listed on the command line in the order listed. After all files have been processed, bc reads from the standard input. All code is executed as it is read. (If a file contains a command to halt the processor, bc will never read from the standard input.) The most common use of bc is within a shell script, using a "here" document to pass the program details to bc.
cat Concatenate and print (display) the content of files. Syntax cat [Options] [File]...
-A, --show-all
equivalent to -vET
-e
equivalent to -vE
-E, --show-ends
-n, --number
-s, --squeeze-blank
-t
equivalent to -vT
-T, --show-tabs
-u
(ignored)
-v, --show-nonprinting use ^ and M- notation, except for LFD and TAB
--help
--version
chmod Change access permissions, change mode. Syntax chmod [Options]... Mode [,Mode]... file...
output a diagnostic for every file processed like verbose but report only when a change is made
-R, --recursive
--help
--version
chmod changes the permissions of each given file according to mode, where mode describes the permissions to modify. Mode can be specified with octal numbers or with letters. Using letters is easier to understand for most people.
cmp Compare two files, and if they differ, tells the first byte and line number where they differ. You can use the `cmp' command to show the offsets and line numbers where two files differ. `cmp' can also show all the characters that differ between the two files, side by side. Syntax cmp options... FromFile [ToFile]
Options Multiple single letter options (unless they take an argument) can be combined into a single command line word: so `-cl' is equivalent to -c -l.
-c Print the differing characters. Display control characters as a `^' followed by a letter of the alphabet and precede characters that have the high bit set with `M-' (which stands for "meta").
--ignore-initial=BYTES Ignore any differences in the the first BYTES bytes of the input files. Treat files with fewer than BYTES bytes as if they are empty.
-l Print the (decimal) offsets and (octal) values of all differing bytes.
--print-chars
Print the differing characters. Display control characters as a `^' followed by a letter of the alphabet and precede characters that have the high bit set with `M-' (which stands for "meta").
--quiet -s --silent Do not print anything; only return an exit status indicating whether the files differ.
--verbose Print the (decimal) offsets and (octal) values of all differing bytes.
date [option] [MMDDhhmm[[CC]YY][.ss]] `date' with no arguments prints the current time and date, in the format of the %c directive (described below). If given an argument that starts with a +, date prints the current time and date (or the time and date specified by the --date option, see below) in the format defined by that argument, which is the same as in the strftime function. Except for directives, which start with %, characters in the format string are printed unchanged. The directives are described below. Options: -d, --date=String Display time described by String, instead of `now'
this can be in almost any common format. It can contain month names, timezones, `am' and `pm', `yesterday', `ago', `next', etc.
-f, --file=DateFile
If DateFile is `-', use standard input. This is useful when you have many dates to process, because the system overhead of starting up the `date' executable many times can be considerable.
-I, --iso-8601[=Timespec] Output an ISO-8601 compliant date/time string., `%Y-%m-%d'. Timespec=`date' (or missing) for date only, `hours', `minutes', or `seconds' for date and time to the indicated precision. If showing any time terms, then include the time zone
using the format `%z'. If `--utc' is also specified, use `%Z' in place of `%z'.
-r, --reference=File
-R, --rfc-822
-s, --set=String
--help --version
Display this help and exit output version information and exit
Here are the same format codes in alphabetical order: %% a literal % %a locale's abbreviated weekday name (Sun..Sat) %A locale's full weekday name, variable length (Sunday..Saturday) %b locale's abbreviated month name (Jan..Dec) %B locale's full month name, variable length (January..December) %c locale's date and time (Sat Nov 04 12:02:33 EST 1989) %d day of month (01..31) %D date (mm/dd/yy) %e day of month, blank padded ( 1..31) %h same as %b, locale's abbreviated month name (Jan..Dec) %H hour :24 hour(00..23) %I hour :12 hour(01..12) %j day of year (001..366) %k hour :24 hour(00..23)
%l hour :12 hour(01..12) %m month (01..12) %M minute (00..59) %n a newline %p locale's AM or PM %r time, 12-hour (hh:mm:ss [AP]M) %s seconds since 00:00:00, Jan 1, 1970 (a GNU extension) Note that this value is defined by the localtime system call. It isn't changed by the `--date' option. %S second (00..60) %t a horizontal tab %T time, 24-hour (hh:mm:ss) %U week number of year with Sunday as first day of week (00..53) %V week number of year with Monday as first day of week (01..53) If the week containing January 1 has four or more days in the new year, then it is considered week 1; otherwise, it is week 53 of the previous year, and the next week is week 1. (See the ISO 8601: 1988 standard.)
%w day of week (0..6); 0 represents Sunday %W week number of year with Monday as first day of week (00..53) %x locale's date representation (mm/dd/yy) %X locale's time representation (%H:%M:%S) %y last two digits of year (00..99) %Y year (1970...) %z RFC-822 style numeric timezone (-0500) (a nonstandard extension) This value reflects the _current_ time zone. It isn't changed by the `--date' option.
%Z time zone (e.g., EDT), or nothing if no time zone is determinable This value reflects the _current_ time zone. It isn't changed by the `--date' option.
echo Display message on screen, writes each given STRING to standard output, with a space between each and a newline after the last one. Syntax echo [options]... [string]...
Options
\a
alert (bell)
\b
backspace
\c
\e \f
\n
new line
\r
carriage return
\t
horizontal tab
\v
vertical tab
\\
backslash
\NNN the character whose ASCII code is NNN (octal); if NNN is not a valid octal number, it is printed literally.
\xnnn the character whose ASCII code is the hexadecimal value nnn (one to three digits) echo is a BASH built-in command
expr Evaluate expressions, evaluates an expression and writes the result on standard output. Syntax expr expression...
Operands are either numbers or strings. `expr' coerces anything appearing in an operand position to an integer or a string depending on the operation being applied to it.
Strings are not quoted for `expr' itself, though you may need to quote them to protect characters with special meaning to the shell, e.g., spaces.
Operators may given as infix symbols or prefix keywords. Parentheses may be used for grouping in the usual manner (you must quote parentheses to avoid the shell evaluating them, however).
Examples
To print the non-directory part of the file name stored in `$fname', which need not contain a `/'. expr $fname : '.*/\(^.*\)' '^|' $fname
expr abc : 'a\(.\)c' => b expr index abcdef cz => 3 expr index index a error--> expr: syntax error expr index quote index a => 0
head Output the first part of files, prints the first part (10 lines by default) of each file. SYNTAX head [options]... [file]...
Options:
-NUMBER Return the first NUMBER of lines from the file. (must be the first option specified)
-CountOptions This option is only recognized if it is specified first. Count is a decimal number optionally followed by a size letter ('b', 'k', 'm' for bytes, Kilobytes or Megabytes) , or 'l' to mean count by lines, or other option letters ('cqv'). -c BYTES --bytes=BYTES Print the first BYTES bytes, instead of initial lines. Appending 'b' multiplies BYTES by 512, 'k' by 1024, and 'm' by 1048576.
-v --verbose Always print file name headers. If no files are given (or if given a FILE of '-') head will read from standard input. If more than one FILE is specified, 'head' will print a one-line header consisting of ==> FILE NAME <== before the output for each FILE.
kill Stop a process from running, either via a signal or forced termination. Syntax kill [-s sigspec] [-n signum] [-sigspec] jobspec or pid kill -l [exit_status] kill -l [sigspec]
Key -l List the signal names -s Send a specific signal -n Send a specific signal number Send a signal specified by sigspec or signum to the process named by job specification jobspec or process ID pid. sigspec is either a case-insensitive signal name such as SIGINT (with or without the SIG prefix) or a signal number; signum is a signal number. If sigspec is not present, SIGTERM is used (Terminate). If any arguments are supplied when `-l' is given, the names of the signals corresponding to the arguments are listed, and the return status is zero. exit_status is a number specifying a signal number or the exit status of a process terminated by a signal. The return status is true if at least one signal was successfully sent, or false if an error occurs or an invalid option is encountered.
ls
List information about files.
-a, --all
-A, --almost-all
-b, --escape
--block-size=SIZE
-B, --ignore-backups
-c
-C
--color[=WHEN]
-d, --directory
-D, --dired
-f
-F, --classify
--format=WORD
--full-time
-g
(ignored)
-G, --no-group
--indicator-style=WORD Append indicator with style WORD to entry names: none (default), classify (-F), file-type (-p)
-i, --inode
-I, --ignore=PATTERN
-k, --kilobytes
Like --block-size=1024
-l
-L, --dereference
-m
-n, --numeric-uid-gid
-N, --literal
Print raw entry names (don't treat e.g. control characters specially)
-o
-p, --file-type
-Q, --quote-name
--quoting-style=WORD Use quoting style WORD for entry names: literal, shell, shell-always, c, escape
-r, --reverse
-R, --recursive
-s, --size
-S
--sort=WORD
size -S, extension -X, none -U atime -u, access -u, use -u
--time=WORD
atime, access, use, ctime or status; also use this as a sort key if --sort=time
-t
-T, --tabsize=COLS
-u
-U
-v
sort by version
-w, --width=COLS
-x
-X
-1
--help
--version
The most common options are -a (all files) and -l (long or details)
mkdir Create new folder(s), if they do not already exist. SYNTAX mkdir [Options] folder...
OPTIONS -m, --mode=MODE set permission mode (as in chmod), not rwxrwxrwx - umask
no error if existing, make parent directories as needed print a message for each created directory
mkdir creates the standard entries . (dot) for the current folder and .. (dot dot) for its parent Any folder name that includes spaces may appear in some applications as "Name%20with%20spaces"
mv [options]... Source... Directory If the last argument names an existing directory, `mv' moves each other given file into a file with the same name in that directory. Otherwise, if only two files are given, it renames the first as the second. It is an error if the last argument is not a directory and more than two files are given. OPTIONS
-b --backup Make a backup of each file that would otherwise be overwritten or removed.
-f --force Remove existing destination files and never prompt the user.
-i --interactive Prompt whether to overwrite each existing destination file, regardless of its permissions. If the response does not begin with `y' or `Y', the file is skipped.
-S SUFFIX --suffix=SUFFIX Append SUFFIX to each backup file made with `-b'. The backup suffix is ~, unless set with SIMPLE_BACKUP_SUFFIX.
-u --update Do not move a nondirectory that has an existing destination with the same or newer modification time.
-V METHOD --version-control=METHOD' Change the type of backups made with `-b'. METHOD can be:
t, numbered
nil, existing numbered if numbered backups exist, simple otherwise never, simple always make simple backups
OPTIONS -d, --delete delete the password for the named account (root only)
-f, --force
-l, --lock
-S, --status
--stdin
-u, --unlock
-?, --help
--usage
If no options are specified - passwd will change the password of the currently logged in user - will prompt for the old and new passwords.
pwd
Print Working Directory (shell builtin) Syntax pwd [-LP]
Options -P : The pathname printed will not contain symbolic links. -L : The pathname printed may contain symbolic links The default action is to show the current folder as an absolute path. All components of the path will be actual folder names - none will be symbolic links.
rm
Remove files (delete/unlink) Syntax rm [options]... file...
-f, --force
-v, --verbose
--help
--version
To remove a file you must have write permission on the file and the folder where it is stored. rm -rf will recursively remove folders and their contents The OWNER of a file does not need rw permissions in order to rm it.
read Read a line from standard input Syntax read [-ers] [-a aname] [-p prompt] [-t timeout] [-n nchars] [-d delim] [name...]
Options
-a aname The words are assigned to sequential indices of the array variable aname, starting at 0. All elements are removed from aname before the assignment. Other name arguments are ignored.
-d delim The first character of delim is used to terminate the input line, rather than newline.
-e If the standard input is coming from a terminal, Readline is used to obtain the line.
-n nchars read returns after reading nchars characters rather than waiting for a complete line of input.
-p prompt Display prompt, without a trailing newline, before attempting to read any input. The prompt is displayed only if input is coming from a terminal.
-r If this option is given, backslash does not act as an escape character. The backslash is considered to be part of the line. In particular, a backslash-newline pair may not be used as a line continuation.
-s Silent mode. If input is coming from a terminal, characters are not echoed.
-t timeout Cause read to time out and return failure if a complete line of input is not read within timeout seconds. This option has no effect if read is not reading input from the terminal or a pipe. This is a BASH shell builtin. sort
Sort text files. Sort, merge, or compare all the lines from the files given (or standard input.) Syntax sort [options] [file...] sort --help sort --version
Options sort has three modes of operation: Sort (the default), Merge (-m), and Check(-c)
-c
if they are
not all sorted, print an error message and exit with a status of 1.
-m
Merge the given files by sorting them as a group. Each input file should already be individually sorted. It always works to sort instead of merge; merging is provided because it is faster, in the case where it works.
sleep Delay for a specified time, pause for an amount of time specified by the sum of the values of the command line arguments. Syntax sleep [NUMBER [smhd]]...
Key:
s : seconds (default)
m : minutes
h : hours
d : days
tail Output the last part of files, print the last part (10 lines by default) of each FILE; tail reads from standard input if no files are given or when given a FILE of `-'. Syntax tail [options]... [file]...
tee Redirect output to multiple files, copies standard input to standard output and also to any files given as arguments. This is useful when you want not only to send some data down a pipe, but also to save a copy. Syntax tee [options]... [file]...
Options -a --append
Append standard input to the given files rather than overwriting them.
Example:
ps -ax | tee processes.txt | more If a file being written to does not already exist, it is created. If a file being written to already exists, the data it previously contained is overwritten unless the `-a' option is used.
tr Translate, squeeze, and/or delete characters Syntax tr [options]... SET1 [SET2] `tr' copies standard input to standard output, performing one of the following operations: * translate, and optionally squeeze repeated characters in the result, * squeeze repeated characters, * delete characters, * delete characters, then squeeze repeated characters from the result.
The SET1 and (if given) SET2 arguments define ordered sets of characters, referred to below as SET1 and SET2. These sets are the characters of the input that `tr' operates on. The `--complement' (`-c') option replaces SET1 with its complement (all of the characters that are not in SET1).
whoami Print the current user id and name. Syntax whoami [options]
--version Display program version info whoami produces the same result as the id -un command (the id command by default provides more detailed information)
ulimit User limits - limit the use of system-wide resources. Syntax ulimit [-acdfHlmnpsStuv] [limit]
Options
-S Change and report the soft limit associated with a resource. -H Change and report the hard limit associated with a resource.
-a All current limits are reported. -c The maximum size of core files created. -d The maximum size of a process's data segment. -f The maximum size of files created by the shell(default option) -l The maximum size that may be locked into memory. -m The maximum resident set size. -n The maximum number of open file descriptors. -p The pipe buffer size. -s The maximum stack size. -t The maximum amount of cpu time in seconds. -u The maximum number of processes available to a single user. -v The maximum amount of virtual memory available to the process. ulimit is a bash built in command.
who Print who is currently logged in Syntax who [options] [file] [am i]
Options
-m Print the current user id, name and domain (Same as `who am i')
-q --count Print only the login names and the number of users logged on. Overrides all other options.
-i -u --idle After the login time, print the number of hours and minutes that the user has been idle. `.' means the user was active in last minute. `old' means the user was idle for more than 24 hours.
-l --lookup Attempt to canonicalize hostnames found in utmp through a DNS lookup. This is not the default because it can cause significant delays on systems with automatic dial-up internet access.
-w -T --mesg
--message --writable After each login name print a character indicating the user's message status:
+ allowing `write' messages - disallowing `write' messages ? cannot find terminal device
zcat
Expand and concatenate data SYNOPSIS zcat [file ... ] DESCRIPTION The zcat utility expands compressed files and writes the results to standard output. This utility is equivalent to the uncompress -c command. The zcat utility does not affect the input files. Input files must be compressed files that are in the format produced by the compress utility. The standard input is used only if no file operands are specified, or if a file operand is - (hyphen). If multiple files are provided as input, the output can be redirected to a file to concatenate the uncompressed input from all of the files. OPTIONS No options are defined for this utility by the Single UNIX Specification. OPERANDS Systems that conform to the Single UNIX Specification support the following operands: file Specifies the path name of a file. If the specified file name includes the .Z suffix, the file with that name is used as the input file. If the specified file name does not include the .Z suffix, zcat usesfile .Z as the name of the input file.
SHELL SCRIPTING
Q. WSS to print name on screen? echo Enter your name read name echo $name
Q. WSS to print the sum of two numbers? echo enter a read a echo enter b read b c=`expr $a + $b` echo the sum is $c
echo enter a read a echo enter b read b c=`expr $a \* $b` echo the sum is $c
Q. WSS to print the qoutient of two numbers? echo enter a read a echo enter b read b c=`expr $a / $b` echo the sum is $c
Q. WSS to print the difference of two numbers? echo enter a read a echo enter b rread b c=`expr $a - $b`
Q. WSS to calculate simple interest? echo enter p,r,t read p r t ans=`expr $p \* $r \* $t / 100` echo the ans is $ans
Q. WSS to change contents of a file from uppercase to lowercase? echo enter filename read name tr [ A-Z ] [ a-z] < $name >tfile mv tfile $name
Q. WSS to input filename, check its existence, check write permission, and translate from upper case to lower case? echo enter filename read name if [ -s $name ] then if [ -w $name ]
then Tr [ A-Z ] [ a-z] < $name >tfile mv tfile $name else echo not writtable fi else echo not exist fi Q. WSS to convert decimal to binary? echo enter number read num c=`expr obase=2; $num | bc` echo $c
Q. WSS to check whether user name input by user has logged in or not? echo enter name read uname if [ who|grep $uname ] then echo logged in else
Q. WSS to calculate factorial of a number? echo enter num read num if [ $num -lt 0 ] then echo no factorial elif [ $num -eq 0 ] fact =1 else fact=1 while [ $num gt 0 ] do fact=`expr $fact \* $num num=`expr $num 1` done echo factorial is $fact fi
Q. WSS to print sum of digits? echo enter number read n sum=0 while [ $n gt 0 ] do sum=`expr $sum + ($n % 10)` n=`expr $n / 10` done echo sum is $sum
Q. WSS to copy a file? echo enter filename & destination? read f d if [ -f $f ] then if [ -s $f ] then cp $f $d else echo FILE empty fi else echo file not exist fi
Q. WSS to decimal to binary without using ibase, obase? echo enter decimal number read n num=0;r=1 while [ $ -gt 1 ] do rem=`expr $n % 2` num=`expr $num + $r \* $rem` r=`expr r \* 10 n=`expr n / 2` done echo binary number is $num
Q. WSS to implement following MENU? MENU : 1. ADD 2. SUB 3. DIV 4. MUL Enter choice:
echo MENU: -n 1. ADD 2. SUB 3. DIV 4. MUL echo Enter choice: read ch
case $ch in 1) echo enter 2 numbers: read a b c=`expr $a + $b` echo the sum is $c ;; 2) echo enter 2 numbers: read a b c=`expr $a - $b` echo the difference is $c ;; 3) echo enter 2 numbers: read a b c=`expr $a / $b` echo the quotient is $c ;; 4) echo enter 2 numbers: read a b c=`expr $a \* $b` echo the product is $c ;; esac
Q. WSS to print a table of numbers using for loop? echo enter num read n
for((i=1;i<=10;i++)) do num=`expr $n \* $i` echo $n x $i = $num done Q. WSS to print Fibonacci series? echo enter limit read n a=1;b=1;c=0 for((i=0;i<n;i++)) do echo $c a=$b b=$c c=`expr $a + $b` done
Q. WSS to accept a number and print that number in reverse? echo enter number read n r=0;num=0
while [ $n gt 0 ]] do r=`expr $n % 10` num=`expr $num \* 10` n=`expr $n / 10` done echo $num
Q. WSS to print the list of files from the current directory I which you have write permission? for a in * do if [ -f a w $a ] then echo $a fi done
Q. WSS to change all files from .c to .cpp? for a in *.c do mv $a ${a% .c}.cpp
done
Q. WSS to print all prime nos from 1 to 500? flag=0 for((num=2;num<500;num++)) do for((i=2;i<=$num/2;i++)) do n=`expr $num % $i` if [ $n eq 0 ] then flag=1 fi done if [ $flag eq 0 ] then echo n $num fi done
Q. WSS to generate all combinations of 123 without repetitions? for a in 1 3 do for b in 1 3 do for c in 1 3 do if [ $a ne $b a $c ne $b a $a ne $c ] then echo $a$b$c fi done done done
Q. WSS which receives even no of filenames and copy content of one file in its next file and so on. echo enter no of filenames read n chk=`expr $n % 2` if [ $chk eq 0 ] then for i in 1 ($n / 2) do echo enter filename $i read f1 enter filename $(i + 1) read f2 cp f1 f2 i=`expr $i + 1`
Q. WSS to implement following using functions? MENU : 1) ADD 2) SUB 3) MUL 4)DIV
Enter choice:
SUM() { echo enter a,b read a b c=`expr $a + $b` echo the sum is $c } SUB() { echo enter 2 numbers: read a b c=`expr $a - $b`
echo the difference is $c } DIV() { echo enter 2 numbers: read a b c=`expr $a / $b` echo the quotient is $c } MUL() { echo enter 2 numbers: read a b c=`expr $a \* $b` echo the product is $c } echo MENU : -n 1) ADD 2) SUB echo Enter choice: read ch case ch in 1) ADD;; 2) SUB;; 3) MUL;; 4) DIV;; *)echo wrong choice;; esac 3) MUL 4)DIV