GNU/LinuxGeneric Mapping Tools (GMT)Python - LMU

Transcription

GNU/LinuxGeneric Mapping Tools (GMT)PythonLinux PrimerJens OeserGeophysicsDepartment of Earth and Environmental ScienceLudwig-Maximilians-Universität München1. März 2018Jens OeserLinux Primer1/99

GNU/LinuxGeneric Mapping Tools (GMT)PythonUnix and GNU/Linux term Unix (Plural: Unices) is used for all operating systems that arebased on the original Unix-Draft (AT&T) today influences from Unix can be found in almost all modernoperating systems it’s ideas and concepts can be found everywhere GNU/Linux and the free BSD-systems re-implement Unix’s behaviorand interfaces and add own extensions when talking about the operating system in a strict sense one wouldhave to talk about GNU/Linux“ as this includes the kernel (Linux)”as well as the system toolsJens OeserLinux Primer2/99

GNU/LinuxGeneric Mapping Tools (GMT)PythonLiterature Linux in a Nutshell Advanced Bash-Scripting Guide LRZ – Hochschulschriften LRZ – Kursprogramm zu Unix und GNU/Linux Google Search Codename: Linux (2001)Jens OeserLinux Primer3/99

GNU/LinuxGeneric Mapping Tools (GMT)PythonProperties of GNU/Linux GNU/Linux consists of a kernelI only the kernel controls devices and processesI provides system calls as interface for the programsI a variety of programs complete the operating system file system is organized hierarchically with arbitrary subdirectoriesI inverse tree structureI/“ is the root directory”Jens OeserLinux Primer4/99

GNU/LinuxJens OeserGeneric Mapping Tools (GMT)Linux PrimerPython5/99

GNU/LinuxGeneric Mapping Tools (GMT)Python a basic principle in GNU/Linux and UnixIEverything is a file!“”I this generalized file concept is inherently includedI easy and consistent interface for the different applicationsI exceptionally easy input/output redirecting into these filesI linking of several programs via these pipes all Unix-like operating systems have a graphical user interface (X11) historically Unix is closely linked to the programming language CJens OeserLinux Primer6/99

GNU/LinuxGeneric Mapping Tools (GMT)Python among the most important properties of GNU/Linux areI high stabilityI multiuserI multitaskingI multithreadingI memory protectionI virtual memoryI TCP/IP network supportI fully developed shellI vast variety of programs for almost any taskI outstanding scripting possibilitiesJens OeserLinux Primer7/99

GNU/LinuxGeneric Mapping Tools (GMT)PythonUsing a GNU/Linux system – access user account usually consists of user name, password and additionalinformation authentification by user name and password authorization afterwards, using the additional information logging on and off is possible via a graphical user interface or a textshellJens OeserLinux Primer8/99

GNU/LinuxGeneric Mapping Tools (GMT)PythonUsing a GNU/Linux system – user groups classification of users enables detailed permission management for every user, the GNU/Linux world is divided into three classesI u login userI g groupI o others all users are identified via a UID (user identification number), that isdirectly mapped to the user name users have one or more additional GID (group identification number)to determine the groups he/she is associated with (permissionclassification together with other members of the group) all users that are not part of this group are considered others for u, g and o, read, write and execute permissions can be set; theyare stored as file attributesJens OeserLinux Primer9/99

GNU/LinuxGeneric Mapping Tools (GMT)PythonUsing a GNU/Linux system – command syntax apart from very few exeptions a GNU/Linux command has the syntax# COMMAND -OPTION PARAMETER introduction into the most important commands will be covered inthe next chapter options influence the execution of a commandIIshort form for options -along form for options --all parameters are mostly filenamesJens OeserLinux Primer10/99

GNU/LinuxGeneric Mapping Tools (GMT)PythonUsing a GNU/Linux system – documentation every system has built-in documentation/help# man COMMAND each man page is separated into individual subsectionsI NAME – name of the commandI SYNOPSIS – syntax descriptionI DESCRIPTION – detailed description of the commandI OPTIONS – list of all options with a short descriptionI COMMANDS – instructions for interactive programsI FILES – files that are associated with the commandI SEE ALSO – references to similar commands and manual entriesI EXAMPLE – examples for calling the commandI BUGS – known bugs and issues the commands info and apropos give additional informationJens OeserLinux Primer11/99

GNU/LinuxGeneric Mapping Tools (GMT)PythonUsing a GNU/Linux system – usage of the system in today’s window world“ the command line seems complicated”I all user tasks can be performed without the command lineI higher comfort comes with less driving fun GNU/Linux systems are like building setsI a set of programs is availableI they can be combined for different tasks it’s not always necessary to use bloated programs if it is possible tosmartly combine the small, specialized programsJens OeserLinux Primer12/99

GNU/LinuxGeneric Mapping Tools (GMT)Python Terminal (Shell)I accepts commandsI processes themI starts programsI outputs the result input of commands according to the forementioned syntaxI the way you input a command is not only determined by the syntax ofthe command you call, but also by the syntax of the shell used withinthe terminalI before execution, the command is parsed (set of changes to the input)I these changes have nothing to do with the command that has beencalled, but are done by the shell applying an always identical set ofsyntactic rules (many simplifications possible at command input)Jens OeserLinux Primer13/99

GNU/LinuxGeneric Mapping Tools (GMT)PythonUsing a GNU/Linux system – files from the user’s point of view, a file is always a series of logicallyconnected information from the system’s point of view there is only a finite series of bytes in GNU/Linux, there are the following important types of filesI regular file file containing data, text or a programI file folder file containing references to other filesI device file file containing a reference to a physical deviceI pipe file for system internal process communicationJens OeserLinux Primer14/99

GNU/LinuxGeneric Mapping Tools (GMT)Python each user has one HOME directory“”# echo HOME during his/her session, each user has a working directory“”# echo PWD file access always via filenames filename can be chosen arbitrarilyIwith some constraints (name conventions) file can be addressed via its absolute or relative path one single file can be linked from different places in the directory tree andhave different namesJens OeserLinux Primer15/99

GNU/LinuxGeneric Mapping Tools (GMT)Python each file has a set of attributesI name of fileI path of fileI type of fileI UID and GID of ownerI access permissionsI length of fileI node numberI number of links, references to the fileI date of creation, last change and last access user can change the attributes editing of a set of files by wild cardsI ?exactly one arbitrary characterI *arbitrarily many charactersI [abc]exactly one of the given charactersI [a-d]a character from within the given rangeI [!abc]none of the given charactersJens OeserLinux Primer16/99

GNU/LinuxGeneric Mapping Tools (GMT)PythonWhat is a shell? a program with which the system can understand the users commands often called command interpreter (shell interpretes the command) successful login always starts the personal login shell currently active shell:gkd22aa@cip50: echo SHELLJens OeserLinux Primer17/99

GNU/LinuxGeneric Mapping Tools (GMT)PythonWhat kinds of shells are there? simple shells:I Bourne-Shell (sh)I Korn-Shell (ksh)I C-Shell (csh) extended shells:I Bourne-Again-Shell (bash)I T-C-Shell (tcsh)I Z-Shell (zsh)Jens OeserLinux Primer18/99

GNU/LinuxGeneric Mapping Tools (GMT)PythonHow can I switch between the different shells?gkd22aa@cip50: echo SHELL/bin/bashgkd22aa@cip50: tcshcip50: cip50: exitgkd22aa@cip50: ksh exitJens OeserLinux Primer19/99

GNU/LinuxGeneric Mapping Tools (GMT)PythonWhat is the prompt? prompt to enter a command depending on the shell the appearance of the prompt can be different changing the prompt using the variable PS1gkd22aa@cip50: lsDesktop maildirgkd22aa@cip50: echo PS1 {debian chroot: ( debian chroot)}\u@\h:\w\ gkd22aa@cip50: PS1 "abc123# "abc123# lsDesktop maildirabc123#Jens OeserLinux Primer20/99

GNU/LinuxGeneric Mapping Tools (GMT)PythonWhat is a variable? in the most general sense simply a container for values a variableI is addressed by a designated nameI has a certain location in the memoryI its value can change in the shells there is only one type of variables variables can be created and changed arbitrarily environment varibalesI are initialized at loginI influence the behavior of the shellI influence the commandsJens OeserLinux Primer21/99

GNU/LinuxGeneric Mapping Tools (GMT)PythonWhich environment variables have been initialized/set?gkd22aa@cip50: envTERM xtermSHELL /bin/bashUSER gkd22aaLOGNAME gkd22aaHOME /home/cip/gkd22aaPWD /home/cip/gkd22aaLANG en GB.UTF-8MAIL /var/mail/gkd22aaPATH /usr/local/bin:/usr/bin:/bin:/usr/gamesDISPLAY localhost:10.0Jens OeserLinux Primer22/99

GNU/LinuxGeneric Mapping Tools (GMT)PythonWhat types of programs are there? as you know, programs are started from the shell there are two different groups of programsI programs that are stored on the hard diskI programs that are programmed“ into the shell (shell builtin programs)” to obtain details about the typegkd22aa@cip50: type mkdirmkdir is /bin/mkdirgkd22aa@cip50: type echoecho is a shell builtingkd22aa@cip50: type lsls is aliased to ‘ls --color auto’Jens OeserLinux Primer23/99

GNU/LinuxGeneric Mapping Tools (GMT)Python obtaining the path of a commandgkd22aa@cip50: which echo/bin/echogkd22aa@cip50: which gnuplot/usr/bin/gnuplot just entering echo shell builtin variant entering /bin/echo program from respective path there might be a slightly different functionality depending on thevariantJens OeserLinux Primer24/99

GNU/LinuxGeneric Mapping Tools (GMT)PythonHow do you string commands together?Imagine you want to start five commands after each other, but each ofthem will take a certain, undetermined amount of time. Possibly you willhave to wait in front of the computer for hours and wait until each of thecommands is finished in order to start the next one. the shell can execute more than one instruction per command a command doesn’t end before the return key is pressed instructions can be separated by semicolonsgkd22aa@cip50: echo HOME; ls Desktop; date -R/home/cip/gkd22aaLinuxCourse.pdf Home.desktop System.desktopSun, 01 Nov 2009 16:00:42 0100Jens OeserLinux Primer25/99

GNU/LinuxGeneric Mapping Tools (GMT)Python continue only when successfulgkd22aa@cip50: dtae -R && ls HOME-bash: dtae: command not found continue only when unsuccessfulgkd22aa@cip50: dtae -R echo "Help, an error."-bash: dtae: command not foundHelp, an error.Jens OeserLinux Primer26/99

GNU/LinuxGeneric Mapping Tools (GMT)PythonMulti-Line-Commands often commands stretch over multiple lines current line can be continued in the next line with the backslashoperator (\)gkd22aa@cip50: find /usr/share/WindowMaker/ \ -type f -name lueImage.jpeggkd22aa@cip50: find /usr/share/WindowMaker/ \ -type f \ -name \ lueImage.jpegJens OeserLinux Primer27/99

GNU/LinuxGeneric Mapping Tools (GMT)PythonWorking with directories – paths the general form of a filename or of a directory name, specifies aunique location in a file system points to a file system location by following the directory treehierarchy expressed in a string of characters in which pathcomponents, separated by a the slash /, represent each directory GNU/Linux distinguishes between two kinds of paths:Iabsolute pathIIIIrelative pathIIJens Oeserpoints to the same location on one file system regardless of the workingdirectory or combined pathsusually written in reference to a root directoryabsolute path always starts with a slash /a path relative to the working directory of the user or application, sothe absolute path will not have to be givenalways starts with a subdirectory or ./Linux Primer28/99

GNU/LinuxGeneric Mapping Tools (GMT)Python working directorygkd22aa@cip50: echo PWD/home/cip/gkd22aagkd22aa@cip50: pwd/home/cip/gkd22aaJens OeserLinux Primer29/99

GNU/LinuxGeneric Mapping Tools (GMT)PythonChange directorycd [PATH] [PATH]I replaced with absolute or relative pathJens OeserLinux Primer30/99

GNU/LinuxGeneric Mapping Tools (GMT)PythonThe following characters have a special meaning for the shell: .Ipoints to the working directory .Ipoints to the directory one level above the working directoryIpoints to the last working directory points to your home directory HOMEI points to your home directoryIJens OeserLinux Primer31/99

GNU/LinuxGeneric Mapping Tools (GMT)Pythongkd22aa@cip50: cd .gkd22aa@cip50:/home/cip cd .gkd22aa@cip50:/home pwd/homegkd22aa@cip50:/home cd ./usr/bingkd22aa@cip50:/usr/bin pwd/usr/bingkd22aa@cip50:/usr/bin cd gkd22aa@cip50: cd /usr/bingkd22aa@cip50:/usr/bin pwd/usr/bingkd22aa@cip50:/usr/bin cd HOME/Desktopgkd22aa@cip50: /Desktop pwd/home/cip/gkd22aa/DesktopJens OeserLinux Primer32/99

GNU/LinuxGeneric Mapping Tools (GMT)PythonList directory contentsls [OPTION] [PATH] [PATH]I replaced with absolute or relative path [OPTION]I -aIJens OeserIdo not ignore entries starting with . (hidden files/directories)Iuse a long listing formatIreverse order while sortingIsort by modification time-lI-rI-tLinux Primer33/99

GNU/LinuxGeneric Mapping Tools (GMT)Pythongkd22aa@cip50: ls DesktopLinuxCourse.pdf Home.desktopgkd22aa@cip50: ls -a.Xauthority.bash logout.dmrc.kderc.mcopDesktopgkd22aa@cip50: ls -ldrwx------ 2 gkd22aa gkd22 4096 Oct 26 08:37 Desktopdrwx------ 2 gkd22aa gkd22 4096 Oct 19 11:50 maildirgkd22aa@cip50: ls -aldrwxr-xr-x15 gkd22aa gkd22 4096 Nov 2 08:04 .drwxr-xr-x 1759 rootroot 32768 Oct 29 16:26 .-rw------1 gkd22aa gkd2251 Nov 2 08:04 .Xauthoritydrwx-----3 gkd22aa gkd22 4096 Oct 26 08:36 .adobeJens OeserLinux Primer34/99

GNU/LinuxGeneric Mapping Tools (GMT)Pythongkd22aa@cip50: ls /adm boot chkpnt dev etclibmnt opt sbin sys usrbin cdrom datahome initrd media proc root srv tmp vargkd22aa@cip50: ls /usr/X11R6 bin games include lib lib64 local man sbin share srcgkd22aa@cip50: ls /usr/share/texmf-texlive/bibtex doc ls-R makeindex texgkd22aa@cip50: ls -l /usr/share/texmf-texlive/drwxr-xr-x 4 root root 4096 Feb 25 2008 bibtexlrwxrwxrwx 1 root root18 Feb 25 2008 doc - ./doc/texlive-dolrwxrwxrwx 1 root root27 Feb 25 2008 ls-R - /var/lib/texmf/ldrwxr-xr-x 4 root root 4096 Feb 25 2008 makeindexdrwxr-xr-x 4 root root 4096 Feb 25 2008 texJens OeserLinux Primer35/99

GNU/LinuxGeneric Mapping Tools (GMT)Pythongkd22aa@cip50: touch fileB && sleep 30 && touch fileA \&& sleep 30 && touch fileCgkd22aa@cip50: ls -l file?-rw------- 1 gkd22aa gkd22 0 Feb 16 16:30 fileA-rw------- 1 gkd22aa gkd22 0 Feb 16 16:29 fileB-rw------- 1 gkd22aa gkd22 0 Feb 16 16:30 fileCgkd22aa@cip50: ls -lt file?-rw------- 1 gkd22aa gkd22 0 Feb 16 16:30 fileC-rw------- 1 gkd22aa gkd22 0 Feb 16 16:30 fileA-rw------- 1 gkd22aa gkd22 0 Feb 16 16:29 fileBgkd22aa@cip50: ls -ltr file?-rw------- 1 gkd22aa gkd22 0 Feb 16 16:29 fileB-rw------- 1 gkd22aa gkd22 0 Feb 16 16:30 fileA-rw------- 1 gkd22aa gkd22 0 Feb 16 16:30 fileCJens OeserLinux Primer36/99

GNU/LinuxGeneric Mapping Tools (GMT)Python Is it a absolute or relative path? To which location does it point c/defaultJens OeserLinux Primer37/99

GNU/LinuxGeneric Mapping Tools (GMT)PythonSome basic commandsecho [TEXT] [TEXT]I output is written to terminalI please put ”.” aroundgkd22aa@cip50: echo " text output from USER "text output from gkd22aaJens OeserLinux Primer38/99

GNU/LinuxGeneric Mapping Tools (GMT)Pythonsleep [SECONDS] [SECONDS]I shell sleeps for the specified numbers of secondsgkd22aa@cip50: date ; sleep 30 ; dateFri Nov 6 13:43:51 CET 2009Fri Nov 6 13:44:21 CET 2009gkd22aa@cip50: Jens OeserLinux Primer39/99

GNU/LinuxGeneric Mapping Tools (GMT)Pythoncat [FILE]tac [FILE] [FILE]I concatenate files and print on the standard outputI concatenate files and print on the standard output in reverse ordergkd22aa@cip50: cat /etc/ntp.conf .dmrclogfile /var/log/ntpddriftfile /var/lib/ntp/ntp.drift#broadcastclient yesserver 129.187.254.32server 10.156.8.31[Desktop]Session defaultJens OeserLinux Primer40/99

GNU/LinuxGeneric Mapping Tools (GMT)PythonMake directoriesmkdir [PATH] [PATH]I replaced with absolute or relative pathgkd22aa@cip50: lsDesktopgkd22aa@cip50: mkdir dirA ; lsDesktop dirAgkd22aa@cip50: mkdir HOME/dirBgkd22aa@cip50: mkdir /home/cip/ USER/dirCgkd22aa@cip50: lsDesktop dirA dirB dirCJens OeserLinux Primer41/99

GNU/LinuxGeneric Mapping Tools (GMT)PythonRemove empty directoriesrmdir [PATH] [PATH]I replaced with absolute or relative pathI directories must be emptygkd22aa@cip50: lsDesktop dirA dirB dirCgkd22aa@cip50: rmdir dirA dir[BC]gkd22aa@cip50: lsDesktopgkd22aa@cip50: rmdir Desktop/rmdir: Desktop/: Directory not emptyJens OeserLinux Primer42/99

GNU/LinuxGeneric Mapping Tools (GMT)PythonCopy files and directoriescp [OPTION] SOURCE DEST [OPTION]I -aIIIIJens OeserIpreserve all file/diretory attributesImake a backup of each existing destination fileIprompt before overwriteIcopy directories recursivelyIcopy only when the SOURCE file is newer than the destination file orwhen the destination file is missing-b-i-r-uLinux Primer43/99

GNU/LinuxGeneric Mapping Tools (GMT)Python SOURCE DESTI replaced withIIIfilename orabsolute orrelative pathgkd22aa@cip50: cp .bashrc newFilegkd22aa@cip50: lsDesktop maildir newFilegkd22aa@cip50: mkdir TESTgkd22aa@cip50: cp /etc/profile \/usr/share/doc/bash/README.abs-guide TEST/gkd22aa@cip50: ls -l TEST/-rw------- 1 gkd22aa gkd22 1105 Nov 8 15:33 README.abs-guide-rw------- 1 gkd22aa gkd22 486 Nov 8 15:33 profileJens OeserLinux Primer44/99

GNU/LinuxGeneric Mapping Tools (GMT)gkd22aa@cip50: cp -i /etc/profile \/usr/share/doc/bash/README.abs-guide TEST/cp: overwrite ‘TEST/profile’? ycp: overwrite ‘TEST/README.abs-guide’? ygkd22aa@cip50: ls -l TEST/-rw------- 1 gkd22aa gkd22 1105 Nov 8 15:34-rw------- 1 gkd22aa gkd22 486 Nov 8 15:34gkd22aa@cip50: cp -b /etc/profile \/usr/share/doc/bash/README.abs-guide TEST/cp: overwrite ‘TEST/profile’? ycp: overwrite ‘TEST/README.abs-guide’? ygkd22aa@cip50: ls -l TEST/-rw------- 1 gkd22aa gkd22 1105 Nov 8 15:36-rw------- 1 gkd22aa gkd22 1105 Nov 8 15:34-rw------- 1 gkd22aa gkd22 486 Nov 8 15:36-rw------- 1 gkd22aa gkd22 486 Nov 8 15:34Jens OeserLinux eREADME.abs-guide profileprofile 45/99

GNU/LinuxGeneric Mapping Tools (GMT)Pythongkd22aa@cip50: cp -r TEST testgkd22aa@cip50: lsDesktop TEST maildir testgkd22aa@cip50: ls -l TEST testTEST/:-rw------- 1 gkd22aa gkd22 1105 Nov-rw------- 1 gkd22aa gkd22 1105 Nov-rw------- 1 gkd22aa gkd22 486 Nov-rw------- 1 gkd22aa gkd22 486 abs-guide profileprofile 3815:3815:3815:38README.abs-guideREADME.abs-guide profileprofile Jens Oeser1111gkd22aagkd22aagkd22aagkd22aagkd22 1105 Novgkd22 1105 Novgkd22 486 Novgkd22 486 NovLinux Primer46/99

GNU/LinuxGeneric Mapping Tools (GMT)PythonMove or rename files or directoriesmv [OPTION] SOURCE DEST [OPTION]I -bIIImake a backup of each existing destination fileIprompt before overwriteImove only when the SOURCE file is newer than the destination file orwhen the destination file is missing-i-u SOURCE DESTI replaced withIIIJens Oeserfilename orabsolute orrelative pathLinux Primer47/99

GNU/LinuxGeneric Mapping Tools (GMT)Pythongkd22aa@cip50: cd test/gkd22aa@cip50: /test lsREADME.abs-guide README.abs-guide profile profile gkd22aa@cip50: /test mv profile Data-1.txtgkd22aa@cip50: /test lsData-1.txt README.abs-guide README.abs-guide profile gkd22aa@cip50: /test cd .gkd22aa@cip50: mv test/ trygkd22aa@cip50: lsDesktop TEST maildir trygkd22aa@cip50: mv TEST/ try/gkd22aa@cip50: ls try/Data-1.txt README.abs-guide README.abs-guide TEST profile Jens OeserLinux Primer48/99

GNU/LinuxGeneric Mapping Tools (GMT)PythonRemove files or directoriesrm [OPTION] FILE [OPTION]I -iI-rI-fIprompt before every removalIremove directories and their contents recursivelyIignore nonexistent files, never prompt! FILEI replaced withIIIJens Oeserfilename orabsolute orrelative pathLinux Primer49/99

GNU/LinuxGeneric Mapping Tools (GMT)Pythongkd22aa@cip50: rm try/Data-1.txtrm: remove regular file ‘try/Data-1.txt’? ygkd22aa@cip50: ls try/README.abs-guide README.abs-guide TEST profile gkd22aa@cip50: rm -r try/TEST/rm: descend into directory ‘try/TEST/’? yrm: remove regular file ‘try/TEST/profile’? yrm: remove regular file ‘try/TEST/README.abs-guide ’? yrm: remove regular file ‘try/TEST/profile ’? yrm: remove regular file ‘try/TEST/README.abs-guide’? yrm: remove directory ‘try/TEST/’? ygkd22aa@cip50: ls try/README.abs-guide README.abs-guide profile gkd22aa@cip50: rm -rf try/gkd22aa@cip50: lsDesktop maildirJens OeserLinux Primer50/99

GNU/LinuxGeneric Mapping Tools (GMT)PythonMake links between filesln [OPTION] SOURCE LINK NAME [OPTION]I -sImake symbolic links instead of hard linksgkd22aa@cip50: ln -s maildir/ E-MAILgkd22aa@cip50: ln -s /etc/profile HOME/gkd22aa@cip50: ls -l && rm -f E-MAIL profiledrwx------ 2 gkd22aa gkd22 4096 Nov 8 15:27 Desktoplrwxrwxrwx 1 gkd22aa gkd228 Nov 8 16:14 E-MAIL - maildir/drwx------ 2 gkd22aa gkd22 4096 Oct 19 11:50 maildirlrwxrwxrwx 1 gkd22aa gkd2212 Nov 8 16:14 profile - /etc/profJens OeserLinux Primer51/99

GNU/LinuxGeneric Mapping Tools (GMT)PythonCommands for files and directoriestouch FILE change file timestamps or create empty filegkd22aa@cip50: ls -l .bashrc ; echo "###" ; \sleep 80 ; echo "###" ; \touch .bashrc ; ls -l .bashrc-rw------- 1 gkd22aa gkd22 2278 Nov 8 16:22 .bashrc######-rw------- 1 gkd22aa gkd22 2278 Nov 8 16:24 .bashrcJens OeserLinux Primer52/99

GNU/LinuxGeneric Mapping Tools (GMT)Pythonwc [OPTION] FILE print newline, word, and byte counts for each file [OPTION]I -cI-wI-lIprint the byte countsIprint the word countsIprint the newline countsgkd22aa@cip50: wc /etc/hosts39 104 /etc/hostsgkd22aa@cip50: cat /etc/host* /etc/profile wc -l64Jens OeserLinux Primer53/99

GNU/LinuxGeneric Mapping Tools (GMT)Pythonless [OPTION] FILE file viewer [OPTION]I -NIIcauses a line number to be displayed at the beginning of each line inthe displayIcauses less to automatically exit the first time it reaches end-of-file-E NavigationI to move in less – arrow keysI to quit less – qI to search in less – /[PATTERN]Jens OeserLinux Primer54/99

GNU/LinuxGeneric Mapping Tools (GMT)Pythongkd22aa@cip50: less -N /etc/bash.bashrc1 # System-wide .bashrc file for interactive bash(1) shells.23 # To enable the settings / commands in this file for login4 # this file has to be sourced in /etc/profile.5.gkd22aa@cip50: cat /etc/default/* less# Specify options for acpid startup, Debian default is to enable# use of sockets at a non-default positionOPTIONS s /var/run/acpid.socket"# Specify modules to load on acpid’s startup# MODULES may be uncommented to load "none", contain the string# to load all acpi related modules or simply a space seperated.Jens OeserLinux Primer55/99

GNU/LinuxGeneric Mapping Tools (GMT)Pythonhead [OPTION] [FILE]tail [OPTION] [FILE] output the first part or last part of files [OPTION]I -n iIIprint the first or last i lines instead of the first or last 10Ionly appropriable for tailcommand leaves [FILE] openedoutput appended data as the file growsto quit – STRG-C-fIIIJens OeserLinux Primer56/99

GNU/LinuxGeneric Mapping Tools (GMT)Pythongkd22aa@cip50: head -n 7 /etc/profile# /etc/profile: system-wide .profile file for the Bourne shell# and Bourne compatible shells (bash(1), ksh(1), ash(1), .).if [ "id -u‘" -eq 0 ]; thenPATH :/sbin:/elsePATH ip50: tail -n 4 -f /var/log/mail.logNov 13 04:11:24 cip50 postfix/cleanup[7544]: BEE3574477: messageNov 13 04:11:24 cip50 postfix/qmgr[3158]: BEE3574477: from root@Nov 13 04:11:24 cip50 postfix/smtp[7550]: BEE3574477: to spann@cNov 13 04:11:24 cip50 postfix/qmgr[3158]: BEE3574477: removed.gkd22aa@cip50: head -n 1 tomo.0?[05].dat.Jens OeserLinux Primer57/99

GNU/LinuxGeneric Mapping Tools (GMT)Pythonsort [OPTION] [FILE] sort lines of text files [OPTION]I -nIIcompare according to string numerical valueIoutput only the first of an equal run-ugkd22aa@cip50: sort /etc/hosts10.153.84.129libby.cipmath.loc libby cip0410.153.84.179 cip50.cipmath.loc cip50127.0.0.1 localhostJens OeserLinux Primer58/99

GNU/LinuxGeneric Mapping Tools (GMT)Pythongkd22aa@cip50: wget \http://www.geophysik.uni-muenchen.de/ oeser/LV/Shell/sort ex.txtgkd22aa@cip50: cat sort ex.txt.gkd22aa@cip50: sort sort ex.txt.gkd22aa@cip50: sort -u sort ex.txt000 IP001 ICMP002 IGMP003 GGP006 TCP012 PUP017 UDP022 IDP.Jens OeserLinux Primer59/99

GNU/LinuxGeneric Mapping Tools (GMT)PythonSearch for files in a directory hierarchyfind [OPTION] [PATH] [TEST] [ACTION] [OPTION]I -PIInever follow symbolic linksIfollow symbolic links-L [PATH]I replaced withIIabsolute orrelative path [TEST]I -amin/atime [n]IJens Oeserfile was last accessed [n]*24 hours agoLinux Primer60/99

GNU/LinuxGeneric Mapping Tools (GMT)Python [TEST]I -cmin/ctime [n]IIIfile is empty and is either a regular file or a directoryI-gid [n]I-group [NAME]IIIIfile belongs to group gname [NAME]file’s data was last modified [n]*24 hours ago-name [NAME]IIfile’s numeric group ID is [n]-mmin/mtime [n]Ibase of file name (the path with the leading directories removed)matches shell pattern [NAME]-perm [MODE]IJens Oeserfile’s status was last changed [n]*24 hours ago-emptyany of the permission bits [MODE] are set for the fileLinux Primer61/99

GNU/LinuxGeneric Mapping Tools (GMT)Python [TEST]I -size [n][cwbkMG]IIIIfile is of type [TYPE] (b (block special), c (character special), d(directory), p (named pipe (FIFO)), f (regular file), l (symbolic link)and s (socket))-uid [UID]Ifile’s numeric user ID is UIDI-user [NAME]I! [TEST]IIIfile is owned by user [NAME]true if [TEST] is false[TEST] -a / -o [TEST]IJens Oeserfile uses n units of space (2k 2 Kilobyte)-type [TYPE]logical AND or logical ORLinux Primer62/99

GNU/LinuxGeneric Mapping Tools (GMT)Python [ACTION]I -exec [CMD] {} \;IIIIruns the specified command [CMD] on the selected files {} \;-printprint the full file name on the standard output, followed by a newline-print0Iprint the full file name on the standard output, followed by a nullcharacter '\0' instead of the newline characterI-lsI-fls/fprint [FILE]IIlist current file in ls -dils format on standard outputlike -ls or -print but write to [FILE]gkd22aa@cip50: find -name ns OeserLinux Primer63/99

GNU/LinuxGeneric Mapping Tools (GMT)Pythongkd22aa@cip50: find /usr/ -type d -name aa@cip50: find /usr/ -type d -name examples -ls1329753 4 drwxr-xr-x 2 root root 4096 Oct 10 2007 /usr/share/apps1318914 4 drwxr-xr-x 2 root root 4096 Oct 10 2007 /usr/share/apps1318710 4 drwxr-xr-x 4 root root 4096 Oct 10 2007 /usr/share/apps1249525 4 drwxr-xr-x 3 root root 4096 Oct 10 2007 /usr/share/apps.gkd22aa@cip50: cp /etc/profile . ; cp -b /etc/profile .gkd22aa@cip50: find . -name "* " -print -exec rm -f {} \;./profile Jens OeserLinux Primer64/99

GNU/LinuxGeneric Mapping Tools (GMT)PythonPrint lines matching a patterngrep [OPTION] [PATTERN] [FILE] [OPTION]I -cI-vI-HIsuppress normal output; instead print a count of matching lines foreach input fileIinvert the sense of matchingIprint the file name for each match [PATTERN]I replaced with regular expression [FILE]I replaced with filenameJens OeserLinux Primer65/99

GNU/LinuxGeneric Mapping Tools (GMT)Pythongkd22aa@cip50: wget \http://www.geophysik.uni-muenchen.de/ oeser/LV/Shell/ort ex.txt \http://www.geophysik.uni-muenchen.de/ oeser/LV/Shell/ex-1.xyz \http://www.geophysik.uni-muenchen.de/ oeser/LV/Shell/ex-2.xyzgkd22aa@cip50: less -e *ex*gkd22aa@cip50: grep a ort : grep -i "[fn] " *ex*ex-1.xyz:# Hainichenex-2.xyz:# Hainichenort ex.txt:Bremenort ex.txt:Friedrichshafen.Jens OeserLinux Primer66/99

GNU/LinuxGeneric Mapping Tools (GMT)PythonChange file owner and groupchown [OPTION] [USER] [FILE]chgrp [OPTION] [GROUP] [FILE] [OPTION]I -RIoperate on files and directories recursively [FILE]I replaced withIIIJens Oeserfilename orabsolute orrelative pathLinux Primer67/99

GNU/LinuxGeneric Mapping Tools (GMT)Pythongkd22aa@cip50: finger USERLogin: gkd22aaName: Seminar-GeophysDirectory: /home/cip/gkd22aaShell: /bin/bashOn since Fri Feb 17 10:13 (CET) on pts/0 from munich.geophysikNo mail.No Plan.gkd22aa@cip50: iduid 24101(gkd22aa) gid 24100(gkd22) groups 24100(gkd22),117(fuse)gkd22aa@cip50: chown gkd22aa sort ex.txtgkd22aa@cip50: chgrp -R gkd22 Desktop/gkd22aa@cip50: ls -l Desktop/total 1240-rw-------

GNU/LinuxGeneric Mapping Tools (GMT)Python a basic principle in GNU/Linux and Unix I " Everything is a le!\ I this generalized le concept is inherently included I easy and consistent interface for the di erent applications I exceptionally easy input/output redirecting into these les I linking of several programs via these pipes all Unix-like operating systems have a graphical user interface (X11)