Skip to content

Command-Line

Terminal window
.
:: means the current directory, often used to move or copy files to the current directory
ex: $ cp ~/foo.txt . (kopiere die Datei foo.txt, die im Home-Directory liegt, ins aktuelle Directory)
<cmd> <option> <argument(s)> \
:: backslash, line continuation, line break in the command line
ex: $ echo "Hello this is a really long sentence, \
> therefore we need a line break"
cat <file_01> <file_02>
:: dumps the content of a file to the screen (stdout), quick & dirty
:: can be used to combine the contents of multiple files (short for "concatenate")
ex: $ cat hello.txt
cd <dir>
:: change to <dir> (supports tabcompletion)
ex: $ cd foo/
cd ~/<dir>
:: change to a directory via the home-directory
ex: $ cd ~/foo/
cd ~ || cd
:: change to the users home-directory
cd -
:: change to the previous directory
cd ..
:: moves one directory up
cp <file_old> <file_new>
:: copy, copies the content of <file_old> into <file_new>
ex: cp foo bar
cp <file_1> <file_2> <dir>/
:: copies <file_1> and <file_2> into <dir> (mehrere Quellen, ein Ziel)
cp * <dir>/
:: copies all files in the working directory into <dir>
cp m* .txt <dir>/
:: copies all text files starting with "m" into <dir>
cp -r /<dir_old> <dir_new>
:: r -> recursively
:: copies recursively directories and their contents
ex: $ cp -r ~/foo .
tbc
echo <string>
:: prints string to screen (stdout)
ex: $ echo hello
Terminal window
> redirect operator
:: redirects the standard output to a file (from left to right)
ex: $ echo foo > foo.txt
>> append operator
:: takes the stdout of the command on the left and appends (adds) it to the file on the right
ex: $ echo bar >> foo.txt
<
:: takes the stdin from the file on the right and inputs it into the program on the left. The stdout (content of file) appears in the programm (terminal)
ex: $ cat < foo.txt
!! bangbang
:: runs the previous command exactly as written
!<char>
:: runs the last command that started with that character
ex: !curl || $ !cu || $ !c
!<num>
:: executes the <num>th command in the command history
<cmd_1>|<cmd_2> pipe operator
:: takes the stdout of the command on the left and "pipes" it as stdin to the command on the right ("command to command" redirection)
ex: $ head foo | wc
Terminal window
[a-z]
:: any letter
*
:: zero or more
ex: ro[a-z]*s -> matches "ro" and "s" with zero or more letters in between
.
:: any character
ex: .* -> matches "any character", zero or more of them