BeginnerLesson 1 of 15
Terminal, Navigation & Files – Bash
Change folders, create, copy, move, delete and read files.
The shell reads your commands and starts programs. A command consists of a program name, options (-l, --help) and arguments, separated by spaces. You are always in a "current directory". ~ is your home folder, . the current one, .. the parent folder.
pwd # where am I?
ls # show contents
ls -la # long format, incl. hidden files (.name)
cd projekte # change into a subfolder
cd .. # go up one level
cd ~ # go to the home directory (also: just "cd")
cd - # back to the previous folderCreate, copy, move (also: rename) and delete files and folders:
mkdir -p daten/2024/mai # folder including intermediate folders
touch notiz.txt # create an empty file (or refresh the timestamp)
cp notiz.txt kopie.txt # copy
cp -r daten daten_backup # copy a folder recursively
mv kopie.txt daten/ # move
mv notiz.txt idee.txt # rename = move to a new name
rm idee.txt # delete (no recycle bin!)
rm -r daten_backup # delete a folder including its contentsViewing files: cat prints everything, head/tail show the beginning/end, less pages through (quit with q), wc -l counts lines. tail -f follows a growing log file.
cat notiz.txt
head -n 3 server.log # first 3 lines
tail -n 3 server.log # last 3 lines
tail -f server.log # follow live (Ctrl+C stops)
wc -l server.log # line count
man ls # manual; or: ls --helpWarning
rm does not ask and has no recycle bin. rm -rf with a wrong or empty variable (rm -rf "$DIR/" with an empty DIR) has destroyed entire systems. Check paths beforehand with ls or echo.TipTab completes names, Up arrow recalls earlier commands, Ctrl+R searches the history, Ctrl+C cancels,
!! repeats the last command (sudo !!).