Linux Intro in DM500¶
Material for the first hour¶
pwd: print stien til den nuværende mappe (“print working directory”). Hvor står vi henne i vores filsystem?ls: list de elementer (mapper, filer) der er i den nuværende mappe.cd: navigér rundt i filsystemet. Prøv at find hen til din mappe med Java-programmer fra DM550.cp: lav en kopi af en fil eller mappe. Prøv at lav en kopi af DM550 mappen, som du kan rode rundt i med resten af kommandoerne.touch: lav en fil.rm: fjern en fil (eller mappe).mkdir: lav en ny mappermdir: fjern en tom mappe.mv: flyt/omdøb en fil eller mappe.man: læs dokumentation for de forskellige kommandoer.grep: sørg efter ting i filer. Prøv at køregrep -n public SomeClass.javamed en af dine Java-filer i stedet forSomeClass.java.find: find filer eller mapper i dit filsystem. Prøv at kørefind . -iname "*.java"i din DM550-mappe.wc: tæl antal tegn, ord og linjer i filer.
Material from the second hour¶
Additional material:
Unix Pipeline (Brian Kernighan), Computerphile on Youtube.
Standard streams, Wikipedia.
Pipeline (Unix), Wikipedia.
Examples Commands¶
How do I find out what a command does (e.g., ls)?:
man ls
How many lines of code in a file?:
wc -l code.java
Where did I put my Java code?:
find . -iname "*.java"
How many Java files do I have?:
find . -iname "*.java" | wc -l
How many lines of code in each file?:
find . -iname "*.java" | xargs wc -l
in sorted order?:
find . -iname "*.java" | xargs wc -l | sort -n
and without the total count:
find . -iname "*.java" | xargs wc -l | sort -n | head -n -1
or maybe just the total:
find . -iname "*.java" | xargs wc -l | sort -n | tail -n 1
Search for a string in all files:
grep -Rn "^class "
How many matches?:
grep -Rn "^class " | wc -l
Download a webpage, and just print the raw HTML to the terminal:
wget -O - http://dr.dk
Find all lines in the page with links:
wget -O - http://dr.dk | grep http
Extract just the link from the line:
wget -O - http://dr.dk | grep http | sed "s/^.*http/http/" | sed "s/\".*//" | sed "s/\?.*//"
Sort the links, and filter out duplicates:
wget -O - http://dr.dk | grep http | sed "s/^.*http/http/" | sed "s/\".*//" | sed "s/\?.*//" | sort | uniq
Filter out those linking to the same domain:
wget -O - http://dr.dk | grep http | sed "s/^.*http/http/" | sed "s/\".*//" | sed "s/\?.*//" | sort | uniq | grep -v "www.dr.dk"
Someone in my group changed something in a file, but what?:
diff -u original.java changed.java