Introductory Course To Linux - Hpc2n.umu.se

Transcription

LinuxNavigating the File SystemData HandlingFinding PatternsScriptingMore advanced topicsIntroductory Course to LinuxPedro Ojeda-May, Mirko Myllykoski, and Birgitte BrydsöHPC2N,UmeåUniversity,901 87, Sweden.Pedro Ojeda-May, Mirko Myllykoski, and Birgitte BrydsöIntroductory Course to Linux

LinuxNavigating the File SystemData HandlingFinding PatternsScriptingMore advanced topicsTable of contents1Linux2Navigating the File System3Data Handling4Finding Patterns5Scripting6More advanced topicsPedro Ojeda-May, Mirko Myllykoski, and Birgitte BrydsöIntroductory Course to Linux

LinuxNavigating the File SystemData HandlingFinding PatternsScriptingMore advanced topicsLinux OSLinux OS components.Pedro Ojeda-May, Mirko Myllykoski, and Birgitte BrydsöIntroductory Course to Linux

LinuxNavigating the File SystemData HandlingFinding PatternsScriptingMore advanced topicsLinuxUNIX-like OSused in modern Android smartphonesthe difference between all UNIX-like OS is smallPedro Ojeda-May, Mirko Myllykoski, and Birgitte BrydsöIntroductory Course to Linux

LinuxNavigating the File SystemData HandlingFinding PatternsScriptingMore advanced topicsLinux timelinesource: wikipediaPedro Ojeda-May, Mirko Myllykoski, and Birgitte BrydsöIntroductory Course to Linux

LinuxNavigating the File SystemData HandlingFinding PatternsScriptingMore advanced topicsThe Linux terminalon the terminal you can see the so-called Prompthere you can control your PC/account or even a remote serverPedro Ojeda-May, Mirko Myllykoski, and Birgitte BrydsöIntroductory Course to Linux

LinuxNavigating the File SystemData HandlingFinding PatternsScriptingMore advanced topicsFiles organizationPedro Ojeda-May, Mirko Myllykoski, and Birgitte BrydsöIntroductory Course to Linux

LinuxNavigating the File SystemData HandlingFinding PatternsScriptingMore advanced topicsFiles organizationPedro Ojeda-May, Mirko Myllykoski, and Birgitte BrydsöIntroductory Course to Linux

LinuxNavigating the File SystemData HandlingFinding PatternsScriptingMore advanced topicsmanManual pages.man command: man nanoNANO(1)General Commands ManualNANO(1)NAMEnano - Nano’s ANOther editor, an enhanced free Pico cloneSYNOPSISnano [options] [[ line,column] file].DESCRIPTIONnano is a small, free and friendly editorthe default editor included in the non-freecopying Pico’s look and feel, nano alsodisabled by default) features in Pico, such"go to line and column number".Pedro Ojeda-May, Mirko Myllykoski, and Birgitte Brydsöwhich aims to replace Pico,Pine package.On top ofimplements some missing (oras "search and replace" andIntroductory Course to Linux

LinuxNavigating the File SystemData HandlingFinding PatternsScriptingMore advanced topicsNavigating the File SystemPedro Ojeda-May, Mirko Myllykoski, and Birgitte BrydsöIntroductory Course to Linux

LinuxNavigating the File SystemData HandlingFinding PatternsScriptingMore advanced topicslsList the content of a directory ls1CD9 ls -ltotal 24843644drwxrwxr-x 2 pedro pedro4096 nov ls -latotal 24844368drwxr-xr-x 44 pedro pedrodrwxr-xr-x 3 root rootdrwxrwxr-x 2 pedro pedro4096 feb 13 13:19 .4096 sep 19 11:05 .4096 nov 9 11:17 1CD99 11:17 1CD9 ls -lahtotal 24Gdrwxr-xr-x 44 pedro pedro 4,0K feb 13 13:25 .drwxr-xr-x 3 root root 4,0K sep 19 11:05 .drwxrwxr-x 2 pedro pedro 4,0K nov 9 11:17 1CD9Pedro Ojeda-May, Mirko Myllykoski, and Birgitte BrydsöIntroductory Course to Linux

LinuxNavigating the File SystemData HandlingFinding PatternsScriptingMore advanced topicsls ls -lahttotal 24Gdrwxr-xr-x 44 pedro pedro 4,0K feb 13 13:29 .-rw------- 1 pedro pedro 431K feb 13 13:29 .zsh historydrwx------ 6 pedro pedro 4,0K feb 13 13:28 Linux Abisko Kebne ls -lahrttotal 24G-rw-r--r--1 pedro pedro655 sep 19 11:05 .profilePedro Ojeda-May, Mirko Myllykoski, and Birgitte BrydsöIntroductory Course to Linux

LinuxNavigating the File SystemData HandlingFinding PatternsScriptingMore advanced topicschmodChange permissions.Useful cases:chmod Y ZY u,g,oZ r,w,xPedro Ojeda-May, Mirko Myllykoski, and Birgitte BrydsöIntroductory Course to Linux

LinuxNavigating the File SystemData HandlingFinding PatternsScriptingMore advanced topicscdChange directory.Useful cases:cd directorymove to ”directory”cdmove to HOME directorycd move to previous visited directorycd .move to upper directory in the hierarchical treepwd prints out the local directory pathPedro Ojeda-May, Mirko Myllykoski, and Birgitte BrydsöIntroductory Course to Linux

LinuxNavigating the File SystemData HandlingFinding PatternsScriptingMore advanced topicscpCopy files.Useful cases:cp text.txt directory/copy text.txt file to ”directory”cp -r test/ directory/copy the directory test into directory/.cp overwrites existing files!Pedro Ojeda-May, Mirko Myllykoski, and Birgitte BrydsöIntroductory Course to Linux

LinuxNavigating the File SystemData HandlingFinding PatternsScriptingMore advanced topicstouch/mkdirCreate files.Useful cases:touch text.txtcreates text.txt filemkdir testcreates the directory testPedro Ojeda-May, Mirko Myllykoski, and Birgitte BrydsöIntroductory Course to Linux

LinuxNavigating the File SystemData HandlingFinding PatternsScriptingMore advanced topicsrmRemove files.Useful cases:rm text.txtdeletes text.txt filerm -rf test/deletes the directory testdeleted files cannot be recovered!Pedro Ojeda-May, Mirko Myllykoski, and Birgitte BrydsöIntroductory Course to Linux

LinuxNavigating the File SystemData HandlingFinding PatternsScriptingMore advanced topicsWild cards?it represents a single character*it represents a string of characters[0 9] , [A B]it represents a range of numbers or charactersPedro Ojeda-May, Mirko Myllykoski, and Birgitte BrydsöIntroductory Course to Linux

LinuxNavigating the File SystemData HandlingFinding PatternsScriptingMore advanced topicsSymbolic linksalso called soft links is a pointer file to other file/directory. Onecan create a soft link with the ln command:ln -s source.txt linkls -l source.txt linklrwxrwxrwx 1 pedro pedro 14 sep-rw-r--r-- 1 pedro pedro 0 sepPedro Ojeda-May, Mirko Myllykoski, and Birgitte Brydsö8 22:14 link - source.txt8 22:13 source.txtIntroductory Course to Linux

LinuxNavigating the File SystemData HandlingFinding PatternsScriptingMore advanced topicsRedirectionwe can change the standard input (keyboard)/output (screen) ofLinux commands:The operator redirects the output of some commandls test.datin this case to the file test.datThe operator concatenate the output of some commandto the content of a file:ls test.datThe operator changes the standard inputThe operator 2 redirects the standard error:exec2 error .logThe operator 2 &1, redirects both standard output anderror: exec logfile2 &1Pedro Ojeda-May, Mirko Myllykoski, and Birgitte BrydsöIntroductory Course to Linux

LinuxNavigating the File SystemData HandlingFinding PatternsScriptingMore advanced topicsPipesOne can use the output of some command as the input foranother command:grep ’string’ file.txt wcgrep ’string’ file.txt file.outgrep ’string’ file.txt file.outPedro Ojeda-May, Mirko Myllykoski, and Birgitte BrydsöIntroductory Course to Linux

LinuxNavigating the File SystemData HandlingFinding PatternsScriptingMore advanced topicsExporting variablessome programs or libraries require environment variables toworkthey allow the program to follow different schemes withoutbeing re-compiledsome variables such as HOME are intrinsic to Linux OSwe need to export the variables for further use: export NUMBER OF THREADS 6Pedro Ojeda-May, Mirko Myllykoski, and Birgitte BrydsöIntroductory Course to Linux

LinuxNavigating the File SystemData HandlingFinding PatternsScriptingMore advanced topicsEditing filesPedro Ojeda-May, Mirko Myllykoski, and Birgitte BrydsöIntroductory Course to Linux

LinuxNavigating the File SystemData HandlingFinding PatternsScriptingMore advanced topicsData HandlingPedro Ojeda-May, Mirko Myllykoski, and Birgitte BrydsöIntroductory Course to Linux

LinuxNavigating the File SystemData HandlingFinding PatternsScriptingMore advanced topicsCompress/decompress filesCompressing files: gzip file--- file.gzDecompressing files: gunzip file.gzPedro Ojeda-May, Mirko Myllykoski, and Birgitte BrydsöIntroductory Course to Linux

LinuxNavigating the File SystemData HandlingFinding PatternsScriptingMore advanced topicsGenerating archivesGenerate tar-ball: tar -cvf directory.tar directoryOpening tar-ball: tar -xvf directory.tarPedro Ojeda-May, Mirko Myllykoski, and Birgitte BrydsöIntroductory Course to Linux

LinuxNavigating the File SystemData HandlingFinding PatternsScriptingMore advanced topicssshCommand for connecting to a remote computer.Useful cases:ssh username@abisko.hpc2n.umu.seconnecting to abisko machinessh -Xl username abisko.hpc2n.umu.seif you want to enable graphical display.Pedro Ojeda-May, Mirko Myllykoski, and Birgitte BrydsöIntroductory Course to Linux

LinuxNavigating the File SystemData HandlingFinding PatternsScriptingMore advanced topicssftp (scp)Protocol for data transfer. sftp username@abisko.hpc2n.umu.se get file put filePedro Ojeda-May, Mirko Myllykoski, and Birgitte BrydsöIntroductory Course to Linux

LinuxNavigating the File SystemData HandlingFinding PatternsScriptingMore advanced topicsrsyncProtocol for synchronizing data.rsync source targetrsync -az user@kebne.hpc2n.umu.se:/home/proj/ proj/Pedro Ojeda-May, Mirko Myllykoski, and Birgitte BrydsöIntroductory Course to Linux

LinuxNavigating the File SystemData HandlingFinding PatternsScriptingMore advanced topicsFinding patternsPedro Ojeda-May, Mirko Myllykoski, and Birgitte BrydsöIntroductory Course to Linux

LinuxNavigating the File SystemData HandlingFinding PatternsScriptingMore advanced topicsgrepThis command searches for patterns in text files.Useful cases:grep ’word’ fileit searches for pattern ’word’ in filegrep -rine ’word’ homepattern word is searched recursively in the directory /homePedro Ojeda-May, Mirko Myllykoski, and Birgitte BrydsöIntroductory Course to Linux

LinuxNavigating the File SystemData HandlingFinding PatternsScriptingMore advanced topicsawkThis command finds patterns in a file and can performarithmetic/string operations.Useful cases:awk ’/gold/ {print 1}’ fileit searches for pattern ’gold’ in file and prints out the firstcolumnPedro Ojeda-May, Mirko Myllykoski, and Birgitte BrydsöIntroductory Course to Linux

LinuxNavigating the File SystemData HandlingFinding PatternsScriptingMore advanced topicsScriptingPedro Ojeda-May, Mirko Myllykoski, and Birgitte BrydsöIntroductory Course to Linux

LinuxNavigating the File SystemData HandlingFinding PatternsScriptingMore advanced topicsScriptingallows to perform complex tasks without user interventionall Linux commands can be used in a script including wildcardsPedro Ojeda-May, Mirko Myllykoski, and Birgitte BrydsöIntroductory Course to Linux

LinuxNavigating the File SystemData HandlingFinding PatternsScriptingMore advanced topicsScriptinganalysis.sh#!/bin/bashgrep ’ABCD’ file.pdb file filtered.pdbprogram file filtered.pdb output.datexecute script with ./analysis.shPedro Ojeda-May, Mirko Myllykoski, and Birgitte BrydsöIntroductory Course to Linux

LinuxNavigating the File SystemData HandlingFinding PatternsScriptingMore advanced topicsScripting ls -lahtotal 24Gdrwxrwxr-x2 pedro pedro 4,0K nov9 11:17 1CD9permissions are set of ”user”, ”group”, or ”others”we can change permissions with chmod commandFor instance, chmod u x analysis.sh execute script with ./analysis.shPedro Ojeda-May, Mirko Myllykoski, and Birgitte BrydsöIntroductory Course to Linux

LinuxNavigating the File SystemData HandlingFinding PatternsScriptingMore advanced topicsWorking with the Promptctrl a: Go to the beginning of the linectrl e: Go to the end of the linectrl l: Clean the terminalPedro Ojeda-May, Mirko Myllykoski, and Birgitte BrydsöIntroductory Course to Linux

LinuxNavigating the File SystemData HandlingFinding PatternsScriptingMore advanced topicsConfiguring .bashrc fileExploring the history:by typing ”ctrl r” you will be prompted to introduce text whichbash will use to make a search in the list of commands you havetyped previously. That list is saved in the .bash history file in yourhome directory.One can control the behavior of the history file by settingenvironment variables in the .bashrc file as follows:export HISTCONTROL erasedupsexport HISTSIZE 100000export HISTFILESIZE 100000shopt -s histappendPedro Ojeda-May, Mirko Myllykoski, and Birgitte BrydsöIntroductory Course to Linux

LinuxNavigating the File SystemData HandlingFinding PatternsScriptingMore advanced topicsConfiguring .bashrc fileUsing aliases:if you need to type a long command several times, you may add itas an alias in your .bashrc file:alias ldir ’ls -lahrt egrep " d"’Pedro Ojeda-May, Mirko Myllykoski, and Birgitte BrydsöIntroductory Course to Linux

LinuxNavigating the File SystemData HandlingFinding PatternsScriptingMore advanced topicsSpecific commands on our clusterprojinfo: information of the usage of the project resourcessqueue -a -u username: status of the jobs for usernamesbatch script.sh: for job submissionscancel jobid: for cancelling a jobquota: information of the /home and /pfs disk usagePedro Ojeda-May, Mirko Myllykoski, and Birgitte BrydsöIntroductory Course to Linux

LinuxNavigating the File SystemData HandlingFinding PatternsScriptingMore advanced topicsLinux Cheat /linuxcheat-sheetPedro Ojeda-May, Mirko Myllykoski, and Birgitte BrydsöIntroductory Course to Linux

Linux Navigating the File System Data Handling Finding Patterns Scripting More advanced topics Introductory Course to Linux . drwxr-xr-x 3 root root 4,0K sep 19 11:05 . drwxrwxr-x 2 pedro pedro 4,0K nov 9 11:17 1CD9 Pedro Ojeda-May, Mirko Myllykoski, and Birgitte Bryds o Introductory Course to Linux.