




Studia grazie alle numerose risorse presenti su Docsity
Guadagna punti aiutando altri studenti oppure acquistali con un piano Premium
Questa pagina non è visibile nell’anteprima
Non perderti parti importanti!





Bash Commands man o Shows manual for a command. sudo o Execute a command as the superuser. File System Navigation cd o Change current working directory. ls [] [] o List the contents of a directory (current working directory by default). o Options: -l: use a long listing format. -a, --all: do not ignore entries starting with “.” -r, --reverse: reverse order while sorting -R, --recursive: list subdirectories recursively pwd o Print name of the current working directory. File System Manipulation mkdir o Create a new directory, if it does not already exist.. rmdir o Remove a directory, if it is empty. mv o Move (rename) the file to . rm [] o Remove a file. o Options: -R: remove directories and their contents recursively. cp [] o Copy the file to . o Options: -R: copy directories and their contents recursively. ln [] o Create an hard link to file in . o Options: -s: make symbolic links instead of hard links. Process Management ps [] o List active processes.
o Options: -e: list all processes. -l: use a more detailed listing format. top o Show a a dynamic real-time view of running processes. kill - o Send the signal to the process specified by . o Signals: -9: terminate a process. & o Execute command in background. File Operations cat o Print file on the standard output. more / less o Print file on the standard output page by page. sort [] o Sort lines of text files (alphabetically by default). o Options: -r: reverse order. -n: use numerical order. -k : sort via key. cut [] o Remove sections from each line of a text file. o Options: -f : specify fields to select. -d : use instead of TAB for field delimiter. tr [] [] o Translate standard input characters from to . o Options: -d: delete characters from instead of translating them. uniq [] o Omit repeated lines. o Options: -d: report only repeated lines instead of omitting them. grep [] o Print lines of a file matching a pattern. o Options: -e : specify a pattern to be matched.
o Options: -R: change permissions of files and directories recursively. String manipulation basename path o Strip directory and suffix from path. dirname path o Strip last component from path. Redirections cmd1 | cmd o Redirect standard output of cmd1 to standard input of cmd2. cmd < file o Redirect standard input of cmd from file. cmd > file o Redirect standard output of cmd to file. cmd 2> file o Redirect standard error of cmd to file. cmd &> file o Redirect standard output and standard error of cmd to file. cmd >> file o Append standard output of cmd to file. Shortcuts CTRL+C o Terminate the current foreground process. CTRL+Z o Stop the current foreground process. TAB o Autocompletion.
The Pthread Library int pthread_equal (pthread_t tid1, pthread_t tid2); pthread_t pthread_self (void); int pthread_create (pthread_t *tid, const pthread_attr_t *attr, void (startRoutine)(void *), void *arg); void pthread_exit (void *valuePtr); int pthread_join (pthread_t tid, void **valuePtr); int pthread_cancel (pthread_t tid); int pthread_detach (pthread_t tid); Semaphore POSIX int sem_init (sem_t *sem, int pshared, unsigned int value); int sem_wait (sem_t *sem); int sem_trywait (sem_t *sem); int sem_post (sem_t *sem); int sem_getvalue (sem_t *sem, int *valP); int sem_destroy (sem_t *sem); Mutex POSIX int pthread_mutex_init (pthread_mutex_t *mutex, const pthread_mutexattr_t *attr); int pthread_mutex_lock (pthread_mutex_t *mutex); int pthread_mutex_trylock (pthread_mutex_t *mutex); int pthread_mutex_unlock (pthread_mutex_t *mutex); int pthread_mutex_destroy (pthread_mutex_t *mutex);
Execution of arithmetic computations a method chosen by the student Ex. o let s=$n1+$n o Assign to the variable $s the sum of $n1 and $n Special shell variables $0, $1, $2, ... o passing parameters on the command line $* o complete list of parameters, excluding the name of the script $# o number of parameters $$ o PID of the process $? o returned value of the last executed process Construct if-then-else (and elsif) if condition ; then statements elif condition then statements else statements fi Construct while (including the redirection of stdin and stdout) while condition do statements done << $fileIn >> $fileOut Required formats for the condition of the constructs if and while Only the conditions expressed between [ ... ] are required (instead, the conditions based on the keyword test are not required) Numerical comparisons: o -eq equal (==) o -ne not equal (!=) o -gt major (grater) (>) o -ge major or equal (greater equal) (>=) o -lt minor (less) (<) o -le minor or equal (less equal) (>) Strings comparisons: o = equal o != not equal
Conditions on files: o -d true if is a directory o -f true if is a file o -r true if has read permission o -w true if has write permission o -x true if has execution permission Logical operators usable within a condition: o! not o -a and o -o or Logical operators usable in a list of conditions: o && and o || or Costrutto for for var in [ list ] do statements done Instructions break continue Vectors
array[3]="value" array=( 4 8 7 ) array=( [0]=4 [1]=8 [2]=7 [5]=10 )
echo ${array[1]} # Access to the element 1 of the vector (value 8) echo ${array[]} # Print of all the elements of the array echo ${!array[]} # Print of all the keys of the array echo ${#array[*]} # Number of elements contained in the array Associative vector
declare -A array array[“key”]=”value” array=( [pippo]=hello [2]="pluto" ["pluto"]=2 )
echo ${array[pippo]} # Access to the element “pippo” of the array (value “hello”) echo ${array[]} # Print of all the elements of the array echo ${!array[]} # Print of all the keys of the array echo ${#array[*]} # Number of elements contained in the array