Title: Informatik 1 / Unix commands

Q: csh
A: Invoke the c-shell variant of UNIX (to be only done at the start when you open a new terminal window)

Q: pwd
A: Print the absolute path of the current (working) directory

Q: cd dir
cd ~ or just cd
cd ..
cd .
A: - change the current directrory to dir (dir must be a directory)
- change to your home directory
- change to the parent directory (one level up from the current directory)
- change to the current directory (i.e. no change)

Q: ls
ls dir
ls [file/dir ...]
ls -R
ls -p
ls -l
ls -a
ls -t
ls -r
A: - list the contents of the current directory
- list the contents of the directory dir
- more general, with multiple file/directory names (they will be listed in sequence; for a file, the relative path is simply printed if the file exists)
-list recursively the entire contents (including subdirectories, sub-subdirectories, etc...)
- list contents adding a trailing / at the end of directory names
- list contents with more details (long format including permissions, owner/group, sizes and last modification date/time)
- list contents including hidden files/directories (i.e. those with a name starting with a dot)
- list contents sorted by last-modification date/time (most recent to most ancient)
- list in reverse order (e.g. useful in combination with -t)

Q: mk dir [dir ...]
A: Create new (empty) directory (several directory names may be specified)

Q: touch [file ...]
A: For a file that does not exist, create an empty file with the given name, otherwise, update last-modification date/time of the existing file (several filenames may be specified)

Q: cp [source ...] dest
cp -r [source ...] dest
A: - Copy source to dest (source must be an existing file [not a directory], dest can be a new filename or an existing directory; several source files may be specified)
- Copy source to dest (source may now be a directory, dest can be a new file/directory name or an existing directory; several source files/directories may be specified)

Q: mv [source ...] dest
A: Move source to dest (source must be an existing file/directory, dest can be a new file/directory name or an existing directory; several source files/directories may be specified)

Q: rm [target ...]
rmdir [target ...]
rm -r [target ...]
A: - Delete target (target must be an existing file [not a directory], several target files may be specified)
- Delete target (target must be an empty directory, several target directories may be specified)
- Delete target recursively (target must be an existing file/directory, non-empty directories are deleted with their entire content; several target files/directories may be specified)

Q: chmod perm file/dir
A: Change the permissions of the file/directory according to perm.
--> to change permissions use the command chmod UGO file_name where UGO is the three-digit octal string determining the permissions (U: user; G: group; O: other), each digit in the range 0-7
--> octal digit
0  = none
1  = execute (x)
2  = write (w)
3  = write+execute (wx)
4 = read (r)
5 = read+execute (rx)
6 = read+write (rw)
7 = read+write+execute (rwx)
TRICK:
Start from 0
Add 4 for «read»
Add 2 for «write»
Add 1 for «execute»

Q: echo text
A: Print the given text to standard output (the text is generally surrounded by quotes)

Q: cat [file ...]
A: If no argument is given, copy standard input to standard output; if one file is given, print the file contents to standard output; if several files are given, print the file contents in sequence (concatenate) to standard output

Q: tee file
A: Copy the standard input to standard output as well as to the indicated file

Q: > file
< file
>> file
>& file
>>& file
A: - Redirect standard output to the file (overwriting the file if it already exists)
- Redirect standard input from the file (the file must exist)
- append standard ouptut at the rear of the file (creating the file if it does not exist)
- Redirect standard output and error to the file (overwriting the file if it already exists)
- Append standard output and error at the rear of the file (creating the file if it does not exist)

Q: | cmd
A: Redirect standard output to the standard input of a following command cmd (pipe)

Q: man command
A: Display manual information (action, arguments, options, input, output) on the command

Q: which command
A: Print the absolute path of the file containing the command (or reports if it is a shell built-in command or an alias)

Q: alias
A: Print a list of all the commands that are aliases

Q: diff file1 file2
A: Print line-by-line differences between file1 and file2, and the lines where the differences occur

Q: paste file1 file2
A: Assemble file1 and file2 column-wise

Q: wc [file ...]
A: Count the number of lines, words and characters in the file (if no file given, process standard input)

Q: head -n num file
A: Print the first num lines of the file (if no file given, process standard input)

Q: tail -n num file
A: Print the last num lines of the file (if no file given, process standard input)

Q: grep pattern [file ...]
grep -i pattern [file ...]
grep -v pattern [file ...]
grep -n pattern [file ...]
grep -c pattern [file ...]
A: - Search and print the filename and the lines matching the pattern (if no file given, process standard input)
- Make the search case-insensitive
- Search for the lines that do not match the pattern
- Also print the line numbers matching the pattern
- Also print the number of lines matching the pattern

Q: sort [file ...]
A: Sort alphabetically the contents of the file (if no file given, process standard input)

Q: uniq [file ...]
A: Remove all adjacent repeats of a given line in a text file (if no file given, process standard input)

Q: sed script [file ...]
A: Perform line-by-line modifications defined by the script (e.g. text replacements) in the text file (if no file given, process standard input)

Q: awk script [file ...]
A: Perform line-by-line modifications defined by the script (e.g. column changes) in the text file (if no file given, process standard input)

Q: more file
A: Print the contents of the file one page at a time (press <q> to quit; if no file given, process standard input)

Q: less file
A: Print the contents of the file one page at a time, more fancy version (press <q> to quit; if no file given, process standard input)

Q: <ctr> c
A: Interrupts ongoing process immediately

Q: ~
A: Home directory

Q: UNIX syntax
A: command [-options] [object1] [object2] ...

Q: ?
A: Wildcard: Stands for any single character

Q: *
A: Wildcard: matches any sequence of characters

Q: Special characters in UNIX not allowed in file/directory names
A: $ [ ] ! | ' " & * ? ( ) < >

Q: chgrp
A: Permits to change the group of a file/directory so that it belongs to another group

Q: chown
A: Permits to change the owner of a file/directory so it belongs to another owner

Q: added & at end of command line
A: The first command will be run in the background

Q: jobs
A: Check background jobs

Q: sleep number
A: Just tells the computer to wait number seconds

Q: ssh
A: Access another computer from your current machine

Q: gedit
A: Open the text editor program gedit

Q: xmgrace
A: Open graphic visualisation program xmgrace

Q: evince
A: Document viewer will work for pdf and ps

Q: [-options]
A: Square brackets mean option or argument in UNIX commands --> options are preceded by a minus sign; the arguments define objects relevant to the command; most commands use defaults when no arguments are specified

Q: ; (UNIX)
A: Allows in UNIX to give multiple commands in one line, separated by a semicolon

Q: Absolute path
A: Referencing a file/directory from the root

Q: Relative path
A: Referencing a file/directory from the current (working directory)

Q: Root directory
A: The top directory of the system

Q: Current directory
A: The one you are in currently

Q: Home directory
A: The highest directory for you as a user

Q: A child directory
A: One down form your current directory

Q: The parent directory
A: The one up from your current directory

Q: .txt
A: Text file extension

Q: .cc
A: C++ source code file extension

Q: .o
A: Compiled object file entension

Q: .dat
A: Data file extension

Q: [ABC]
A: Wildcard: any character from the list

Q: [A-Z]
A: Wildcard: any character in range

Q: Directory access permissions
A: - read: read the name of the files in the directory (but if alone, no additional information)
- write: right to modify entries in the directory (creating files, deleting files, renaming files)
- execute: right to access file contents and metainfo (but alone, not to list the directory)

Q: PID
A: process identification number --> each UNIX process has one

Q: UID
A: User identification number --> each UNIX process has one

Q: kill PID
kill -9 PID
A: - Interrupt the execution of any process (including the ones running in the background)
- kill "mercilessly"

Q: script
A: A succession of UNIX commands in a file, that can be run as a single command

Q: bc
A: For conversion between number systems

Q: xxd
A: To convert char into ascii(hex)