<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://teaching.healthtech.dtu.dk/unix/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=WikiSysop</id>
	<title>Unix - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://teaching.healthtech.dtu.dk/unix/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=WikiSysop"/>
	<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/unix/index.php/Special:Contributions/WikiSysop"/>
	<updated>2026-04-16T15:28:57Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/unix/index.php?title=MediaWiki:Sidebar&amp;diff=63</id>
		<title>MediaWiki:Sidebar</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/unix/index.php?title=MediaWiki:Sidebar&amp;diff=63"/>
		<updated>2024-03-20T12:24:54Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: Created page with &amp;quot; * navigation ** https://teaching.healthtech.dtu.dk/|Course List ** https://teaching.healthtech.dtu.dk/unix/|Unix * TOOLBOX&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
* navigation&lt;br /&gt;
** https://teaching.healthtech.dtu.dk/|Course List&lt;br /&gt;
** https://teaching.healthtech.dtu.dk/unix/|Unix&lt;br /&gt;
* TOOLBOX&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/unix/index.php?title=Commands_summary&amp;diff=62</id>
		<title>Commands summary</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/unix/index.php?title=Commands_summary&amp;diff=62"/>
		<updated>2024-03-20T12:23:28Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: Created page with &amp;quot;__NOTOC__ = Unix architecture and file system = {| class=&amp;quot;wikitable&amp;quot; |- !style=&amp;quot;width: 25%&amp;quot;| Unix Command !Acronym translation  !Description |-  |&amp;#039;&amp;#039;&amp;#039;who&amp;#039;&amp;#039;&amp;#039; or &amp;#039;&amp;#039;&amp;#039;whoami&amp;#039;&amp;#039;&amp;#039; |&amp;lt;nowiki&amp;gt;-&amp;lt;/nowiki&amp;gt; |Tells you who the current user is. The &amp;#039;who&amp;#039; command is not present in MobaXterm but you can use &amp;#039;whoami&amp;#039; instead  |- |&amp;#039;&amp;#039;&amp;#039;man&amp;#039;&amp;#039;&amp;#039; &amp;lt;COMMAND&amp;gt; |Manual |A very useful command. By using this command on other Unix commands, it gives you a manual of how to use them. This command is not pre...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
= Unix architecture and file system =&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;width: 25%&amp;quot;| Unix Command&lt;br /&gt;
!Acronym translation &lt;br /&gt;
!Description&lt;br /&gt;
|- &lt;br /&gt;
|&#039;&#039;&#039;who&#039;&#039;&#039; or &#039;&#039;&#039;whoami&#039;&#039;&#039;&lt;br /&gt;
|&amp;lt;nowiki&amp;gt;-&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|Tells you who the current user is. The &#039;who&#039; command is not present in MobaXterm but you can use &#039;whoami&#039; instead &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;man&#039;&#039;&#039; &amp;lt;COMMAND&amp;gt;&lt;br /&gt;
|Manual&lt;br /&gt;
|A very useful command. By using this command on other Unix commands, it gives you a manual of how to use them. This command is not present in MobaXterm, but you can instead use google to find command manuals. &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;cal&#039;&#039;&#039; &amp;lt;nowiki&amp;gt;[OPTION]&amp;lt;/nowiki&amp;gt; &lt;br /&gt;
|Calendar&lt;br /&gt;
|Gives you the current date in a calendar form&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;date&#039;&#039;&#039; &amp;lt;nowiki&amp;gt;[OPTION]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|&amp;lt;nowiki&amp;gt;-&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|Gives you the current date &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;pwd&#039;&#039;&#039; &amp;lt;nowiki&amp;gt;[OPTION]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|Print working directory&lt;br /&gt;
|Where are you? Shows the current directory &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;ls&#039;&#039;&#039; &amp;lt;nowiki&amp;gt;[OPTION]&amp;lt;/nowiki&amp;gt; [DIRECTORY]&lt;br /&gt;
|List segments&lt;br /&gt;
|Shows the files in the current directory if a filepath is not given.    &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;cd&#039;&#039;&#039; &amp;lt;nowiki&amp;gt;[OPTION]&amp;lt;/nowiki&amp;gt; &amp;lt;DIRECTORY&amp;gt; &lt;br /&gt;
|Change Directory&lt;br /&gt;
|Moves you to a specified directory. You can type &#039;cd ..&#039; to move one directory back. The &#039;..&#039; simply means to go up one level towards your root  &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;mkdir&#039;&#039;&#039; &amp;lt;nowiki&amp;gt;[OPTION]&amp;lt;/nowiki&amp;gt; &amp;lt;DIRECTORY&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
|Make directory&lt;br /&gt;
|Makes the specified directory&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;rmdir&#039;&#039;&#039; &amp;lt;nowiki&amp;gt;[OPTION]&amp;lt;/nowiki&amp;gt; &amp;lt;DIRECTORY&amp;gt;&lt;br /&gt;
|Remove directory&lt;br /&gt;
|Removes the specified directory if it&#039;s empty. To remove a non-empty directory, one can use the recursive option &#039;&#039;&#039;r&#039;&#039;.&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;ln&#039;&#039;&#039; &amp;lt;nowiki&amp;gt;[OPTION]&amp;lt;/nowiki&amp;gt; &amp;lt;DIRECTORY&amp;gt; &amp;lt;LINK_NAME&amp;gt;&lt;br /&gt;
|Link&lt;br /&gt;
|Can be used to create links (shortcuts) between files and directories. &lt;br /&gt;
|}&lt;br /&gt;
= Standard streams and working with files =&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Unix Command&lt;br /&gt;
!Acronym translation &lt;br /&gt;
!Description&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;touch&#039;&#039;&#039; [OPTION] &amp;lt;FILE&amp;gt;&lt;br /&gt;
|&amp;lt;nowiki&amp;gt;-&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|Touches a file. If the file doesn&#039;t exist already it will create a file with the specified name. If it already exists it will update the date of the file &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;mv&#039;&#039;&#039; [OPTION] &amp;lt;FILE&amp;gt; &amp;lt;destination directory or another filename&amp;gt;&lt;br /&gt;
|Move&lt;br /&gt;
|Moves a file to a specified directory. It can also be used to rename files. &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;rm&#039;&#039;&#039; [OPTION] &amp;lt;FILE&amp;gt; &lt;br /&gt;
|Remove&lt;br /&gt;
|Removes specified file in current directory. This command can also be used to remove non-empty directories. &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;cp&#039;&#039;&#039; [OPTION] &amp;lt;FILE&amp;gt; &amp;lt;destination directory or another file&amp;gt;&lt;br /&gt;
|Copy&lt;br /&gt;
|Works a lot like mv, but moves a copy of the file instead. Can also be used copy the content of one file to another file.  &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;cat&#039;&#039;&#039; [OPTION] &amp;lt;FILE&amp;gt;&lt;br /&gt;
|Concatenate &lt;br /&gt;
|Concatenates files and displays it in standard output. If used on one file, the content of that file is displayed in the command line interface. &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;head&#039;&#039;&#039; [OPTION] &amp;lt;FILE&amp;gt; &lt;br /&gt;
|&amp;lt;nowiki&amp;gt;-&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|Outputs the first part of a file&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;tail&#039;&#039;&#039; [OPTION] &amp;lt;FILE&amp;gt;&lt;br /&gt;
|&amp;lt;nowiki&amp;gt;-&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|Outputs the last part of a file&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;less&#039;&#039;&#039; &amp;lt;FILE&amp;gt;&lt;br /&gt;
|&amp;lt;nowiki&amp;gt;-&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|Shows a screenfull of the file. This is a useful command for viewing big files as it loads at smalls segments at a time. q --&amp;gt; quit , space --&amp;gt; scroll forward one page , b --&amp;gt; scroll backward one page. Arrow keys can be used to scroll up and down one line at a time.     &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;wc&#039;&#039;&#039; [OPTION] &amp;lt;FILE&amp;gt; &lt;br /&gt;
|Word count&lt;br /&gt;
|Counts the lines and words in the file/files, but can also count other things based on the options you give it.   &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;paste&#039;&#039;&#039; [OPTION] &amp;lt;FILE&amp;gt;&lt;br /&gt;
|&amp;lt;nowiki&amp;gt;-&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|Merges lines from different files. &lt;br /&gt;
|- &lt;br /&gt;
|&#039;&#039;&#039;cut&#039;&#039;&#039; &amp;lt;nowiki&amp;gt;[OPTION]&amp;lt;/nowiki&amp;gt; &amp;lt;FILE&amp;gt;&lt;br /&gt;
|&amp;lt;nowiki&amp;gt;-&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|Removes different parts of a file depending on on what is specified in the option. &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;echo&#039;&#039;&#039; [OPTION] &amp;lt;STRING&amp;gt; &lt;br /&gt;
|&amp;lt;nowiki&amp;gt;-&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|Outputs the string to your command line interface. In computer language, a string is just a sequence of characters.&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;wget&#039;&#039;&#039; [OPTION] &amp;lt;URL&amp;gt;&lt;br /&gt;
|web get&lt;br /&gt;
|A non-interactive network downloader used to download files located at the URL. &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;curl&#039;&#039;&#039; [OPTION] &amp;lt;URL&amp;gt; &lt;br /&gt;
|client URL&lt;br /&gt;
|Similarly to &#039;&#039;&#039;wget&#039;&#039;&#039;, it is used to download files at the specified URL. This is an alternative MAC OS users, where &#039;&#039;&#039;wget&#039;&#039;&#039; doesn&#039;t work. &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;tee&#039;&#039;&#039; [OPTION] &amp;lt;FILE&amp;gt;&lt;br /&gt;
|It&#039;s named after the &#039;T-splitter&#039; used in plumbing. &lt;br /&gt;
|Splits output so that it can be outputted to both the terminal and a file. &lt;br /&gt;
|}&lt;br /&gt;
= Text editors and some shell scripting =&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Unix Command&lt;br /&gt;
!Acronym translation &lt;br /&gt;
!Description&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;alias&#039;&#039;&#039; &amp;lt;nowiki&amp;gt;&amp;lt;alias_name&amp;gt;=&amp;lt;The stuff you want to make an alias for&amp;gt;&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|&amp;lt;nowiki&amp;gt;-&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|Creates an alias called alias_name for what you&#039;ve inserted on the right side of &#039;=&#039;&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;source&#039;&#039;&#039; &amp;lt;FILE&amp;gt; &lt;br /&gt;
|&amp;lt;nowiki&amp;gt;-&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|Executes the contents of a file in current shell. Changes made when the file is run will be permanent until changed. It is synonymous with Prompt$ &#039;&#039;&#039;.&#039;&#039;&#039; &amp;lt;FILE&amp;gt;.   &lt;br /&gt;
|- &lt;br /&gt;
|&#039;&#039;&#039;bash&#039;&#039;&#039; &amp;lt;FILE&amp;gt;&lt;br /&gt;
|Bourne again shell&lt;br /&gt;
|&#039;&#039;&#039;Bash&#039;&#039;&#039; will execute &amp;lt;FILE&amp;gt; as a different process. This way, changes that occur while the file is being executed cannot affect your shell.  &lt;br /&gt;
|}&lt;br /&gt;
= Setting up your shell script =&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Unix Command&lt;br /&gt;
!Acronym translation &lt;br /&gt;
!Description&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;which&#039;&#039;&#039; &amp;lt;COMMAND&amp;gt;&lt;br /&gt;
|&amp;lt;nowiki&amp;gt;-&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|Shows the full path to the command.&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;read&#039;&#039;&#039; [OPTION] [input1] [input2] [input3]&lt;br /&gt;
|&amp;lt;nowiki&amp;gt;-&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|Can be used to prompt user for input and save them as variables [input1]..[input3].  &lt;br /&gt;
|}&lt;br /&gt;
= Filtering and regular expressions =&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Unix Command&lt;br /&gt;
!Acronym translation &lt;br /&gt;
!Description&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;grep&#039;&#039;&#039; [PATTERN] &amp;lt;FILE&amp;gt;&lt;br /&gt;
|Global regular expression print. &lt;br /&gt;
|Uses regular expressions select lines in a file that matches the pattern. &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;sed&#039;&#039;&#039; [OPTION] &amp;lt;SCRIPT&amp;gt; &amp;lt;FILE&amp;gt;&lt;br /&gt;
|stream editor&lt;br /&gt;
|Allows user to edit files without actually opening the files using regular expressions.&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;tr&#039;&#039;&#039; [OPTION] &amp;lt;SET1&amp;gt; &amp;lt;SET2&amp;gt;&lt;br /&gt;
|Translate&lt;br /&gt;
|Translates characters from the standard input and writes to the standard output.  &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;sort&#039;&#039;&#039; [OPTION] &amp;lt;FILE&amp;gt;&lt;br /&gt;
|&amp;lt;nowiki&amp;gt;-&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|Sorts the content of a file.  &lt;br /&gt;
|}&lt;br /&gt;
= File permissions = &lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Unix Command&lt;br /&gt;
!Acronym translation&lt;br /&gt;
!Description&lt;br /&gt;
|- &lt;br /&gt;
|&#039;&#039;&#039;chmod&#039;&#039;&#039; [OPTION] [MODE] &amp;lt;FILE&amp;gt;&lt;br /&gt;
|Change mode.&lt;br /&gt;
|Changes file permissions on a file according to the mode given. No need to be confused about [MODE], as it just another term used for file permission. It can be specified with letters or numbers. It&#039;s easier to understand what you&#039;re doing with letters but using numbers can be faster. In the example, we&#039;ll show how to use both. &lt;br /&gt;
|- &lt;br /&gt;
|&#039;&#039;&#039;chown&#039;&#039;&#039; [OPTION] [OWNER][:[GROUP]] &amp;lt;FILE&amp;gt;&lt;br /&gt;
|Change owner. &lt;br /&gt;
|Change file owner and/or group. This can be done separately or simultaneously by typing [OWNER]:[GROUP]. &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;chgrp&#039;&#039;&#039; [OPTION] &amp;lt;FILE&amp;gt;&lt;br /&gt;
|Change group.&lt;br /&gt;
|Change group of a file.&lt;br /&gt;
|}&lt;br /&gt;
= File compression and advanced packaging tools =&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Unix Command&lt;br /&gt;
!Acronym translation &lt;br /&gt;
!Description&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;tar&#039;&#039;&#039; [OPTION] &amp;lt;ARCHIVE&amp;gt; &amp;lt;FILES&amp;gt; &lt;br /&gt;
|Tape archive&lt;br /&gt;
|Archive utility tool, used to create and extract archives. Archives are simply multiple files that have been combined into one file. &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;gzip&#039;&#039;&#039; [OPTION] &amp;lt;FILE&amp;gt; &lt;br /&gt;
|GNU Zone informational Protocol. &lt;br /&gt;
|Compresses &amp;lt;FILE&amp;gt;   &lt;br /&gt;
|- &lt;br /&gt;
|&#039;&#039;&#039;gunzip&#039;&#039;&#039; [OPTION] &amp;lt;FILE&amp;gt;&lt;br /&gt;
|GNU un Zone informational Protocol. &lt;br /&gt;
|Decompresses &amp;lt;FILE&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;zip&#039;&#039;&#039; [OPTION] &amp;lt;FILE&amp;gt;&lt;br /&gt;
|Zone informational Protocol&lt;br /&gt;
|Archive and compression utility. Used to make an archive or compress &amp;lt;FILE&amp;gt;.&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;unzip&#039;&#039;&#039;&lt;br /&gt;
|un Zone informational Protocol&lt;br /&gt;
|Decompresses &amp;lt;FILE&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;apt&#039;&#039;&#039; [OPTION] &amp;lt;PACKAGE&amp;gt;&lt;br /&gt;
|Advanced Packaging tool&lt;br /&gt;
|Package manager for Ubuntu with many utilities. &lt;br /&gt;
|}&lt;br /&gt;
= Processes: foreground and background, ps, top, kill, screen, nohup and daemons =&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;width: 18%&amp;quot;| Unix Command&lt;br /&gt;
!Acronym translation &lt;br /&gt;
!Description&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;COMMAND&amp;gt; &#039;&#039;&#039;&amp;amp;&#039;&#039;&#039; &lt;br /&gt;
|&amp;lt;nowiki&amp;gt;-&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|Runs command as a background process &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;bg&#039;&#039;&#039; %&amp;lt;PID&amp;gt; &lt;br /&gt;
|bg and PID are short for background and process identification respectively  &lt;br /&gt;
|Continues a stopped job in the background  &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;fg&#039;&#039;&#039; %&amp;lt;PID&amp;gt; &lt;br /&gt;
|fg and PID are short for foreground and process identification&lt;br /&gt;
|Continues a stopped job in the foreground&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;sleep&#039;&#039;&#039; &amp;lt;NUMBER&amp;gt;[s/m/h/d]&lt;br /&gt;
|&amp;lt;nowiki&amp;gt;-&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|Delays for a specified amount of time. This can be specified &amp;lt;NUMBER&amp;gt; and suffixes; s, m, h and d which are short seconds, minuted, hours and days respectively. By default, the suffix is s &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;top&#039;&#039;&#039; [OPTION]&lt;br /&gt;
|&amp;lt;nowiki&amp;gt;-&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|Displays all the processes running on your computer&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;ps&#039;&#039;&#039; [OPTION]&lt;br /&gt;
|Process status&lt;br /&gt;
|Reports a snapshot of current processes &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;kill&#039;&#039;&#039; [OPTION] &amp;lt;PID&amp;gt;&lt;br /&gt;
|&amp;lt;nowiki&amp;gt;-&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|Sends a signal to a process and by default this signal is to terminate the process&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;screen&#039;&#039;&#039; [OPTION]&lt;br /&gt;
|&amp;lt;nowiki&amp;gt;-&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|Used to create new terminal windows that are detached from each other. Child processes created within these new terminal windows are not affected if their parent process is terminated   &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;disown&#039;&#039;&#039;&lt;br /&gt;
|&amp;lt;nowiki&amp;gt;-&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|Dissociates process from current terminal session&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;nohup&#039;&#039;&#039; [OPTION]&lt;br /&gt;
|No hangup&lt;br /&gt;
|Used to run commands immune to hangups, ignoring stdin. By default output is redirected to nohup.out. &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;pstree&#039;&#039;&#039;&lt;br /&gt;
|Process tree&lt;br /&gt;
|Display a tree of parent and child processes&lt;br /&gt;
|}&lt;br /&gt;
= Understanding network and remote servers: IP/URL, ssh, scp, wget, curl =&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Unix Command&lt;br /&gt;
!Acronym translation &lt;br /&gt;
!Description&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;wget&#039;&#039;&#039; [OPTION] &amp;lt;URL&amp;gt;&lt;br /&gt;
|web get&lt;br /&gt;
|A non-interactive network downloader used to download files located at the URL. &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;curl&#039;&#039;&#039; [OPTION] &amp;lt;URL&amp;gt;&lt;br /&gt;
|Client url&lt;br /&gt;
|Similarly to &#039;&#039;&#039;wget&#039;&#039;&#039;, it is used to download files at the specified URL. This is an alternative MAC OS users, where &#039;&#039;&#039;wget&#039;&#039;&#039; doesn&#039;t work. &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;ssh&#039;&#039;&#039;  &amp;lt;PORT&amp;gt; &amp;lt;user@IP/Domain_name&amp;gt;&lt;br /&gt;
|Secure shell &lt;br /&gt;
|Used to establish a secure connection to a remote server/system. It&#039;s also known as secure shell protocol.  &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;scp&#039;&#039;&#039; &amp;lt;PORT&amp;gt; &amp;lt;user@IP/Domain_name&amp;gt; &amp;lt;user@IP/Domain_name&amp;gt; &lt;br /&gt;
|Secure copy protocol&lt;br /&gt;
|Starts a secure copy protocol, which copies files securely across from remote networks to clients or from clients to remote networks. &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;telnet&#039;&#039;&#039; &amp;lt;URL&amp;gt; &amp;lt;PORT&amp;gt;&lt;br /&gt;
|Teletype network&lt;br /&gt;
|Establishes a connection with the specified URL and port. &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;ifconfig&#039;&#039;&#039; [OPTION]&lt;br /&gt;
|Interface configuration&lt;br /&gt;
|Displays currently active networks but when used with &#039;&#039;&#039;a&#039;&#039;&#039;, it displays the status of all networks.&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;nslookup&#039;&#039;&#039;&lt;br /&gt;
|Name server lookup&lt;br /&gt;
|Used to obtain information about a server through a DNS (Domain name system) server. &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;ping&#039;&#039;&#039; [OPTION] &amp;lt;IP/URL&amp;gt;&lt;br /&gt;
|Packet Internet Groper&lt;br /&gt;
|Checks network connectivity between host (your computer) and host/server.  &lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/unix/index.php?title=File:Protocol_overview.png&amp;diff=61</id>
		<title>File:Protocol overview.png</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/unix/index.php?title=File:Protocol_overview.png&amp;diff=61"/>
		<updated>2024-03-20T12:22:44Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/unix/index.php?title=Understanding_network_and_remote_servers:_IP/URL,_ssh,_scp,_wget,_curl&amp;diff=60</id>
		<title>Understanding network and remote servers: IP/URL, ssh, scp, wget, curl</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/unix/index.php?title=Understanding_network_and_remote_servers:_IP/URL,_ssh,_scp,_wget,_curl&amp;diff=60"/>
		<updated>2024-03-20T12:21:51Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Servers and URLS */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
In computing, a network is simply a network consisting of computers and other devices; routers, gateways, modems etc.. These computers are either desktop pc&#039;s, which is the type that you&#039;re using, or they&#039;re server computers. The internet in its entirety is in fact an example of humongous network of global proportions, so as a short introduction, watch this short and simple video explaining the internet [https://www.youtube.com/watch?v=7_LPdttKXPc What&#039;s the internet]. &lt;br /&gt;
&lt;br /&gt;
Computers and other devices within the internet have addresses called IP addresses that have the syntax x.x.x.x, where x is a number between 0 and 255. There are 2 types of IP addresses; private and public. The difference is in what numbers are used. Private IP address are &#039;private&#039;, which just means that they&#039;re not directly connected to the internet. You can check your computers IP by typing, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;ifconfig&#039;&#039;&#039; &lt;br /&gt;
which will display information on the IP addresses currently in use by your computer. For windows users, your IP address should be under &#039;wifi0&#039; or &#039;eth0&#039;. The terms &#039;wifi0&#039; and &#039;eth0&#039; mean that you&#039;re connected to the internet via wifi and LAN cable respectively. For Mac users it should be one of the IP addresses next to &#039;&#039;inet&#039;&#039;. The &#039;lo: inet 127.0.0.1&#039; is your machines loopback address and is not your private IP address. For more information on finding your IP address on a MAC, you can follow this link [http://osxdaily.com/2010/11/21/find-ip-address-mac/ Finding your IP address on Mac OS]. &lt;br /&gt;
&lt;br /&gt;
Public IP addresses connect you with the rest of the internet. Typically, public IP addresses belong to a modem/router, which you can simply think of as a frontline device that connects all of your private devices to the rest of internet. Devices that are connected to the same modem, will all share the same public IP address and because public IP addresses are &#039;public&#039; they must be unique. This is not the case for private IP addresses, because they aren&#039;t directly connected to the internet. The term for a network consisting of public IP addresses is called &#039;World Area Network&#039; (WAN), which is represented  with a &amp;lt;span style=&amp;quot;color:#ff0000&amp;quot;&amp;gt;&#039;&#039;&#039;red&#039;&#039;&#039;&amp;lt;/span&amp;gt; line in &#039;&#039;&#039;figure 7.1&#039;&#039;&#039;. Just so you know, &#039;&#039;&#039;figure 7.1&#039;&#039;&#039; has been simplified so that the router for the server computers aren&#039;t included. &lt;br /&gt;
You can look up your public IP address by following this link [https://whatismyipaddress.com/ Public IP address]. But you can also find your public IP address by using &#039;&#039;&#039;wget&#039;&#039;&#039;,&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;wget&#039;&#039;&#039; -qO- ifconfig.me&lt;br /&gt;
The command option &#039;&#039;&#039;q&#039;&#039;&#039; is short for quiet mode, and -O- ensures that the output is written to stdout. The Mac OS is not equipped with &#039;&#039;&#039;wget&#039;&#039;&#039; by default, but you can instead use the command &#039;&#039;&#039;curl&#039;&#039;&#039;, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;curl&#039;&#039;&#039; ifconfig.me &lt;br /&gt;
&lt;br /&gt;
You shouldn&#039;t get too attached to your IP addresses, as they can easily change. IP addresses are determined by your internet service provider (ISP), hence, it&#039;ll change depending on the WiFi you&#039;re logged onto, when you unplug and replug your router or perhaps if your ISP decides to change it. &lt;br /&gt;
&lt;br /&gt;
We briefly mentioned something about using a LAN cable, but we haven&#039;t defined what LAN is. LAN is short for &#039;Local Area Network (LAN)&#039;, and you can think of it as the network connecting your private devices. In &#039;&#039;&#039;figure 7.1&#039;&#039;&#039;, this is depicted as the devices connected by the &amp;lt;span style=&amp;quot;color:#00ff00&amp;quot;&amp;gt;&#039;&#039;&#039;green&#039;&#039;&#039;&amp;lt;/span&amp;gt; line; printer, phone and computer. The device that allocates private IP addresses to your &#039;private devices&#039; while also establishing connectivity between these devices, is your router. Often, it is the case that the modem and router are combined into one device, which is how it&#039;s illustrated in &#039;&#039;&#039;figure 7.1&#039;&#039;&#039;. For more information on the difference between router and modem, follow this link [https://www.howtogeek.com/234233/whats-the-difference-between-a-modem-and-a-router/ Modem vs router]&lt;br /&gt;
&lt;br /&gt;
The IP addresses we&#039;ve been discussing so far are IPv4 addresses. The amount of possible IPv4 addresses is approximately 4.3 billion, which was a sufficient amount for some time. However, it very quickly became clear that it wasn&#039;t, therefore, the next version of IP addresses, IPv6, has 7.9x10^28 as many IP addresses as IPv4. &lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
[[File:Network_LAN&amp;amp;WAN.png|center|frame|&#039;&#039;&#039;Figure 7.1 Network Overview:&#039;&#039;&#039; This figure gives an overview of a network and distinguishes between LAN (&amp;lt;span style=&amp;quot;color:#00ff00&amp;quot;&amp;gt;&#039;&#039;&#039;green&#039;&#039;&#039;&amp;lt;/span&amp;gt;) and WAN (&amp;lt;span style=&amp;quot;color:#ff0000&amp;quot;&amp;gt;&#039;&#039;&#039;red&#039;&#039;&#039;&amp;lt;/span&amp;gt;). The modem connects private devices within the same network to the internet, while the router connects devices within the LAN. Servers don&#039;t necessarily need to be run by a server computer and can also be run by a desktop computer.]]&lt;br /&gt;
&lt;br /&gt;
== Servers and URLS == &lt;br /&gt;
A &#039;server&#039; is simply a computer connected to a network that provides &#039;services&#039; to other computers. The computers that the server provides services for are called &#039;&#039;clients&#039;&#039;. This kind of relationship between servers and clients is what&#039;s defined as the &#039;client-server model&#039;. &lt;br /&gt;
&lt;br /&gt;
A simple example of a server that you&#039;re likely familiar with are print servers. Print servers are servers that provide the service of printing for computers connected to the same network. In a &#039;client-server model&#039;, the connected computers are the clients and the print server is the server. A print server would typically be what&#039;s called a &#039;local server&#039;. Servers can be distinguished into local and remote servers, the only difference being that local servers are setup to be within a LAN (so within the green lines in &#039;&#039;&#039;figure 7.1&#039;&#039;&#039;) and remote servers are setup on another &#039;remote computer&#039; (the servers connected by the red line in &#039;&#039;&#039;figure 7.1&#039;&#039;&#039;). It goes without saying, that remote servers are found everywhere on the internet, because that&#039;s largely what the internet is made of. There are different type of servers, but you&#039;re probably most familiar with web servers like (wikipedia, google, youtube, facebook etc..). Web servers are available to clients through the use of a web browser (Google Chrome, Internet Explorer etc.) and a URL, which is likely the only way you&#039;ve been accessing them up till now. You can, however, also interact with them in a little more &#039;old school way&#039; through the command line interface. For example, in the section &#039;Standard streams and working with files&#039;, we used &#039;&#039;&#039;wget&#039;&#039;&#039; to retrieve files from URLS. &lt;br /&gt;
&lt;br /&gt;
URL is short for &#039;Uniform resource locator&#039;, and they&#039;re are used to identify websites. A URL consists of several parts; &#039;protocol&#039;, &#039;sub domain&#039;, &#039;second level domain&#039;, &#039;top level domain&#039;, &#039;directory/folder&#039;, &#039;filename/webpage&#039;, and &#039;file extension&#039;. Let&#039;s go through what each part represents by using a wikipedia URL as an example.&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#ff0000&amp;quot;&amp;gt;&#039;&#039;&#039;https&#039;&#039;&#039;&amp;lt;/span&amp;gt;&#039;&#039;&#039;://&#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:#ff00ff&amp;quot;&amp;gt;&#039;&#039;&#039;en&#039;&#039;&#039;&amp;lt;/span&amp;gt;&#039;&#039;&#039;.&#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:#00ff00&amp;quot;&amp;gt;&#039;&#039;&#039;wikipedia&#039;&#039;&#039;&amp;lt;/span&amp;gt;&#039;&#039;&#039;.&#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:#ffff00&amp;quot;&amp;gt;&#039;&#039;&#039;org&#039;&#039;&#039;&amp;lt;/span&amp;gt;&#039;&#039;&#039;/&#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:#0000ff&amp;quot;&amp;gt;&#039;&#039;&#039;wiki&#039;&#039;&#039;&amp;lt;/span&amp;gt;&#039;&#039;&#039;/&#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:#008080&amp;quot;&amp;gt;&#039;&#039;&#039;Elon_Musk&#039;&#039;&#039;&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;span style=&amp;quot;color:#ff0000&amp;quot;&amp;gt;&#039;&#039;&#039;https&#039;&#039;&#039;&amp;lt;/span&amp;gt; --&amp;gt; protocol.&lt;br /&gt;
*&amp;lt;span style=&amp;quot;color:#ff00ff&amp;quot;&amp;gt;&#039;&#039;&#039;en&#039;&#039;&#039;&amp;lt;/span&amp;gt; --&amp;gt; subdomain.&lt;br /&gt;
*&amp;lt;span style=&amp;quot;color:#00ff00&amp;quot;&amp;gt;&#039;&#039;&#039;wikipedia&#039;&#039;&#039;&amp;lt;/span&amp;gt; --&amp;gt; second level domain.&lt;br /&gt;
*&amp;lt;span style=&amp;quot;color:#ffff00&amp;quot;&amp;gt;&#039;&#039;&#039;org&#039;&#039;&#039;&amp;lt;/span&amp;gt; --&amp;gt; top level domain.&lt;br /&gt;
*&amp;lt;span style=&amp;quot;color:#0000ff&amp;quot;&amp;gt;&#039;&#039;&#039;wiki&#039;&#039;&#039;&amp;lt;/span&amp;gt; --&amp;gt; folder/directory.&lt;br /&gt;
*&amp;lt;span style=&amp;quot;color:#008080&amp;quot;&amp;gt;&#039;&#039;&#039;Elon_Musk&#039;&#039;&#039;&amp;lt;/span&amp;gt; --&amp;gt; webpage.&lt;br /&gt;
&lt;br /&gt;
The protocol used is &amp;lt;span style=&amp;quot;color:#ff0000&amp;quot;&amp;gt;&#039;&#039;&#039;https&#039;&#039;&#039;&amp;lt;/span&amp;gt; short for &#039;Hypertext Transfer Protocol Secure&#039;. This is the protocol that your computer uses to retrieve data securely from your browser (google chrome, internet explorer etc.) corresponding to the URL. Protocols are a different topic, and we&#039;ll talk more about that later. Before &#039;https&#039;, the protocol used was &#039;http&#039; but due to problems with data insecurity, there&#039;s a gradual increase in the use of the &#039;https&#039; protocol. In short, &#039;https&#039; ensures that the data received from your browser is encrypted and you can read more about this by following this [https://www.entrepreneur.com/article/281633 link]. But not all websites use it, for instance, this very website is using the &#039;http&#039; protocol for interaction with browsers.&amp;lt;br&amp;gt; &lt;br /&gt;
Following &#039;https&#039;, there can be a subdomain and in this case it&#039;s &amp;lt;span style=&amp;quot;color:#ff00ff&amp;quot;&amp;gt;&#039;&#039;&#039;en&#039;&#039;&#039;&amp;lt;/span&amp;gt;. The subdomain can be called just about anything but the most commonly used is &#039;www&#039;. You don&#039;t actually have to add a subdomain but  what&#039;s important, is that one of the 2 URLS, one with a subdomain and the one without, redirects to the other in order to avoid duplicate versions of the URL. For example, if you write &#039;https://wikipedia.org/wiki/Elon_Musk&#039; in your browser, you will be redirected to &#039;https://en.wikipedia.org/wiki/Elon_Musk&#039;. Next, &amp;lt;span style=&amp;quot;color:#00ff00&amp;quot;&amp;gt;&#039;&#039;&#039;wikipedia&#039;&#039;&#039;&amp;lt;/span&amp;gt; is the second level domain. Along with the top level domain, the second level domain make up the domain name of URL which is what makes the URL unique. The top level domain in this URL is &amp;lt;span style=&amp;quot;color:#ffff00&amp;quot;&amp;gt;&#039;&#039;&#039;org&#039;&#039;&#039;&amp;lt;/span&amp;gt;, which is short for organization. A more commonly used top level domain you&#039;re  familiar with is &#039;com&#039;, short for commercial. The folder/directory is &amp;lt;span style=&amp;quot;color:#0000ff&amp;quot;&amp;gt;&#039;&#039;&#039;wiki&#039;&#039;&#039;&amp;lt;/span&amp;gt;. This is followed by the webpage &amp;lt;span style=&amp;quot;color:#008080&amp;quot;&amp;gt;&#039;&#039;&#039;Elon Musk&#039;&#039;&#039;&amp;lt;/span&amp;gt;. In this case, there&#039;s no file extension but in previous sections we&#039;ve been using URL&#039;s, https://teaching.healthtech.dtu.dk/material/unix/ex1.acc,  where the filename is &#039;ex1&#039; and the file extension is &#039;acc&#039;.   &lt;br /&gt;
&lt;br /&gt;
You can find the IP address of a domain, by using the command &#039;&#039;&#039;nslookup&#039;&#039;&#039;,&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;nslookup&#039;&#039;&#039; &amp;lt;Domain_name&amp;gt;&lt;br /&gt;
would output the IP address along with some additional information to your terminal. For example, if you typed &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;nslookup&#039;&#039;&#039; wikipedia.org&lt;br /&gt;
you would get the IP address 91.198.174.192. The command, &#039;&#039;&#039;nslookup&#039;&#039;&#039;, actually receives this information from what&#039;s called DNS (Domain name system) servers. DNS servers are simply systems that store URL&#039;s with their corresponding IP addresses, ensuring that you&#039;re brought to the right IP address when you use a URL.  &lt;br /&gt;
&lt;br /&gt;
Another useful command is  &#039;&#039;&#039;ping&#039;&#039;&#039;, which is used to check network connectivity between host (your computer) and another host or server. In simple terms, it sends a data packet to the specified IP or URL with the message &amp;quot;PING&amp;quot; and waits for a response. The response time from the host/server is called latency. High latency and slow ping are what causes &#039;lagging&#039; in online computer games or maybe just some really slow websites. Conversely, low latency and fast pings ensure enjoyable gaming and web browsing. You can check the ping of a website by typing, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;ping&#039;&#039;&#039; &amp;lt;IP/HOSTNAME&amp;gt;&lt;br /&gt;
in your terminal. &lt;br /&gt;
&lt;br /&gt;
We&#039;ve already used &#039;&#039;&#039;wget&#039;&#039;&#039; in an earlier section to download datafiles, but here we&#039;ll go more into detail with some of its options. Essentially, &#039;&#039;&#039;wget&#039;&#039;&#039; allows you to download files from servers without being logged into that server. If you&#039;re using a MAC OS, &#039;&#039;&#039;wget&#039;&#039;&#039; won&#039;t work, but you can use &#039;&#039;&#039;curl&#039;&#039;&#039; instead.    &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;wget&#039;&#039;&#039; &amp;lt;URL&amp;gt; &lt;br /&gt;
will download files from the server specified by the URL, as long as it doesn&#039;t require any sort of login. You can try this out yourself for any URL, but the content of the files you download might seem a little strange, if all you&#039;re downloading is a website. Websites are written in &#039;html&#039;, a programming language you might not be familiar with. &lt;br /&gt;
&lt;br /&gt;
If you need to download a big file, you can run the download as a background process.&lt;br /&gt;
 Prompt$ -b &#039;&#039;&#039;wget&#039;&#039;&#039; &amp;lt;URL&amp;gt;&lt;br /&gt;
will download the URL as a background process, allowing you to do other work within the shell as you wait. &lt;br /&gt;
  &lt;br /&gt;
If you&#039;re download was interrupted for some reason, you can resume the download of the partially downloaded file using the &#039;&#039;&#039;c&#039;&#039;&#039; option&lt;br /&gt;
 Prompt$ -c &#039;&#039;&#039;wget&#039;&#039;&#039; &amp;lt;URL&amp;gt; &lt;br /&gt;
will resume the download of the file from the URL.  &lt;br /&gt;
&lt;br /&gt;
The command &#039;&#039;&#039;curl&#039;&#039;&#039; is quite similar to &#039;&#039;&#039;wget&#039;&#039;&#039;, there are some differences however. The difference are summed up nicely in this link [https://daniel.haxx.se/docs/curl-vs-wget.html Curl vs wget].&lt;br /&gt;
&lt;br /&gt;
Similar to &#039;&#039;&#039;wget&#039;&#039;&#039; you can download a file from a URL, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;curl&#039;&#039;&#039; &amp;lt;URL&amp;gt;&lt;br /&gt;
will download files from the server specified by the URL. &lt;br /&gt;
&lt;br /&gt;
Multiple files can be downloaded with the syntax,&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;curl&#039;&#039;&#039; http://website.{URL_1, URL_2, URL_3}.com &lt;br /&gt;
will download from the URLS; URL_1, URL_2 and URL_3.&lt;br /&gt;
&lt;br /&gt;
If you need to download a series of files,  &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;curl&#039;&#039;&#039; ftp://ftp.something.com/file[1-20].jpeg&lt;br /&gt;
will download the file[1-20]. Here we using the ftp protocol.  &lt;br /&gt;
&lt;br /&gt;
You can save the content of the URL to a specific file on your computer,&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;curl -o&#039;&#039;&#039; &amp;lt;FILE&amp;gt; &amp;lt;URL&amp;gt;&lt;br /&gt;
will download the content from the URL and save it as &amp;lt;FILE&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In networks, we distinguish between &#039;&#039;webpages&#039;&#039; and &#039;&#039;websites&#039;&#039;. A website is a URL that can contain a multitude webpages all under the same domain. So examples of a websites and webpage could be https://wikipedia.org and https://wikipedia.org/wiki/Elon_Musk respectively. Websites like Wikipedia, Netflix, Google etc., all have some server computer connected to the internet that provides informational data to clients. There are many other types of servers as well; Mail servers, data servers, FTP servers, proxy servers, chat servers etc.. If you&#039;re interested in these other types of servers you can read more about them by following this link, [https://www.webopedia.com/quick_ref/servers.asp Different server types]. &lt;br /&gt;
&lt;br /&gt;
We defined a &#039;server&#039; as a computer connected to a network that provides &#039;services&#039; to other computers, which essentially means that any computer could be made into a server. That being said, however, there are actually computers that are designed especially to be servers. These type of computers are called &#039;server computers&#039;. They have different different specs then normal computers and are designed to operate many clients to be operated simultaneously. They also typically have a lot of hardware redundancy; &#039;RAID disk systems&#039;, &#039;ECC memory&#039; and &#039;dual power supply, which ensure that if one part server breaks the server can continue working without crashing. However, a server doesn&#039;t have to be run by a server computer and you can just as well a run a server on a desktop computer. It really depends on the scale for which the server is going to be used. Finally, most servers do not use GUI (Graphical User interfaces) and can only be operated through CLI (Command line interface), which is one of the main reasons why you&#039;ve been learning to become efficient with CLI&#039;s. You might be wondering why don&#039;t servers use graphical user interfaces,  as it can&#039;t be that hard to implement and then you wouldn&#039;t have to take this course. There&#039;s actually a very good reason for this. Applications, hereunder graphical user interfaces, make servers more susceptible to security breaches, which could allow uninvited guests (hackers) inside the server. Hence, servers are normally designed to be as simple as possible, while also giving utility to the intended user.&lt;br /&gt;
&lt;br /&gt;
== Protocols and ports ==&lt;br /&gt;
IP addresses play a central role in connecting your computer to the internet and they ensure that your requests go to the right place while also ensuring that information is returned correctly. In order to make sure that you can access the internet efficiently, something called &#039;&#039;protocols&#039;&#039; is used. You don&#039;t need a deep understanding of protocols unless you&#039;re planning to become a web developer. Simply put, protocols are a standard set of rules that dictate how computers are to communicate efficiently across a network. A protocol that you&#039;re likely familiar with is &#039;http&#039;, short for &#039;hyper text transfer protocol&#039;,  which is the protocol that your browser uses for extracting data from a website. Protocols use something called ports, which you can think of as a door from which data can go out and in. There are 65535 ports in total, and port numbers ranging from 0-1023 are considered system ports which are the ones that the most common protocols use.  The port numbers typically used for HTTP, SMTP (Simple Mail Transfer Protocol) and FTP (File Transfer Protocol) are ports; 80, 25 and 21. Keep in mind, however, that there are alternative ports for most protocols, and you can in fact use any port number as long as it isn&#039;t assigned to another protocol. The port numbers ranging from 1024-65535 are called &#039;&#039;dynamic ports&#039;&#039; and they&#039;re usually assigned as needed. Exactly what &#039;assigned as needed&#039; means can be illustrated with an example. Imagine you&#039;ve connected to a web server through port 80 using the http protocol and you&#039;re waiting for the web server to respond and send you your data. If there are few people using the server, you might get this data sent back through port 80. However, if there are many using the server, port 80 might not be available. If this is the case, the web server will assign whatever port is available to send back the requested data. This type of assignation of ports is the most common use for &#039;&#039;dynamic ports&#039;&#039;, however, assignation of dynamic ports also happen when you install a new application that uses a dynamic port.  Let&#039;s get into how we can use commands like &#039;&#039;&#039;telnet&#039;&#039;&#039; and &#039;&#039;&#039;ssh&#039;&#039;&#039; to connect with servers. Till now, you&#039;ve likely only been connecting with remote servers through the use of browser applications like Google chrome, Mozilla Firefox, Safari, etc. &lt;br /&gt;
&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;telnet&#039;&#039;&#039; &amp;lt;URL&amp;gt; &amp;lt;PORT&amp;gt;&lt;br /&gt;
will connect you to the specified &amp;lt;URL&amp;gt; using the specified &amp;lt;PORT&amp;gt;. For example, you can connect to a gmail using the &#039;smtp&#039; protocol and port 465. &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;telnet&#039;&#039;&#039; smtp.gmail.com 465&lt;br /&gt;
Writing mails with &#039;&#039;&#039;telnet&#039;&#039;&#039; is technically possible but difficult to do and we won&#039;t be bothering with trying. Practically, &#039;&#039;&#039;telnet&#039;&#039;&#039; is mostly used to troubleshoot whether the connection of your computer to a server is working properly. &lt;br /&gt;
&lt;br /&gt;
The commands &#039;&#039;&#039;ssh&#039;&#039;&#039; and &#039;&#039;&#039;scp&#039;&#039;&#039;, short for secure shell and secure copy, are commands that establish secure connections to remote servers. The command &#039;&#039;&#039;ssh&#039;&#039;&#039; sets you up with a shell environment at remote server, allowing you to do work there. The command &#039;&#039;&#039;scp&#039;&#039;&#039;, allows you to copy files to and from a remote server. As a quick introduction, this tutorial tells you almost all you need to know about &#039;&#039;&#039;ssh&#039;&#039;&#039; and &#039;&#039;&#039;scp&#039;&#039;&#039;, [https://www.youtube.com/watch?v=rm6pewTcSro Tutorial video on using ssh and scp]. &lt;br /&gt;
&lt;br /&gt;
To establish a connection to a remote server in a secure shell environment with port 443, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;ssh -p443&#039;&#039;&#039; username@x.x.x.x &lt;br /&gt;
where &#039;username&#039; is the username you&#039;re using on the remote server with the IP address &#039;x.x.x.x&#039;. Port 443 is the port normally for &#039;secure web browser communication&#039;, and data transferred across this port highly resistant to interception. There&#039;s no specific reason to why we&#039;re using it here and it&#039;s just to show that you can specify with port you would like access remote servers with. &lt;br /&gt;
&lt;br /&gt;
To copy a file from a remote server to your device with port 443,  &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;scp -p443&#039;&#039;&#039; username@x.x.x.x:Directory/to/the/file/file.txt /mnt/c/Users/Username/Desktop/My_working_directory&lt;br /&gt;
where &#039;filepath/to/the/file/file.txt&#039; is filepath leading to the location of the file on the remote server and /mnt/c/Users/Username/Desktop/My_working_directory is filepath to where the file is copied to. &lt;br /&gt;
&lt;br /&gt;
Oppositely, you can copy a file from your device to the remote server with port 443, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;scp -p443&#039;&#039;&#039; /mnt/c/Users/Username/Desktop/My_working_directory/file.txt username@x.x.x.x:Directory/to/the/file&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
== From web server to your computer display (optional) ==&lt;br /&gt;
Here we give a explanation of exactly how information is transferred from a web server and displayed on your computer. Understanding this in detail is optional, and it&#039;s really just placed here for your curiosity. &lt;br /&gt;
&lt;br /&gt;
This link [https://www.youtube.com/watch?v=PpsEaqJV_A0 Introduction to protocols] will guide you to an introductory video on protocols. In the video, protocols are explained in layers and so to be consistent we&#039;ll do the same. There&#039;s also a small mistake in the video, as the &#039;SMTP&#039; (simple mail transfer protocol) is not used for checking mail but only for sending mail. For checking mail other protocols like POP (Post office protocol) and IMAP (Internet message access protocol) are used. ﻿&lt;br /&gt;
&lt;br /&gt;
[[File:Protocol_overview.png|right|frame|&#039;&#039;&#039;Figure 7.2 Using Protocols Overview:&#039;&#039;&#039; The figure shows how data is transferred to your screen display through the use of a web browser (in this case, Mozilla Firefox) and URL, while also showing how protocols; http, TCP, IP influence this transaction.]]&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Application layer (HTTP, SMTP, FTP) and ports&#039;&#039;&#039; &lt;br /&gt;
In the application layer, protocols like HTTP (Hyper text transfer protocol) receive data from the program that you&#039;re using. In the case of HTTP, the data would originate from your web browser, but in the case of SMTP the data would originate from a mail application. After having received the data from the program you&#039;re running, the application layer will send the data through a port to the TCP (Transmission control protocol). There are 65535 ports in total, and port numbers ranging from 0-1023 are considered system ports which are the ones that the most common protocols use.  Port number typically used for HTTP, SMTP and FTP are ports; 80, 25 and 21. Keep in mind, however, that there are alternative ports for almost every protocol, and you can in fact use any port number as long as it isn&#039;t assigned to another protocol.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Transport layer (TCP)&#039;&#039;&#039; &lt;br /&gt;
In the Transmission control protocol (TCP), the data received from the application layer is allocated into what&#039;s called &#039;packets&#039;, which you can think of as small bundles of data. By allocating the data into packets, this allows for the data to be transported as fast as possible to ultimately needs to go. For the data to be put back together properly after having arrived at its destination, TCP equips each packet with headers which contain instructions for how to put the packets together. First, however, these packets go through the internet protocol (IP).   &lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Internet layer (IP)&#039;&#039;&#039;  &lt;br /&gt;
The &#039;&#039;Internet Protocol&#039;&#039; (this is what the &#039;IP&#039; in &#039;IP address is short for) ensures addressing, delivering and routing your requests correctly. The packets that it receives from the transport layer are equipped with both origin and destination IP address. This ensure that the packets know where they need to go, and that the receiving device knows where the packets came from. Next, the packets go through the Network layer.  &lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Network layer&#039;&#039;&#039;&lt;br /&gt;
Among other things, the network layer handles &#039;Mac addressing&#039;, which ensures that the data from the packets are converted to electrical impulses and ensuring that they&#039;re delivered to the right device in the right places.  &lt;br /&gt;
&lt;br /&gt;
== Command list == &lt;br /&gt;
Here we present all the commands used in this section. &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Unix Command&lt;br /&gt;
!Acronym translation &lt;br /&gt;
!Description&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;wget&#039;&#039;&#039; [OPTION] &amp;lt;URL&amp;gt;&lt;br /&gt;
|web get&lt;br /&gt;
|A non-interactive network downloader used to download files located at the URL. &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;curl&#039;&#039;&#039; [OPTION] &amp;lt;URL&amp;gt;&lt;br /&gt;
|Client url&lt;br /&gt;
|Similarly to &#039;&#039;&#039;wget&#039;&#039;&#039;, it is used to download files at the specified URL. This is an alternative MAC OS users, where &#039;&#039;&#039;wget&#039;&#039;&#039; doesn&#039;t work. &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;ssh&#039;&#039;&#039;  &amp;lt;PORT&amp;gt; &amp;lt;user@IP/Domain_name&amp;gt;&lt;br /&gt;
|Secure shell &lt;br /&gt;
|Used to establish a secure connection to a remote server/system. It&#039;s also known as secure shell protocol.  &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;scp&#039;&#039;&#039; &amp;lt;PORT&amp;gt; &amp;lt;user@IP/Domain_name&amp;gt; &amp;lt;user@IP/Domain_name&amp;gt; &lt;br /&gt;
|Secure copy protocol&lt;br /&gt;
|Starts a secure copy protocol, which copies files securely across from remote networks to clients or from clients to remote networks. &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;telnet&#039;&#039;&#039; &amp;lt;URL&amp;gt; &amp;lt;PORT&amp;gt;&lt;br /&gt;
|Teletype network&lt;br /&gt;
|Establishes a connection with the specified URL and port. &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;ifconfig&#039;&#039;&#039; [OPTION]&lt;br /&gt;
|Interface configuration&lt;br /&gt;
|Displays currently active networks but when used with &#039;&#039;&#039;a&#039;&#039;&#039;, it displays the status of all networks.&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;nslookup&#039;&#039;&#039; [OPTION]&lt;br /&gt;
|Name server lookup&lt;br /&gt;
|Used to obtain information about a server through a DNS (Domain name system) server. &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;ping&#039;&#039;&#039; [OPTION] &amp;lt;IP/URL&amp;gt;&lt;br /&gt;
|Packet Internet Groper&lt;br /&gt;
|Checks network connectivity between host (your computer) and host/server.  &lt;br /&gt;
|}&lt;br /&gt;
 &lt;br /&gt;
== Exercises 1: Using ssh and scp ==&lt;br /&gt;
In order to use the commands &#039;&#039;&#039;ssh and scp&#039;&#039;&#039; you need to actually have a remote server you can try it on. You can create a SSH server on your local server (so on your own computer), and although this is hardly a remote server this will allow you to try the commands &#039;&#039;&#039;ssh and scp&#039;&#039;&#039;. For windows users, this require a couple more steps. &lt;br /&gt;
&lt;br /&gt;
* For windows users&lt;br /&gt;
First make sure ubuntu is updated,&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sudo apt-get update&#039;&#039;&#039; &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sudo apt-get upgrade&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
Then install ssh client and server, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sudo apt-get openssh-client&#039;&#039;&#039;&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sudo apt-get install openssh-server&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
You should now be able to start a ssh server,&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sudo service ssh start&#039;&#039;&#039;&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;ps -A&#039;&#039;&#039; &lt;br /&gt;
You should be able the daemon process, &#039;sshd&#039;, up and running. You can stop it again by typing, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sudo service ssh stop&#039;&#039;&#039;&lt;br /&gt;
* For Mac users &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;systemsetup -setremotelogin on&#039;&#039;&#039;&lt;br /&gt;
You should now be able to start a ssh server,&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sudo service ssh start&#039;&#039;&#039;&lt;br /&gt;
You can view check if the ssh server is up on and running with, &#039;&#039;&#039;ps -A&#039;&#039;&#039;, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;ps -A&#039;&#039;&#039; &lt;br /&gt;
where you should be able the daemon process, &#039;sshd&#039;, up and running. You can stop it again by typing, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sudo service ssh stop&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
By default the port number that your ssh server uses, is port number 22. You can, however, change this by going to the file &amp;lt;ssh_config&amp;gt;&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sudo vim&#039;&#039;&#039; /etc/ssh/ssh_config&lt;br /&gt;
&lt;br /&gt;
# Now that you&#039;re setup with an ssh server, start it and connect with &#039;&#039;&#039;ssh&#039;&#039;&#039; (whenever you want to exit the remote server, simply type &#039;&#039;&#039;exit&#039;&#039;&#039; in the command prompt).&lt;br /&gt;
# Copy any file from your computer to somewhere on the server.&lt;br /&gt;
# Copy any file from the remote server to your home directory.&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/unix/index.php?title=File:Network_LAN%26WAN.png&amp;diff=59</id>
		<title>File:Network LAN&amp;WAN.png</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/unix/index.php?title=File:Network_LAN%26WAN.png&amp;diff=59"/>
		<updated>2024-03-20T12:19:30Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/unix/index.php?title=Understanding_network_and_remote_servers:_IP/URL,_ssh,_scp,_wget,_curl&amp;diff=58</id>
		<title>Understanding network and remote servers: IP/URL, ssh, scp, wget, curl</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/unix/index.php?title=Understanding_network_and_remote_servers:_IP/URL,_ssh,_scp,_wget,_curl&amp;diff=58"/>
		<updated>2024-03-20T12:18:42Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: Created page with &amp;quot;__NOTOC__ In computing, a network is simply a network consisting of computers and other devices; routers, gateways, modems etc.. These computers are either desktop pc&amp;#039;s, which is the type that you&amp;#039;re using, or they&amp;#039;re server computers. The internet in its entirety is in fact an example of humongous network of global proportions, so as a short introduction, watch this short and simple video explaining the internet [https://www.youtube.com/watch?v=7_LPdttKXPc What&amp;#039;s the in...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
In computing, a network is simply a network consisting of computers and other devices; routers, gateways, modems etc.. These computers are either desktop pc&#039;s, which is the type that you&#039;re using, or they&#039;re server computers. The internet in its entirety is in fact an example of humongous network of global proportions, so as a short introduction, watch this short and simple video explaining the internet [https://www.youtube.com/watch?v=7_LPdttKXPc What&#039;s the internet]. &lt;br /&gt;
&lt;br /&gt;
Computers and other devices within the internet have addresses called IP addresses that have the syntax x.x.x.x, where x is a number between 0 and 255. There are 2 types of IP addresses; private and public. The difference is in what numbers are used. Private IP address are &#039;private&#039;, which just means that they&#039;re not directly connected to the internet. You can check your computers IP by typing, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;ifconfig&#039;&#039;&#039; &lt;br /&gt;
which will display information on the IP addresses currently in use by your computer. For windows users, your IP address should be under &#039;wifi0&#039; or &#039;eth0&#039;. The terms &#039;wifi0&#039; and &#039;eth0&#039; mean that you&#039;re connected to the internet via wifi and LAN cable respectively. For Mac users it should be one of the IP addresses next to &#039;&#039;inet&#039;&#039;. The &#039;lo: inet 127.0.0.1&#039; is your machines loopback address and is not your private IP address. For more information on finding your IP address on a MAC, you can follow this link [http://osxdaily.com/2010/11/21/find-ip-address-mac/ Finding your IP address on Mac OS]. &lt;br /&gt;
&lt;br /&gt;
Public IP addresses connect you with the rest of the internet. Typically, public IP addresses belong to a modem/router, which you can simply think of as a frontline device that connects all of your private devices to the rest of internet. Devices that are connected to the same modem, will all share the same public IP address and because public IP addresses are &#039;public&#039; they must be unique. This is not the case for private IP addresses, because they aren&#039;t directly connected to the internet. The term for a network consisting of public IP addresses is called &#039;World Area Network&#039; (WAN), which is represented  with a &amp;lt;span style=&amp;quot;color:#ff0000&amp;quot;&amp;gt;&#039;&#039;&#039;red&#039;&#039;&#039;&amp;lt;/span&amp;gt; line in &#039;&#039;&#039;figure 7.1&#039;&#039;&#039;. Just so you know, &#039;&#039;&#039;figure 7.1&#039;&#039;&#039; has been simplified so that the router for the server computers aren&#039;t included. &lt;br /&gt;
You can look up your public IP address by following this link [https://whatismyipaddress.com/ Public IP address]. But you can also find your public IP address by using &#039;&#039;&#039;wget&#039;&#039;&#039;,&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;wget&#039;&#039;&#039; -qO- ifconfig.me&lt;br /&gt;
The command option &#039;&#039;&#039;q&#039;&#039;&#039; is short for quiet mode, and -O- ensures that the output is written to stdout. The Mac OS is not equipped with &#039;&#039;&#039;wget&#039;&#039;&#039; by default, but you can instead use the command &#039;&#039;&#039;curl&#039;&#039;&#039;, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;curl&#039;&#039;&#039; ifconfig.me &lt;br /&gt;
&lt;br /&gt;
You shouldn&#039;t get too attached to your IP addresses, as they can easily change. IP addresses are determined by your internet service provider (ISP), hence, it&#039;ll change depending on the WiFi you&#039;re logged onto, when you unplug and replug your router or perhaps if your ISP decides to change it. &lt;br /&gt;
&lt;br /&gt;
We briefly mentioned something about using a LAN cable, but we haven&#039;t defined what LAN is. LAN is short for &#039;Local Area Network (LAN)&#039;, and you can think of it as the network connecting your private devices. In &#039;&#039;&#039;figure 7.1&#039;&#039;&#039;, this is depicted as the devices connected by the &amp;lt;span style=&amp;quot;color:#00ff00&amp;quot;&amp;gt;&#039;&#039;&#039;green&#039;&#039;&#039;&amp;lt;/span&amp;gt; line; printer, phone and computer. The device that allocates private IP addresses to your &#039;private devices&#039; while also establishing connectivity between these devices, is your router. Often, it is the case that the modem and router are combined into one device, which is how it&#039;s illustrated in &#039;&#039;&#039;figure 7.1&#039;&#039;&#039;. For more information on the difference between router and modem, follow this link [https://www.howtogeek.com/234233/whats-the-difference-between-a-modem-and-a-router/ Modem vs router]&lt;br /&gt;
&lt;br /&gt;
The IP addresses we&#039;ve been discussing so far are IPv4 addresses. The amount of possible IPv4 addresses is approximately 4.3 billion, which was a sufficient amount for some time. However, it very quickly became clear that it wasn&#039;t, therefore, the next version of IP addresses, IPv6, has 7.9x10^28 as many IP addresses as IPv4. &lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
[[File:Network_LAN&amp;amp;WAN.png|center|frame|&#039;&#039;&#039;Figure 7.1 Network Overview:&#039;&#039;&#039; This figure gives an overview of a network and distinguishes between LAN (&amp;lt;span style=&amp;quot;color:#00ff00&amp;quot;&amp;gt;&#039;&#039;&#039;green&#039;&#039;&#039;&amp;lt;/span&amp;gt;) and WAN (&amp;lt;span style=&amp;quot;color:#ff0000&amp;quot;&amp;gt;&#039;&#039;&#039;red&#039;&#039;&#039;&amp;lt;/span&amp;gt;). The modem connects private devices within the same network to the internet, while the router connects devices within the LAN. Servers don&#039;t necessarily need to be run by a server computer and can also be run by a desktop computer.]]&lt;br /&gt;
&lt;br /&gt;
== Servers and URLS == &lt;br /&gt;
A &#039;server&#039; is simply a computer connected to a network that provides &#039;services&#039; to other computers. The computers that the server provides services for are called &#039;&#039;clients&#039;&#039;. This kind of relationship between servers and clients is what&#039;s defined as the &#039;client-server model&#039;. &lt;br /&gt;
&lt;br /&gt;
A simple example of a server that you&#039;re likely familiar with are print servers. Print servers are servers that provide the service of printing for computers connected to the same network. In a &#039;client-server model&#039;, the connected computers are the clients and the print server is the server. A print server would typically be what&#039;s called a &#039;local server&#039;. Servers can be distinguished into local and remote servers, the only difference being that local servers are setup to be within a LAN (so within the green lines in &#039;&#039;&#039;figure 7.1&#039;&#039;&#039;) and remote servers are setup on another &#039;remote computer&#039; (the servers connected by the red line in &#039;&#039;&#039;figure 7.1&#039;&#039;&#039;). It goes without saying, that remote servers are found everywhere on the internet, because that&#039;s largely what the internet is made of. There are different type of servers, but you&#039;re probably most familiar with web servers like (wikipedia, google, youtube, facebook etc..). Web servers are available to clients through the use of a web browser (Google Chrome, Internet Explorer etc.) and a URL, which is likely the only way you&#039;ve been accessing them up till now. You can, however, also interact with them in a little more &#039;old school way&#039; through the command line interface. For example, in the section &#039;Standard streams and working with files&#039;, we used &#039;&#039;&#039;wget&#039;&#039;&#039; to retrieve files from URLS. &lt;br /&gt;
&lt;br /&gt;
URL is short for &#039;Uniform resource locator&#039;, and they&#039;re are used to identify websites. A URL consists of several parts; &#039;protocol&#039;, &#039;sub domain&#039;, &#039;second level domain&#039;, &#039;top level domain&#039;, &#039;directory/folder&#039;, &#039;filename/webpage&#039;, and &#039;file extension&#039;. Let&#039;s go through what each part represents by using a wikipedia URL as an example.&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#ff0000&amp;quot;&amp;gt;&#039;&#039;&#039;https&#039;&#039;&#039;&amp;lt;/span&amp;gt;&#039;&#039;&#039;://&#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:#ff00ff&amp;quot;&amp;gt;&#039;&#039;&#039;en&#039;&#039;&#039;&amp;lt;/span&amp;gt;&#039;&#039;&#039;.&#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:#00ff00&amp;quot;&amp;gt;&#039;&#039;&#039;wikipedia&#039;&#039;&#039;&amp;lt;/span&amp;gt;&#039;&#039;&#039;.&#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:#ffff00&amp;quot;&amp;gt;&#039;&#039;&#039;org&#039;&#039;&#039;&amp;lt;/span&amp;gt;&#039;&#039;&#039;/&#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:#0000ff&amp;quot;&amp;gt;&#039;&#039;&#039;wiki&#039;&#039;&#039;&amp;lt;/span&amp;gt;&#039;&#039;&#039;/&#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:#008080&amp;quot;&amp;gt;&#039;&#039;&#039;Elon_Musk&#039;&#039;&#039;&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;span style=&amp;quot;color:#ff0000&amp;quot;&amp;gt;&#039;&#039;&#039;https&#039;&#039;&#039;&amp;lt;/span&amp;gt; --&amp;gt; protocol.&lt;br /&gt;
*&amp;lt;span style=&amp;quot;color:#ff00ff&amp;quot;&amp;gt;&#039;&#039;&#039;en&#039;&#039;&#039;&amp;lt;/span&amp;gt; --&amp;gt; subdomain.&lt;br /&gt;
*&amp;lt;span style=&amp;quot;color:#00ff00&amp;quot;&amp;gt;&#039;&#039;&#039;wikipedia&#039;&#039;&#039;&amp;lt;/span&amp;gt; --&amp;gt; second level domain.&lt;br /&gt;
*&amp;lt;span style=&amp;quot;color:#ffff00&amp;quot;&amp;gt;&#039;&#039;&#039;org&#039;&#039;&#039;&amp;lt;/span&amp;gt; --&amp;gt; top level domain.&lt;br /&gt;
*&amp;lt;span style=&amp;quot;color:#0000ff&amp;quot;&amp;gt;&#039;&#039;&#039;wiki&#039;&#039;&#039;&amp;lt;/span&amp;gt; --&amp;gt; folder/directory.&lt;br /&gt;
*&amp;lt;span style=&amp;quot;color:#008080&amp;quot;&amp;gt;&#039;&#039;&#039;Elon_Musk&#039;&#039;&#039;&amp;lt;/span&amp;gt; --&amp;gt; webpage.&lt;br /&gt;
&lt;br /&gt;
The protocol used is &amp;lt;span style=&amp;quot;color:#ff0000&amp;quot;&amp;gt;&#039;&#039;&#039;https&#039;&#039;&#039;&amp;lt;/span&amp;gt; short for &#039;Hypertext Transfer Protocol Secure&#039;. This is the protocol that your computer uses to retrieve data securely from your browser (google chrome, internet explorer etc.) corresponding to the URL. Protocols are a different topic, and we&#039;ll talk more about that later. Before &#039;https&#039;, the protocol used was &#039;http&#039; but due to problems with data insecurity, there&#039;s a gradual increase in the use of the &#039;https&#039; protocol. In short, &#039;https&#039; ensures that the data received from your browser is encrypted and you can read more about this by following this link [https://www.entrepreneur.com/article/281633]. But not all websites use it, for instance, this very website is using the &#039;http&#039; protocol for interaction with browsers.&amp;lt;br&amp;gt; &lt;br /&gt;
Following &#039;https&#039;, there can be a subdomain and in this case it&#039;s &amp;lt;span style=&amp;quot;color:#ff00ff&amp;quot;&amp;gt;&#039;&#039;&#039;en&#039;&#039;&#039;&amp;lt;/span&amp;gt;. The subdomain can be called just about anything but the most commonly used is &#039;www&#039;. You don&#039;t actually have to add a subdomain but  what&#039;s important, is that one of the 2 URLS, one with a subdomain and the one without, redirects to the other in order to avoid duplicate versions of the URL. For example, if you write &#039;https://wikipedia.org/wiki/Elon_Musk&#039; in your browser, you will be redirected to &#039;https://en.wikipedia.org/wiki/Elon_Musk&#039;. Next, &amp;lt;span style=&amp;quot;color:#00ff00&amp;quot;&amp;gt;&#039;&#039;&#039;wikipedia&#039;&#039;&#039;&amp;lt;/span&amp;gt; is the second level domain. Along with the top level domain, the second level domain make up the domain name of URL which is what makes the URL unique. The top level domain in this URL is &amp;lt;span style=&amp;quot;color:#ffff00&amp;quot;&amp;gt;&#039;&#039;&#039;org&#039;&#039;&#039;&amp;lt;/span&amp;gt;, which is short for organization. A more commonly used top level domain you&#039;re  familiar with is &#039;com&#039;, short for commercial. The folder/directory is &amp;lt;span style=&amp;quot;color:#0000ff&amp;quot;&amp;gt;&#039;&#039;&#039;wiki&#039;&#039;&#039;&amp;lt;/span&amp;gt;. This is followed by the webpage &amp;lt;span style=&amp;quot;color:#008080&amp;quot;&amp;gt;&#039;&#039;&#039;Elon Musk&#039;&#039;&#039;&amp;lt;/span&amp;gt;. In this case, there&#039;s no file extension but in previous sections we&#039;ve been using URL&#039;s, http://teaching.bioinformatics.dtu.dk/material/36610/ex1.acc,  where the filename is &#039;ex1&#039; and the file extension is &#039;acc&#039;.   &lt;br /&gt;
&lt;br /&gt;
You can find the IP address of a domain, by using the command &#039;&#039;&#039;nslookup&#039;&#039;&#039;,&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;nslookup&#039;&#039;&#039; &amp;lt;Domain_name&amp;gt;&lt;br /&gt;
would output the IP address along with some additional information to your terminal. For example, if you typed &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;nslookup&#039;&#039;&#039; wikipedia.org&lt;br /&gt;
you would get the IP address 91.198.174.192. The command, &#039;&#039;&#039;nslookup&#039;&#039;&#039;, actually receives this information from what&#039;s called DNS (Domain name system) servers. DNS servers are simply systems that store URL&#039;s with their corresponding IP addresses, ensuring that you&#039;re brought to the right IP address when you use a URL.  &lt;br /&gt;
&lt;br /&gt;
Another useful command is  &#039;&#039;&#039;ping&#039;&#039;&#039;, which is used to check network connectivity between host (your computer) and another host or server. In simple terms, it sends a data packet to the specified IP or URL with the message &amp;quot;PING&amp;quot; and waits for a response. The response time from the host/server is called latency. High latency and slow ping are what causes &#039;lagging&#039; in online computer games or maybe just some really slow websites. Conversely, low latency and fast pings ensure enjoyable gaming and web browsing. You can check the ping of a website by typing, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;ping&#039;&#039;&#039; &amp;lt;IP/HOSTNAME&amp;gt;&lt;br /&gt;
in your terminal. &lt;br /&gt;
&lt;br /&gt;
We&#039;ve already used &#039;&#039;&#039;wget&#039;&#039;&#039; in an earlier section to download datafiles, but here we&#039;ll go more into detail with some of its options. Essentially, &#039;&#039;&#039;wget&#039;&#039;&#039; allows you to download files from servers without being logged into that server. If you&#039;re using a MAC OS, &#039;&#039;&#039;wget&#039;&#039;&#039; won&#039;t work, but you can use &#039;&#039;&#039;curl&#039;&#039;&#039; instead.    &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;wget&#039;&#039;&#039; &amp;lt;URL&amp;gt; &lt;br /&gt;
will download files from the server specified by the URL, as long as it doesn&#039;t require any sort of login. You can try this out yourself for any URL, but the content of the files you download might seem a little strange, if all you&#039;re downloading is a website. Websites are written in &#039;html&#039;, a programming language you might not be familiar with. &lt;br /&gt;
&lt;br /&gt;
If you need to download a big file, you can run the download as a background process.&lt;br /&gt;
 Prompt$ -b &#039;&#039;&#039;wget&#039;&#039;&#039; &amp;lt;URL&amp;gt;&lt;br /&gt;
will download the URL as a background process, allowing you to do other work within the shell as you wait. &lt;br /&gt;
  &lt;br /&gt;
If you&#039;re download was interrupted for some reason, you can resume the download of the partially downloaded file using the &#039;&#039;&#039;c&#039;&#039;&#039; option&lt;br /&gt;
 Prompt$ -c &#039;&#039;&#039;wget&#039;&#039;&#039; &amp;lt;URL&amp;gt; &lt;br /&gt;
will resume the download of the file from the URL.  &lt;br /&gt;
&lt;br /&gt;
The command &#039;&#039;&#039;curl&#039;&#039;&#039; is quite similar to &#039;&#039;&#039;wget&#039;&#039;&#039;, there are some differences however. The difference are summed up nicely in this link [https://daniel.haxx.se/docs/curl-vs-wget.html Curl vs wget].&lt;br /&gt;
&lt;br /&gt;
Similar to &#039;&#039;&#039;wget&#039;&#039;&#039; you can download a file from a URL, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;curl&#039;&#039;&#039; &amp;lt;URL&amp;gt;&lt;br /&gt;
will download files from the server specified by the URL. &lt;br /&gt;
&lt;br /&gt;
Multiple files can be downloaded with the syntax,&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;curl&#039;&#039;&#039; http://website.{URL_1, URL_2, URL_3}.com &lt;br /&gt;
will download from the URLS; URL_1, URL_2 and URL_3.&lt;br /&gt;
&lt;br /&gt;
If you need to download a series of files,  &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;curl&#039;&#039;&#039; ftp://ftp.something.com/file[1-20].jpeg&lt;br /&gt;
will download the file[1-20]. Here we using the ftp protocol.  &lt;br /&gt;
&lt;br /&gt;
You can save the content of the URL to a specific file on your computer,&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;curl -o&#039;&#039;&#039; &amp;lt;FILE&amp;gt; &amp;lt;URL&amp;gt;&lt;br /&gt;
will download the content from the URL and save it as &amp;lt;FILE&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In networks, we distinguish between &#039;&#039;webpages&#039;&#039; and &#039;&#039;websites&#039;&#039;. A website is a URL that can contain a multitude webpages all under the same domain. So examples of a websites and webpage could be https://wikipedia.org and https://wikipedia.org/wiki/Elon_Musk respectively. Websites like Wikipedia, Netflix, Google etc., all have some server computer connected to the internet that provides informational data to clients. There are many other types of servers as well; Mail servers, data servers, FTP servers, proxy servers, chat servers etc.. If you&#039;re interested in these other types of servers you can read more about them by following this link, [https://www.webopedia.com/quick_ref/servers.asp Different server types]. &lt;br /&gt;
&lt;br /&gt;
We defined a &#039;server&#039; as a computer connected to a network that provides &#039;services&#039; to other computers, which essentially means that any computer could be made into a server. That being said, however, there are actually computers that are designed especially to be servers. These type of computers are called &#039;server computers&#039;. They have different different specs then normal computers and are designed to operate many clients to be operated simultaneously. They also typically have a lot of hardware redundancy; &#039;RAID disk systems&#039;, &#039;ECC memory&#039; and &#039;dual power supply, which ensure that if one part server breaks the server can continue working without crashing. However, a server doesn&#039;t have to be run by a server computer and you can just as well a run a server on a desktop computer. It really depends on the scale for which the server is going to be used. Finally, most servers do not use GUI (Graphical User interfaces) and can only be operated through CLI (Command line interface), which is one of the main reasons why you&#039;ve been learning to become efficient with CLI&#039;s. You might be wondering why don&#039;t servers use graphical user interfaces,  as it can&#039;t be that hard to implement and then you wouldn&#039;t have to take this course. There&#039;s actually a very good reason for this. Applications, hereunder graphical user interfaces, make servers more susceptible to security breaches, which could allow uninvited guests (hackers) inside the server. Hence, servers are normally designed to be as simple as possible, while also giving utility to the intended user.&lt;br /&gt;
&lt;br /&gt;
== Protocols and ports ==&lt;br /&gt;
IP addresses play a central role in connecting your computer to the internet and they ensure that your requests go to the right place while also ensuring that information is returned correctly. In order to make sure that you can access the internet efficiently, something called &#039;&#039;protocols&#039;&#039; is used. You don&#039;t need a deep understanding of protocols unless you&#039;re planning to become a web developer. Simply put, protocols are a standard set of rules that dictate how computers are to communicate efficiently across a network. A protocol that you&#039;re likely familiar with is &#039;http&#039;, short for &#039;hyper text transfer protocol&#039;,  which is the protocol that your browser uses for extracting data from a website. Protocols use something called ports, which you can think of as a door from which data can go out and in. There are 65535 ports in total, and port numbers ranging from 0-1023 are considered system ports which are the ones that the most common protocols use.  The port numbers typically used for HTTP, SMTP (Simple Mail Transfer Protocol) and FTP (File Transfer Protocol) are ports; 80, 25 and 21. Keep in mind, however, that there are alternative ports for most protocols, and you can in fact use any port number as long as it isn&#039;t assigned to another protocol. The port numbers ranging from 1024-65535 are called &#039;&#039;dynamic ports&#039;&#039; and they&#039;re usually assigned as needed. Exactly what &#039;assigned as needed&#039; means can be illustrated with an example. Imagine you&#039;ve connected to a web server through port 80 using the http protocol and you&#039;re waiting for the web server to respond and send you your data. If there are few people using the server, you might get this data sent back through port 80. However, if there are many using the server, port 80 might not be available. If this is the case, the web server will assign whatever port is available to send back the requested data. This type of assignation of ports is the most common use for &#039;&#039;dynamic ports&#039;&#039;, however, assignation of dynamic ports also happen when you install a new application that uses a dynamic port.  Let&#039;s get into how we can use commands like &#039;&#039;&#039;telnet&#039;&#039;&#039; and &#039;&#039;&#039;ssh&#039;&#039;&#039; to connect with servers. Till now, you&#039;ve likely only been connecting with remote servers through the use of browser applications like Google chrome, Mozilla Firefox, Safari, etc. &lt;br /&gt;
&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;telnet&#039;&#039;&#039; &amp;lt;URL&amp;gt; &amp;lt;PORT&amp;gt;&lt;br /&gt;
will connect you to the specified &amp;lt;URL&amp;gt; using the specified &amp;lt;PORT&amp;gt;. For example, you can connect to a gmail using the &#039;smtp&#039; protocol and port 465. &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;telnet&#039;&#039;&#039; smtp.gmail.com 465&lt;br /&gt;
Writing mails with &#039;&#039;&#039;telnet&#039;&#039;&#039; is technically possible but difficult to do and we won&#039;t be bothering with trying. Practically, &#039;&#039;&#039;telnet&#039;&#039;&#039; is mostly used to troubleshoot whether the connection of your computer to a server is working properly. &lt;br /&gt;
&lt;br /&gt;
The commands &#039;&#039;&#039;ssh&#039;&#039;&#039; and &#039;&#039;&#039;scp&#039;&#039;&#039;, short for secure shell and secure copy, are commands that establish secure connections to remote servers. The command &#039;&#039;&#039;ssh&#039;&#039;&#039; sets you up with a shell environment at remote server, allowing you to do work there. The command &#039;&#039;&#039;scp&#039;&#039;&#039;, allows you to copy files to and from a remote server. As a quick introduction, this tutorial tells you almost all you need to know about &#039;&#039;&#039;ssh&#039;&#039;&#039; and &#039;&#039;&#039;scp&#039;&#039;&#039;, [https://www.youtube.com/watch?v=rm6pewTcSro Tutorial video on using ssh and scp]. &lt;br /&gt;
&lt;br /&gt;
To establish a connection to a remote server in a secure shell environment with port 443, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;ssh -p443&#039;&#039;&#039; username@x.x.x.x &lt;br /&gt;
where &#039;username&#039; is the username you&#039;re using on the remote server with the IP address &#039;x.x.x.x&#039;. Port 443 is the port normally for &#039;secure web browser communication&#039;, and data transferred across this port highly resistant to interception. There&#039;s no specific reason to why we&#039;re using it here and it&#039;s just to show that you can specify with port you would like access remote servers with. &lt;br /&gt;
&lt;br /&gt;
To copy a file from a remote server to your device with port 443,  &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;scp -p443&#039;&#039;&#039; username@x.x.x.x:Directory/to/the/file/file.txt /mnt/c/Users/Username/Desktop/My_working_directory&lt;br /&gt;
where &#039;filepath/to/the/file/file.txt&#039; is filepath leading to the location of the file on the remote server and /mnt/c/Users/Username/Desktop/My_working_directory is filepath to where the file is copied to. &lt;br /&gt;
&lt;br /&gt;
Oppositely, you can copy a file from your device to the remote server with port 443, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;scp -p443&#039;&#039;&#039; /mnt/c/Users/Username/Desktop/My_working_directory/file.txt username@x.x.x.x:Directory/to/the/file&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
== From web server to your computer display (optional) ==&lt;br /&gt;
Here we give a explanation of exactly how information is transferred from a web server and displayed on your computer. Understanding this in detail is optional, and it&#039;s really just placed here for your curiosity. &lt;br /&gt;
&lt;br /&gt;
This link [https://www.youtube.com/watch?v=PpsEaqJV_A0 Introduction to protocols] will guide you to an introductory video on protocols. In the video, protocols are explained in layers and so to be consistent we&#039;ll do the same. There&#039;s also a small mistake in the video, as the &#039;SMTP&#039; (simple mail transfer protocol) is not used for checking mail but only for sending mail. For checking mail other protocols like POP (Post office protocol) and IMAP (Internet message access protocol) are used. ﻿&lt;br /&gt;
&lt;br /&gt;
[[File:Protocol_overview.png|right|frame|&#039;&#039;&#039;Figure 7.2 Using Protocols Overview:&#039;&#039;&#039; The figure shows how data is transferred to your screen display through the use of a web browser (in this case, Mozilla Firefox) and URL, while also showing how protocols; http, TCP, IP influence this transaction.]]&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Application layer (HTTP, SMTP, FTP) and ports&#039;&#039;&#039; &lt;br /&gt;
In the application layer, protocols like HTTP (Hyper text transfer protocol) receive data from the program that you&#039;re using. In the case of HTTP, the data would originate from your web browser, but in the case of SMTP the data would originate from a mail application. After having received the data from the program you&#039;re running, the application layer will send the data through a port to the TCP (Transmission control protocol). There are 65535 ports in total, and port numbers ranging from 0-1023 are considered system ports which are the ones that the most common protocols use.  Port number typically used for HTTP, SMTP and FTP are ports; 80, 25 and 21. Keep in mind, however, that there are alternative ports for almost every protocol, and you can in fact use any port number as long as it isn&#039;t assigned to another protocol.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Transport layer (TCP)&#039;&#039;&#039; &lt;br /&gt;
In the Transmission control protocol (TCP), the data received from the application layer is allocated into what&#039;s called &#039;packets&#039;, which you can think of as small bundles of data. By allocating the data into packets, this allows for the data to be transported as fast as possible to ultimately needs to go. For the data to be put back together properly after having arrived at its destination, TCP equips each packet with headers which contain instructions for how to put the packets together. First, however, these packets go through the internet protocol (IP).   &lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Internet layer (IP)&#039;&#039;&#039;  &lt;br /&gt;
The &#039;&#039;Internet Protocol&#039;&#039; (this is what the &#039;IP&#039; in &#039;IP address is short for) ensures addressing, delivering and routing your requests correctly. The packets that it receives from the transport layer are equipped with both origin and destination IP address. This ensure that the packets know where they need to go, and that the receiving device knows where the packets came from. Next, the packets go through the Network layer.  &lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Network layer&#039;&#039;&#039;&lt;br /&gt;
Among other things, the network layer handles &#039;Mac addressing&#039;, which ensures that the data from the packets are converted to electrical impulses and ensuring that they&#039;re delivered to the right device in the right places.  &lt;br /&gt;
&lt;br /&gt;
== Command list == &lt;br /&gt;
Here we present all the commands used in this section. &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Unix Command&lt;br /&gt;
!Acronym translation &lt;br /&gt;
!Description&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;wget&#039;&#039;&#039; [OPTION] &amp;lt;URL&amp;gt;&lt;br /&gt;
|web get&lt;br /&gt;
|A non-interactive network downloader used to download files located at the URL. &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;curl&#039;&#039;&#039; [OPTION] &amp;lt;URL&amp;gt;&lt;br /&gt;
|Client url&lt;br /&gt;
|Similarly to &#039;&#039;&#039;wget&#039;&#039;&#039;, it is used to download files at the specified URL. This is an alternative MAC OS users, where &#039;&#039;&#039;wget&#039;&#039;&#039; doesn&#039;t work. &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;ssh&#039;&#039;&#039;  &amp;lt;PORT&amp;gt; &amp;lt;user@IP/Domain_name&amp;gt;&lt;br /&gt;
|Secure shell &lt;br /&gt;
|Used to establish a secure connection to a remote server/system. It&#039;s also known as secure shell protocol.  &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;scp&#039;&#039;&#039; &amp;lt;PORT&amp;gt; &amp;lt;user@IP/Domain_name&amp;gt; &amp;lt;user@IP/Domain_name&amp;gt; &lt;br /&gt;
|Secure copy protocol&lt;br /&gt;
|Starts a secure copy protocol, which copies files securely across from remote networks to clients or from clients to remote networks. &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;telnet&#039;&#039;&#039; &amp;lt;URL&amp;gt; &amp;lt;PORT&amp;gt;&lt;br /&gt;
|Teletype network&lt;br /&gt;
|Establishes a connection with the specified URL and port. &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;ifconfig&#039;&#039;&#039; [OPTION]&lt;br /&gt;
|Interface configuration&lt;br /&gt;
|Displays currently active networks but when used with &#039;&#039;&#039;a&#039;&#039;&#039;, it displays the status of all networks.&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;nslookup&#039;&#039;&#039; [OPTION]&lt;br /&gt;
|Name server lookup&lt;br /&gt;
|Used to obtain information about a server through a DNS (Domain name system) server. &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;ping&#039;&#039;&#039; [OPTION] &amp;lt;IP/URL&amp;gt;&lt;br /&gt;
|Packet Internet Groper&lt;br /&gt;
|Checks network connectivity between host (your computer) and host/server.  &lt;br /&gt;
|}&lt;br /&gt;
 &lt;br /&gt;
== Exercises 1: Using ssh and scp ==&lt;br /&gt;
In order to use the commands &#039;&#039;&#039;ssh and scp&#039;&#039;&#039; you need to actually have a remote server you can try it on. You can create a SSH server on your local server (so on your own computer), and although this is hardly a remote server this will allow you to try the commands &#039;&#039;&#039;ssh and scp&#039;&#039;&#039;. For windows users, this require a couple more steps. &lt;br /&gt;
&lt;br /&gt;
* For windows users&lt;br /&gt;
First make sure ubuntu is updated,&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sudo apt-get update&#039;&#039;&#039; &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sudo apt-get upgrade&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
Then install ssh client and server, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sudo apt-get openssh-client&#039;&#039;&#039;&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sudo apt-get install openssh-server&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
You should now be able to start a ssh server,&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sudo service ssh start&#039;&#039;&#039;&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;ps -A&#039;&#039;&#039; &lt;br /&gt;
You should be able the daemon process, &#039;sshd&#039;, up and running. You can stop it again by typing, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sudo service ssh stop&#039;&#039;&#039;&lt;br /&gt;
* For Mac users &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;systemsetup -setremotelogin on&#039;&#039;&#039;&lt;br /&gt;
You should now be able to start a ssh server,&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sudo service ssh start&#039;&#039;&#039;&lt;br /&gt;
You can view check if the ssh server is up on and running with, &#039;&#039;&#039;ps -A&#039;&#039;&#039;, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;ps -A&#039;&#039;&#039; &lt;br /&gt;
where you should be able the daemon process, &#039;sshd&#039;, up and running. You can stop it again by typing, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sudo service ssh stop&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
By default the port number that your ssh server uses, is port number 22. You can, however, change this by going to the file &amp;lt;ssh_config&amp;gt;&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sudo vim&#039;&#039;&#039; /etc/ssh/ssh_config&lt;br /&gt;
&lt;br /&gt;
# Now that you&#039;re setup with an ssh server, start it and connect with &#039;&#039;&#039;ssh&#039;&#039;&#039; (whenever you want to exit the remote server, simply type &#039;&#039;&#039;exit&#039;&#039;&#039; in the command prompt).&lt;br /&gt;
# Copy any file from your computer to somewhere on the server.&lt;br /&gt;
# Copy any file from the remote server to your home directory.&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/unix/index.php?title=File:Ongoing_processes3.png&amp;diff=57</id>
		<title>File:Ongoing processes3.png</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/unix/index.php?title=File:Ongoing_processes3.png&amp;diff=57"/>
		<updated>2024-03-20T12:18:05Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/unix/index.php?title=File:Top_kill.png&amp;diff=56</id>
		<title>File:Top kill.png</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/unix/index.php?title=File:Top_kill.png&amp;diff=56"/>
		<updated>2024-03-20T12:17:34Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/unix/index.php?title=File:Ps_ef_command.png&amp;diff=55</id>
		<title>File:Ps ef command.png</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/unix/index.php?title=File:Ps_ef_command.png&amp;diff=55"/>
		<updated>2024-03-20T12:17:06Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/unix/index.php?title=Processes;_foreground_and_background,_ps,_top,_kill,_screen,_nohup_and_daemons&amp;diff=54</id>
		<title>Processes; foreground and background, ps, top, kill, screen, nohup and daemons</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/unix/index.php?title=Processes;_foreground_and_background,_ps,_top,_kill,_screen,_nohup_and_daemons&amp;diff=54"/>
		<updated>2024-03-20T12:16:30Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: Created page with &amp;quot;__NOTOC__  A process is simply the instance of a running program. Processes are a fundamental concept of Linux systems and we&amp;#039;ll start by discussing what can be termed as the life cycle of processes. This includes the concepts of parent and child processes and while going through this subject, we&amp;#039;ll also introduce some essential commands that allow us to view ongoing processes in our terminal. These commands are &amp;#039;&amp;#039;&amp;#039;ps&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;jobs&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;top&amp;#039;&amp;#039;&amp;#039;.  Next we discuss foregr...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__ &lt;br /&gt;
A process is simply the instance of a running program. Processes are a fundamental concept of Linux systems and we&#039;ll start by discussing what can be termed as the life cycle of processes. This includes the concepts of parent and child processes and while going through this subject, we&#039;ll also introduce some essential commands that allow us to view ongoing processes in our terminal. These commands are &#039;&#039;&#039;ps&#039;&#039;&#039;, &#039;&#039;&#039;jobs&#039;&#039;&#039; and &#039;&#039;&#039;top&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Next we discuss foreground and background processes and how processes can be managed practically using UNIX commands and operators. These commands include &#039;&#039;&#039;sleep&#039;&#039;&#039;, &#039;&#039;&#039;fg&#039;&#039;&#039;, &#039;&#039;&#039;bg&#039;&#039;&#039;, &#039;&#039;&#039;jobs&#039;&#039;&#039; and &#039;&#039;&#039;kill&#039;&#039;&#039;. The only new operator we&#039;ll be looking at is &#039;&#039;&#039;&amp;amp;&#039;&#039;&#039;, which is used to start a command as a background process. We&#039;ll be revising redirectional operators, &amp;lt;, &amp;gt; and taking a look at file descriptors. &lt;br /&gt;
&lt;br /&gt;
Lastly we go a bit more into detail with the &#039;SIGHUP&#039; signal. In short, this is a signal that is sent out when a terminal session is closed, which results in child processes being terminated. We&#039;ll discuss how one can make processes immune to the &#039;SIGHUP&#039; signal, so that processes can continue even after we&#039;ve closed the terminal. The commands introduced for this are &#039;&#039;&#039;screen&#039;&#039;&#039;, &#039;&#039;&#039;disown&#039;&#039;&#039; and &#039;&#039;&#039;nohup&#039;&#039;&#039;. Lastly we introduce the concept of daemon processes.          &lt;br /&gt;
&lt;br /&gt;
== Parent and child processes == &lt;br /&gt;
Processes are distinguished into parent, child and daemon processes, but for now we&#039;ll focus on parent and child processes. All processes have parent processes but not all parent processes have child processes. The relationship between the two is how you&#039;d imagine; a child process is derived/spawned from its parent process. When a process starts the execution of a new program, it first makes a copy process of itself. In Linux we call this &#039;forking&#039; and it is carried out by the system call fork(). You can think of system calls as an interface between applications and the kernel, where the shell is the intermediary translator between the two. The fork() is usually followed by a exec() system calls, which is what converts the child process into a new process.&lt;br /&gt;
&lt;br /&gt;
You can see the Linux processes currently running in your terminal by using the command &#039;&#039;&#039;ps&#039;&#039;&#039;, which is short for &#039;process status&#039;. &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;ps -ef&#039;&#039;&#039;&lt;br /&gt;
[[File:Ps ef command.png|none|frame|&#039;&#039;&#039;Figure 8.1:&#039;&#039;&#039; Parent and child processes. In columns 1-8 there are UID (User ID), PID (Process ID) , PPID (Parent process ID&#039;s), C (Processor Utilization), STIME (Start time), TTY (&#039;TeleTYpewriter&#039;), TIME (CPU Time) and CMD (the actual command). It&#039;s not important to remember what all these columns mean, as you can always figure this out by going to the man page for &#039;&#039;&#039;ps&#039;&#039;&#039;. But just know that you can display different columns depending on the options that you use with &#039;&#039;&#039;ps&#039;&#039;&#039;. ]]&lt;br /&gt;
&lt;br /&gt;
A process is a child process of another process, if its PPID (Parent process ID) is the same as that of the other processes PID (Process ID). By using different command options you can make &#039;&#039;&#039;ps&#039;&#039;&#039; display a lot of different column statistics on the processes running on your computer. You can often guess what the meaning of these columns are, but if you&#039;re in doubt you can always go to the man page for &#039;&#039;&#039;ps&#039;&#039;&#039;.  UID is short for &#039;user ID&#039; and in this case there are only two instances of users; root and goodboy. PID is short &#039;process IDS&#039; which are unique identification numbers, assigned to processes making it easier to target them. PPID is short for &#039;parent process IDS&#039; which unique identification number of a process&#039;s parent process. Recall, that UNIX commands are in fact small programs, which is why &#039;&#039;&#039;ps -ef&#039;&#039;&#039; appears as a process. Take note that the PPID for &#039;&#039;&#039;ps -ef&#039;&#039;&#039; is 4, which is the PID for &#039;&#039;&#039;-bash&#039;&#039;&#039;. This means that &#039;&#039;&#039;-bash&#039;&#039;&#039; is the parent process of &#039;&#039;&#039;ps -ef&#039;&#039;&#039;. The parent process for &#039;&#039;&#039;-bash&#039;&#039;&#039; is &#039;&#039;&#039;/init ro&#039;&#039;&#039;, which in turn has no parent processes. You can think of the &#039;&#039;init&#039;&#039; process as &#039;super parent process&#039;, which is the very first process to be run when you start/boot a unix computer. &#039;&#039;init&#039;&#039; should always have the PID 1. If a parent process terminates before it&#039;s child process, &#039;&#039;init&#039;&#039; will become the new parent of the child. For a more graphical view of this you can use the command &#039;&#039;&#039;pstree&#039;&#039;&#039;,&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;pstree&#039;&#039;&#039;&lt;br /&gt;
which displays a tree of parent and child processes. The &#039;&#039;init&#039;&#039; process should always be the starting node of this tree.&lt;br /&gt;
&lt;br /&gt;
== Foreground and background processes == &lt;br /&gt;
Processes can run in the foreground and background. Foreground processes is any command that you enter in the prompt, whereafter you have to wait for its completion before being able to enter a new command. Up till now you&#039;ve only been executing commands as foreground processes. Unlike foreground processes, when a background process has been executed you don&#039;t have to wait for its completion before being able to issue a new command. Any command can be run as a background process by typing a space and &#039;&amp;amp;&#039; after the command,  &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;&amp;lt;COMMAND&amp;gt; &amp;amp;&#039;&#039;&#039;&lt;br /&gt;
As an example, we use the command, &#039;&#039;&#039;sleep&#039;&#039;&#039;, which is essentially a pause command that does nothing for a specified amount of time,&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sleep 30 &amp;amp;&#039;&#039;&#039;&lt;br /&gt;
will create a pause of 30 seconds as a background process, which you can view with the &#039;&#039;&#039;ps&#039;&#039;&#039; command. Now try to run &#039;&#039;&#039;sleep&#039;&#039;&#039; as foreground process,&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sleep 60&#039;&#039;&#039;&lt;br /&gt;
which will create of pause of 60 seconds. To exit this pause you have two choices; Press &#039;&#039;&#039;Ctrl-c&#039;&#039;&#039; which will send a kill signal to any process running in foreground, terminating it immediately. This is a very effective and often used way to stop programs. You can instead press &#039;&#039;&#039;Ctrl-z&#039;&#039;&#039; to send a suspend signal to any process running in the foreground, pausing it immediately. If you chose the pause option you&#039;ll be able to see the process with &#039;&#039;&#039;ps ax&#039;&#039;&#039;, but its status will be T (Stopped). If you&#039;ve paused the process you can restart it as a background process or foreground process.  &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;bg&#039;&#039;&#039; %&amp;lt;job ID&amp;gt;&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;fg&#039;&#039;&#039; %&amp;lt;job ID&amp;gt;&lt;br /&gt;
which will restart the process as a background or foreground process respectively. Do NOT forget your suspended processes, as they use resources, even if they do not do anything. You can see job ID&#039;s of currently running background processes by executing, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;jobs&#039;&#039;&#039;&lt;br /&gt;
which displays a list of active jobs. Jobs can be defined as processes that are initiated in the shell interactively by you, the user.  Each job is assigned a job ID which the commands, &#039;&#039;&#039;bg&#039;&#039;&#039; and &#039;&#039;&#039;fg&#039;&#039;&#039;, use for targeting. &lt;br /&gt;
&lt;br /&gt;
You can terminate a background process by sending it to the foreground and then terminating it with &#039;&#039;&#039;Ctrl-c&#039;&#039;&#039;. But a more direct approach to terminating a background process is to use the &#039;&#039;&#039;kill&#039;&#039;&#039; command. It doesn&#039;t use job ID&#039;s and instead uses PID&#039;s, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;kill&#039;&#039;&#039; &amp;lt;PID&amp;gt; &lt;br /&gt;
will terminate the process with corresponding &amp;lt;PID&amp;gt;. The &#039;&#039;&#039;kill&#039;&#039;&#039; command can actually be used to send a multitude of signals to processes. You can see a list of all these different signals by using &#039;&#039;&#039;-l&#039;&#039;&#039; command line option, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;kill -l&#039;&#039;&#039; &lt;br /&gt;
By default the signal used by &#039;&#039;&#039;kill&#039;&#039;&#039; is the kill signal, &#039;SIGKILL&#039;, but you can also use &#039;&#039;&#039;kill&#039;&#039;&#039; to send a stop signal, &#039;SIGSTOP&#039;.&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;kill -19&#039;&#039;&#039; &amp;lt;PID&amp;gt;   &lt;br /&gt;
will send a stop signal to the process with corresponding &amp;lt;PID&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Lastly, an alternative command to &#039;&#039;&#039;ps&#039;&#039;&#039; is &#039;&#039;&#039;top&#039;&#039;&#039;, the difference being that &#039;&#039;&#039;top&#039;&#039;&#039; provides a continuous representation of ongoing processes with an interactive command mode and &#039;&#039;&#039;ps&#039;&#039;&#039; only provides a snapshot of current processes. By typing,  &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;top&#039;&#039;&#039; &lt;br /&gt;
an interactive command mode and columns containing statistics of ongoing processes is displayed. The meaning of the columns is listed herunder.  &lt;br /&gt;
* PID: Unique process id.&lt;br /&gt;
* PR: Priority of the task.&lt;br /&gt;
* VIRT: Total virtual memory.&lt;br /&gt;
* USER: User name of owner.&lt;br /&gt;
* %CPU: CPU usage.&lt;br /&gt;
* TIME+: CPU Time,  similar to ‘TIME’.&lt;br /&gt;
* SHR: Shared Memory size (kb).&lt;br /&gt;
* NI: Nice Value. A negative nice value implies high priority and a positive nice value implies a low priority.&lt;br /&gt;
* %MEM: Memory usage.&lt;br /&gt;
&lt;br /&gt;
You can exit the interactive command mode of &#039;&#039;&#039;top&#039;&#039;&#039; by pressing q. You can use the kill utility by pressing k while in the interactive command mode. You will then be prompted to enter which PID you want to send a signal to, whereafter you&#039;ll be prompted to enter what kind of signal you&#039;d like to send. By default this is the the kill signal, so if you don&#039;t enter any signal type and simply press enter, a kill signal will be sent. In &#039;&#039;&#039;figure 8.2&#039;&#039;&#039; a kill signal is being sent to the process with the PID, 24, from the &#039;&#039;&#039;top&#039;&#039;&#039; interactive command mode.     &lt;br /&gt;
&lt;br /&gt;
[[File:top kill.png|frame|none|&#039;&#039;&#039;Figure 8.2 The top command:&#039;&#039;&#039; The &#039;&#039;&#039;top&#039;&#039;&#039; command displays a continuous representation of ongoing processes. In this representation, we enter the kill utility by pressing k, whereafter we&#039;re prompted for a the PID we would like to send a signal to. In this case, we enter the PID, 24. Afterwards we&#039;ll be prompted for the signal type. By default this is the kill signal, so by entering nothing and a kill signal will be sent.]]&lt;br /&gt;
&lt;br /&gt;
== File descriptors == &lt;br /&gt;
When you a open a file on your computer, your operating system will create an entry wherein information for that file can be stored. These entries have an entry number, which can be any positive integer (6,7,12,301 etc.) and this number is what&#039;s called a file descriptor. Standard input, standard output and standard error are also thought of as files in Unix, and they therefore also have file descriptors. These are by default always set to 0, 1 and 2 for stdin, stout and stderror respectively. You can actually find these files on your system by going to the device directory. &lt;br /&gt;
 Prompt$ cd /dev &lt;br /&gt;
&lt;br /&gt;
== Redirecting outputs and providing necessary stdin for background processes == &lt;br /&gt;
If a command requires additional stdin from the user or has some output, it will cause problems if it&#039;s run as a background process. If a program run in the background requires additional stdin and doesn&#039;t receive it, the program will suspend and wait for infinity for the input. Furthermore, stdout and stderror from a background process needs to be redirected to somewhere else than the terminal. For example, when installing packages with &#039;&#039;&#039;apt&#039;&#039;&#039; there&#039;s a continuous stream of output regardless of whether it&#039;s run in the background or foreground. While this is being outputted we cannot continue working with other stuff in the terminal, which ruins the point of background processes.  &lt;br /&gt;
&lt;br /&gt;
So in order to run a program as a background process, you often need to redirect stdout and stderror to somewhere else, which can be done by using file descriptors. &lt;br /&gt;
 Prompt$ &amp;lt;COMMAND&amp;gt; &amp;gt; &amp;lt;output_file&amp;gt; &#039;&#039;&#039;2&amp;gt;&#039;&#039;&#039; &amp;lt;error_file&amp;gt; &#039;&#039;&#039;&amp;amp;&#039;&#039;&#039; &lt;br /&gt;
In this command, stdout and stderror from &#039;&#039;&#039;Unix command&#039;&#039;&#039; is redirected to two separate files. By default, the &#039;&#039;&#039;&amp;gt;&#039;&#039;&#039; operator redirects stdout, which is why we only have to write &#039;&#039;&#039;&amp;gt;&#039;&#039;&#039;.&lt;br /&gt;
If we don&#039;t care about the stdout and stderror we can redirect to what&#039;s called the &#039;&#039;null device&#039;&#039;. &lt;br /&gt;
 Prompt$ &amp;lt;COMMAND&amp;gt; &amp;gt; /dev/null &#039;&#039;&#039;2&amp;gt;&amp;amp;1 &amp;amp;&#039;&#039;&#039; &lt;br /&gt;
In this command, the stdout is used to redirect to &#039;/dev/null&#039; with &#039;&#039;&#039;&amp;gt;&#039;&#039;&#039;, and the stderror is redirected, &#039;&#039;&#039;2&amp;gt;&#039;&#039;&#039;, to the same place as the stdout, &#039;&#039;&#039;&amp;amp;1&#039;&#039;&#039;. Alternatively, you could have also typed, &lt;br /&gt;
 Prompt$ &amp;lt;COMMAND&amp;gt; &amp;gt; /dev/null &#039;&#039;&#039;2&amp;gt;&#039;&#039;&#039; /dev/null &#039;&#039;&#039;&amp;amp;&#039;&#039;&#039;&lt;br /&gt;
which will also redirect both stdout and stderror to the null device. If it helps, think of the null device as a black hole where we send data we don&#039;t need. &lt;br /&gt;
&lt;br /&gt;
We&#039;ve dealt with the problem of redirecting stdout and stderror, but we still have to deal with the stdin. For instance, in the last section were we used &#039;&#039;&#039;apt&#039;&#039;&#039; to install packages, we needed to type in &#039;y&#039; for installation of a package to continue. A solution to this, is simply to use the &#039;&#039;&#039;y&#039;&#039;&#039; option as shown in the last section. &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sudo apt -y install&#039;&#039;&#039; &amp;lt;PACKAGE&amp;gt; &#039;&#039;&#039;&amp;gt;&#039;&#039;&#039; /dev/null &#039;&#039;&#039;2&amp;gt;&amp;amp;1 &amp;amp;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This command, will install &amp;lt;PACKAGE&amp;gt; without asking for the additional &#039;y&#039; confirmation and will direct all output to &#039;/dev/null&#039;. There might, however, not always be an option like the &#039;&#039;&#039;y&#039;&#039;&#039; option. Therefore, we show another method where we use &#039;&#039;&#039;echo&#039;&#039;&#039; to pipe the stdin you need,   &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;echo&#039;&#039;&#039; &#039;Your_stdin&#039; &#039;&#039;&#039;|&#039;&#039;&#039; &#039;&#039;&#039;sudo apt install&#039;&#039;&#039; &amp;lt;PACKAGE&amp;gt; &#039;&#039;&#039;&amp;gt;&#039;&#039;&#039; /dev/null &#039;&#039;&#039;2&amp;gt;&amp;amp;1 &amp;amp;&#039;&#039;&#039;&lt;br /&gt;
Also, you could create an &amp;lt;inputfile&amp;gt; and use redirectional operator for stdin, &#039;&#039;&#039;&amp;lt;&#039;&#039;&#039;, to feed its contents.  &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sudo apt install&#039;&#039;&#039; &amp;lt;PACKAGE&amp;gt; &#039;&#039;&#039;&amp;lt;&#039;&#039;&#039; &amp;lt;inputfile&amp;gt;  &#039;&#039;&#039;&amp;gt;&#039;&#039;&#039; /dev/null &#039;&#039;&#039;2&amp;gt;&amp;amp;1 &amp;amp;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
When you use &#039;&#039;&#039;sudo&#039;&#039;&#039; you&#039;ll be prompted to enter your password, which will grant you root privileges for 15 minutes. In these 15 minutes you won&#039;t be prompted again for your password when executing commands that require root privileges. If you run a command that requires root privileges as a background process while output is redirected to /dev/null and you don&#039;t have root privileges, the process will stop. The simplest solution to this problem is to run another command with root privileges prior to running your background process. It doesn&#039;t matter what command you use to acquire these root privileges, it could for example be &#039;&#039;&#039;ls&#039;&#039;&#039;,   &lt;br /&gt;
 Prompt$ sudo ls&lt;br /&gt;
 Prompt$ sudo &amp;lt;COMMAND&amp;gt; &amp;gt; dev/null &#039;&#039;&#039;2&amp;gt;&amp;amp;1&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
You could also utilize the fact that &#039;&#039;&#039;sudo&#039;&#039;&#039; by default doesn&#039;t read passwords from stdin, but directly from your keyboard. This is useful, if you need to run a command that requires both password and some stdin like &#039;y&#039;, because then you don&#039;t have to worry about &#039;y&#039; being fed as your password.&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;echo&#039;&#039;&#039; &#039;y&#039; &#039;&#039;&#039;| sudo apt remove &#039;&#039;&#039; &amp;lt;PACKAGE&amp;gt; &amp;gt; /dev/null 2&amp;gt;&amp;amp;1  &lt;br /&gt;
will ask you for your password which it receives from your keyboard. Subsequently, it&#039;s fed &#039;y&#039; as stdin and all output is redirected to /dev/null. After having initiated the process, you can make it a background process, by first pausing it with &#039;&#039;&#039;Ctrl-z&#039;&#039;&#039; and then making it a background process with &#039;&#039;&#039;bg&#039;&#039;&#039; %&amp;lt;job ID&amp;gt;.  &lt;br /&gt;
&lt;br /&gt;
It might be useful to know that you can actually feed your password with stdin by using &#039;&#039;&#039;-S&#039;&#039;&#039; option. &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;echo&#039;&#039;&#039; &amp;quot;Password&amp;quot; | &#039;&#039;&#039;sudo -S&#039;&#039;&#039; &amp;lt;COMMAND&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Continuing processes after exiting terminal: screen, disown and nohup ==&lt;br /&gt;
Under normal circumstances, any child processes are sent what&#039;s called &#039;SIGHUP&#039; (short for signal hangup) when the terminal session ends, effectively terminating them. In other words, if the computer or server you&#039;re working from crashes, or you simply have to go home and bring your laptop with you, ongoing processes will be terminated. This is obviously problematic and are 3 ways to avoid this; &#039;&#039;&#039;screen&#039;&#039;&#039;, &#039;&#039;&#039;disown&#039;&#039;&#039; and &#039;&#039;&#039;nohup&#039;&#039;&#039;.  &lt;br /&gt;
&lt;br /&gt;
When people talk about multiple screens in Linux, they&#039;re talking about running multiple terminal windows separate from each other. The processes run within these different terminal windows are not affected by the user logging of, and they&#039;re all equipped with a shell.       &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;&#039;sudo screen -S&#039;&#039;&#039; &amp;lt;Screen_name&amp;gt;&lt;br /&gt;
will start a new terminal window called &amp;lt;Screen_name&amp;gt;. Within this terminal window you can start a lengthy process in the foreground, then quit the terminal window while keeping its shell running by pressing &#039;&#039;&#039;Ctrl a-d&#039;&#039;&#039;. You don&#039;t have to redirect output as it is directed to the terminal where you started the process, which is the screen. Screens are quite useful if you&#039;re doing a lengthy proces and you&#039;re not sure what stdin it might need, so you want to be able to be able interact with it. &lt;br /&gt;
    &lt;br /&gt;
You can read more about screens here:&amp;lt;br&amp;gt;&lt;br /&gt;
[https://kb.iu.edu/d/acuy Additional info on screens 1]&amp;lt;br&amp;gt;&lt;br /&gt;
[https://www.computerhope.com/unix/screen.htm Additional info on screens 2]&lt;br /&gt;
&lt;br /&gt;
As mentioned, the signal that terminates processes when terminal session ends, is called &#039;SIGHUP&#039;. You can make processes inmmune to this signal by using the command &#039;&#039;&#039;disown&#039;&#039;&#039;, which will detach the process from the shells job list, so that the process is not sent a &#039;SIGHUP&#039; signal when the terminal session ends. For example,&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sudo bash -c&#039;&#039;&#039; &#039;&#039;&#039;&#039;apt-get -y install&#039;&#039;&#039; &amp;lt;PACKAGE&amp;gt; &#039;&#039;&#039;&amp;gt;&#039;&#039;&#039; /dev/null &#039;&#039;&#039;2&amp;gt;&amp;amp;1 &amp;amp; disown&#039;&#039;&#039;&#039;&lt;br /&gt;
will install &amp;lt;PACKAGE&amp;gt; as a child process separate from the terminal, and the installation of the package will therefore proceed even if the terminal is shut down.  &lt;br /&gt;
&lt;br /&gt;
Lastly, a very useful command that has similar function to &#039;&#039;&#039;disown&#039;&#039;&#039; is &#039;&#039;&#039;nohup&#039;&#039;&#039;. Unlike &#039;&#039;&#039;disown&#039;&#039;&#039;, the command &#039;&#039;&#039;nohup&#039;&#039;&#039; is defined by POSIX, which means that it works within most shells. We haven&#039;t really discussed what POSIX is. Essentially, POSIX represents a standard for the syntax of Unix operating systems and command line shells, and ensures compatibility between them. It is, however, rarely the case that an OS is &#039;POSIX-certified&#039;, and most OS&#039;s are defined as &#039;Mostly POSIX-compliant&#039;. For instance, there are some shells where &#039;&#039;&#039;disown&#039;&#039;&#039; doesn&#039;t work (tcsh, csh, dash and sh). Any command run with &#039;&#039;&#039;nohup&#039;&#039;&#039; will be immune to SIGHUP signaling, furthermore, &#039;&#039;&#039;nohup&#039;&#039;&#039; ignores all standard input and directs any output bound for the terminal to the file, nohup.out. This means that this command is not ideal for processes that require additional stdin.  &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;nohup&#039;&#039;&#039; &amp;lt;COMMAND&amp;gt; &lt;br /&gt;
will execute &amp;lt;COMMAND&amp;gt;, direct all output to nohup.out and ignore all stdin. Also, if the terminal ends, the &#039;SIGHUP&#039; signal will be ignored and the process will not end.&lt;br /&gt;
&lt;br /&gt;
== Daemon processes == &lt;br /&gt;
Daemon processes are difficult to characterize as they share many of the characteristics that normal background processes have. They run in the background and are detached from the terminal. The parent process of daemon processes is most often the init process, which means that daemons will most often have PPID value of 1. They&#039;re usually created by forking a child process, followed by an immediate exit of the process, however, they can also be created directly by the init process.  Users will typically have no control over daemons. You can see the daemon processes running on your device by typing, &lt;br /&gt;
 Prompt$ ps -A&lt;br /&gt;
which lists ongoing Unix processes. Except for the init process and a few others, daemon processes typically have the ending, &#039;d&#039;. The output from executing &#039;&#039;&#039;ps -A&#039;&#039;&#039; is shown in &#039;&#039;&#039;figure 8.3&#039;&#039;&#039;. Here, there are 3 daemon processes which are underlined with red. Two of these are the init process and the third is what&#039;s called &#039;Secure shell server&#039; process. The screen process has been underlined with orange to show that processes with a PPID value of 1, aren&#039;t necessarily a daemon. There are other daemons which won&#039;t show up unless you&#039;re using a Linux computer. &lt;br /&gt;
&lt;br /&gt;
The purpose of daemons is to provide a service. Examples could be printer service, network service, sound, web service, mail service, etc. It is system level services that we often do not have to care about.&lt;br /&gt;
&lt;br /&gt;
[[File:Ongoing processes3.png|frame|none|&#039;&#039;&#039;Figure 8.3 Ongoing processes, some of which are daemons:&#039;&#039;&#039; The figure shows the execution and output of the command, &#039;&#039;&#039;ps -A&#039;&#039;&#039;, which shows ongoing Unix processes.  3 daemon processes are underlined with red, two of which are init process process and the third is a &#039;Secure shell server&#039; process. Processes with a PPID value of 1, such as the screen process underlined with orange, aren&#039;t necessarily daemons.]]&lt;br /&gt;
&lt;br /&gt;
== Command list == &lt;br /&gt;
In the table below, we list this sections Unix commands.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;width: 18%&amp;quot;| Unix Command&lt;br /&gt;
!Acronym translation &lt;br /&gt;
!Description&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;COMMAND&amp;gt; &#039;&#039;&#039;&amp;amp;&#039;&#039;&#039; &lt;br /&gt;
|&amp;lt;nowiki&amp;gt;-&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|Runs command as a background process &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;bg&#039;&#039;&#039; %&amp;lt;PID&amp;gt; &lt;br /&gt;
|bg and PID are short for background and process identification respectively  &lt;br /&gt;
|Continues a stopped job in the background  &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;fg&#039;&#039;&#039; %&amp;lt;PID&amp;gt; &lt;br /&gt;
|fg and PID are short for foreground and process identification&lt;br /&gt;
|Continues a stopped job in the foreground&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;sleep&#039;&#039;&#039; &amp;lt;NUMBER&amp;gt;[s/m/h/d]&lt;br /&gt;
|&amp;lt;nowiki&amp;gt;-&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|Delays for a specified amount of time. This can be specified &amp;lt;NUMBER&amp;gt; and suffixes; s, m, h and d which are short seconds, minuted, hours and days respectively. By default, the suffix is s &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;top&#039;&#039;&#039; [OPTION]&lt;br /&gt;
|&amp;lt;nowiki&amp;gt;-&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|Displays all the processes running on your computer&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;ps&#039;&#039;&#039; [OPTION]&lt;br /&gt;
|Process status&lt;br /&gt;
|Reports a snapshot of current processes &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;kill&#039;&#039;&#039; [OPTION] &amp;lt;PID&amp;gt;&lt;br /&gt;
|&amp;lt;nowiki&amp;gt;-&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|Sends a signal to a process and by default this signal is to terminate the process&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;screen&#039;&#039;&#039; [OPTION]&lt;br /&gt;
|&amp;lt;nowiki&amp;gt;-&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|Used to create new terminal windows that are detached from each other. Child processes created within these new terminal windows are not affected if their parent process is terminated   &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;disown&#039;&#039;&#039;&lt;br /&gt;
|&amp;lt;nowiki&amp;gt;-&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|Dissociates process from current terminal session&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;nohup&#039;&#039;&#039; [OPTION]&lt;br /&gt;
|No hangup&lt;br /&gt;
|Used to run commands immune to hangups, ignoring stdin. By default output is redirected to nohup.out. &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;pstree&#039;&#039;&#039;&lt;br /&gt;
|Process tree&lt;br /&gt;
|Display a tree of parent and child processes&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Exercise 1: Working with PIDs ==&lt;br /&gt;
1. Take a snapshot of current processes and save the process information to a file. The process information should contain PID&#039;s and PPID&#039;s as a minimum.&amp;lt;br&amp;gt;&lt;br /&gt;
2. In the file, replace the occurrence of bash with &#039;Hacked&#039;.&amp;lt;br&amp;gt;  &lt;br /&gt;
3. Extract the process ID of the &#039;Hacked&#039; process and have the output directed to your terminal (&#039;&#039;&#039;Hint 1&#039;&#039;&#039;).&amp;lt;br&amp;gt;&lt;br /&gt;
4. Make a screen and exit it without closing it.&amp;lt;br&amp;gt; &lt;br /&gt;
5. Extract its PID and have it redirected to your terminal.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Hint 1:&#039;&#039;&#039; A good way to do this is to use what you learned in &#039;Filtering and regular expressions&#039; combined with pipelines.&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/unix/index.php?title=File:Apt_remove2.png&amp;diff=53</id>
		<title>File:Apt remove2.png</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/unix/index.php?title=File:Apt_remove2.png&amp;diff=53"/>
		<updated>2024-03-20T12:15:53Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/unix/index.php?title=File:Apt_install.png&amp;diff=52</id>
		<title>File:Apt install.png</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/unix/index.php?title=File:Apt_install.png&amp;diff=52"/>
		<updated>2024-03-20T12:15:26Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/unix/index.php?title=File:Apt_update%26%26upgrade.png&amp;diff=51</id>
		<title>File:Apt update&amp;&amp;upgrade.png</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/unix/index.php?title=File:Apt_update%26%26upgrade.png&amp;diff=51"/>
		<updated>2024-03-20T12:15:05Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/unix/index.php?title=File:Tar_pipe_gzip.png&amp;diff=50</id>
		<title>File:Tar pipe gzip.png</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/unix/index.php?title=File:Tar_pipe_gzip.png&amp;diff=50"/>
		<updated>2024-03-20T12:14:36Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/unix/index.php?title=File_compression_and_advanced_packaging_tools&amp;diff=49</id>
		<title>File compression and advanced packaging tools</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/unix/index.php?title=File_compression_and_advanced_packaging_tools&amp;diff=49"/>
		<updated>2024-03-20T12:13:44Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: Created page with &amp;quot;__NOTOC__ You might&amp;#039;ve encountered files with file extensions like &amp;#039;.tar&amp;#039;, &amp;#039;.gzip&amp;#039; and &amp;#039;.zip&amp;#039; when downloading files from the internet. These file extensions mean that the file is compressed and file byte size reduced so that it requires less disk space. Bytes are simply a sequence of 8 bits, and we&amp;#039;ve previously seen how this is used to store ASCII characters. Files that have been compressed can also be decompressed, making them user readable but requiring more bytes on...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
You might&#039;ve encountered files with file extensions like &#039;.tar&#039;, &#039;.gzip&#039; and &#039;.zip&#039; when downloading files from the internet. These file extensions mean that the file is compressed and file byte size reduced so that it requires less disk space. Bytes are simply a sequence of 8 bits, and we&#039;ve previously seen how this is used to store ASCII characters. Files that have been compressed can also be decompressed, making them user readable but requiring more bytes on your disk. In this section, we first discuss how it&#039;s possible to reduce the byte size of a file and afterwards restore it back to its original byte size. Next we discuss the file extensions &#039;.tar&#039;, &#039;.gzip&#039; and &#039;.zip&#039;; what they mean and how they differ. In short, tar doesn&#039;t really compress files and there are different ways for how files can be compressed, hence, there are also different file extensions like .gzip and .zip. We will also introduce the commands; &#039;&#039;&#039;tar&#039;&#039;&#039;, &#039;&#039;&#039;gzip&#039;&#039;&#039; and &#039;&#039;&#039;zip&#039;&#039;&#039; and how they can be used to compress/decompress files.         &lt;br /&gt;
&lt;br /&gt;
Lastly, we discuss packaging managers and how the command &#039;&#039;&#039;apt&#039;&#039;&#039;, short for &#039;Advanced Packaging tool&#039;, is used. If you&#039;re running a Unix terminal from your Mac OS, you won&#039;t be able to run the command &#039;&#039;&#039;apt&#039;&#039;&#039;, because it&#039;s not supported. In order to use it, you&#039;d need to either use a virtualbox or connect to a server with a Linux OS. We haven&#039;t talked about connecting to remote servers and you&#039;d have to find such a server as well, so if you want to try these commands out, the easiest option would be to use a virtualbox (there&#039;s a link to a guide in the section &#039;Course Introduction&#039;). You could also try out the Mac OS equivalent of the &#039;Advanced Packaging tool&#039;, which is called &#039;Homebrew&#039;. Here&#039;s an introductory video for this package manager [https://www.youtube.com/watch?v=SELYgZvAZbU Homebrew Guide]. &lt;br /&gt;
   &lt;br /&gt;
At first it might seem rather mysterious that files can be reduced in byte size and decompressed back to their original byte size. The concept, however, is actually quite simple. Files, especially text files, have many patterns that are redundant and appear multiple times. The idea is therefore to make a dictionary that assigns these patterns with a bit value. During file compression, every time these patterns appear, they are then assigned with the same bit value. This type of compression, is called lossless compression, and for an intuitive understanding of this, you can check out this video by crash course [https://www.youtube.com/watch?v=OtDxDvCpPL4&amp;amp;feature=youtu.be File compression] (0:00-6:26).  &lt;br /&gt;
&lt;br /&gt;
For obvious reasons, files that have many redundancies can be compressed significantly more than files that have many unique characters like; music, video and picture files. This, however, is only true if you want the compressed file to have exactly the same shade of blue or sound frequency as the original file. The type of compression we&#039;ve been discussing up till now is what&#039;s called &#039;&#039;lossless compression&#039;&#039;. As the name implies, none of the file content is lost during this type of compression and it compressed file can be recreated perfectly. But there&#039;s actually another type of compression called &#039;&#039;lossy compression&#039;&#039;. The rest of the crash course video linked above, is about this sort of compression (6:26:12:47). Lossy compression operates by removing unnecessary bits of information. After all, the human ear and eye are not acutely evolved enough to perceive small differences in color shades and sound frequencies. Software that use lossy compression, alter the color value and frequency of pixels and sounds respectively to identical values, reducing byte size and ensuring that it&#039;s indistinguishable to us. &lt;br /&gt;
 &lt;br /&gt;
= What is tar, gzip and zip =&lt;br /&gt;
Here, we list the commands we&#039;ll be using in the section, which includes both those used for compression/decompression of files as well as those needed for package management.  &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Unix Command&lt;br /&gt;
!Acronym translation &lt;br /&gt;
!Description&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;tar&#039;&#039;&#039; [OPTION] &amp;lt;ARCHIVE&amp;gt; &amp;lt;FILES&amp;gt; &lt;br /&gt;
|Tape archive&lt;br /&gt;
|Archive utility tool, used to create and extract archives. Archives are simply multiple files that have been combined into one file. &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;gzip&#039;&#039;&#039; [OPTION] &amp;lt;FILE&amp;gt; &lt;br /&gt;
|GNU Zone informational Protocol. &lt;br /&gt;
|Compresses &amp;lt;FILE&amp;gt;   &lt;br /&gt;
|- &lt;br /&gt;
|&#039;&#039;&#039;gunzip&#039;&#039;&#039; [OPTION] &amp;lt;FILE&amp;gt;&lt;br /&gt;
|GNU un Zone informational Protocol. &lt;br /&gt;
|Decompresses &amp;lt;FILE&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;zip&#039;&#039;&#039; [OPTION] &amp;lt;FILE&amp;gt;&lt;br /&gt;
|Zone informational Protocol&lt;br /&gt;
|Archive and compression utility. Used to make an archive or compress &amp;lt;FILE&amp;gt;.&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;unzip&#039;&#039;&#039;&lt;br /&gt;
|un Zone informational Protocol&lt;br /&gt;
|Decompresses &amp;lt;FILE&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;apt&#039;&#039;&#039; [OPTION] &amp;lt;PACKAGE&amp;gt;&lt;br /&gt;
|Advanced Packaging tool&lt;br /&gt;
|Package manager for Ubuntu with many utilities. &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Tar is the oldest of the 3 utilities; &#039;&#039;&#039;tar&#039;&#039;&#039;, &#039;&#039;&#039;gzip&#039;&#039;&#039;, and &#039;&#039;&#039;zip&#039;&#039;&#039;. Unlike &#039;&#039;&#039;gzip&#039;&#039;&#039; and &#039;&#039;&#039;&#039;zip&#039;&#039;&#039;, &#039;&#039;&#039;tar&#039;&#039;&#039; is actually not compressing files, but rather bundling them into archives and giving them the file extension &#039;.tar&#039;. So using &#039;&#039;&#039;tar&#039;&#039;&#039; on 100 files of 10 kB, might not make the resulting &#039;.tar&#039; file byte size smaller than 1 mB.  This actually depends on how the files are arranged in directories, as &#039;&#039;&#039;tar&#039;&#039;&#039; eliminates the space wasted by the file system.  The main reason for using &#039;&#039;&#039;tar&#039;&#039;&#039; is to create a single file of multiple files, a so-called &#039;archive&#039;, that makes for easier portability and storage. &lt;br /&gt;
&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;tar cvf&#039;&#039;&#039; &amp;lt;ARCHIVE&amp;gt; &amp;lt;DIRECTORY&amp;gt;&lt;br /&gt;
will create an archive called &amp;lt;ARCHIVE&amp;gt; from the files in &amp;lt;DIRECTORY&amp;gt;. The option &#039;&#039;&#039;c&#039;&#039;&#039;, &#039;&#039;&#039;v&#039;&#039;&#039; an &#039;&#039;&#039;f&#039;&#039;&#039; are short for &#039;create archive&#039;, &#039;verbose&#039; and  &#039;redirect stdout to given filename&#039; respectively. The &#039;&#039;&#039;tar&#039;&#039;&#039; command has a lot options which are listed hereunder,&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;c&#039;&#039;&#039; : Create archive&lt;br /&gt;
* &#039;&#039;&#039;x&#039;&#039;&#039; : Extract archive &lt;br /&gt;
* &#039;&#039;&#039;f&#039;&#039;&#039; : Redirect stdout to given filename &lt;br /&gt;
* &#039;&#039;&#039;t&#039;&#039;&#039; : Display files in archived file&lt;br /&gt;
* &#039;&#039;&#039;u&#039;&#039;&#039; : Archives and add to existing archive file&lt;br /&gt;
* &#039;&#039;&#039;v&#039;&#039;&#039; : Verbose &lt;br /&gt;
* &#039;&#039;&#039;A&#039;&#039;&#039; : Concatenate archive files&lt;br /&gt;
* &#039;&#039;&#039;z&#039;&#039;&#039; : zip, will use gzip for compression on resulting tar file.&lt;br /&gt;
* &#039;&#039;&#039;r&#039;&#039;&#039; : Add file/directory in already existing .tar file  &lt;br /&gt;
&lt;br /&gt;
You can extract files from the archive by typing, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;tar xvf&#039;&#039;&#039; &amp;lt;ARCHIVE&amp;gt; &lt;br /&gt;
which will extract &amp;lt;ARCHIVE&amp;gt; and return it to its original state.&lt;br /&gt;
&lt;br /&gt;
After having created an archive using &#039;&#039;&#039;tar&#039;&#039;&#039;, the &#039;&#039;&#039;gzip&#039;&#039;&#039; utility can be used compress the archive. The file extension for gzipped files is &#039;.gz&#039;. However, if you&#039;ve used the tar utility on the files to make an archive, the file extension is tar.gz or the abbreviated form, .tgz. &lt;br /&gt;
From the command line, you can compress files by typing, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;gzip&#039;&#039;&#039; &amp;lt;FILE&amp;gt;&lt;br /&gt;
which will compress &amp;lt;FILE&amp;gt; to &amp;lt;FILE.gz&amp;gt;. The &#039;&#039;&#039;gzip&#039;&#039;&#039; command automatically adds the &#039;&#039;&#039;.gz&#039;&#039;&#039; file extension. If you want your file to not have the &#039;&#039;&#039;.gz&#039;&#039;&#039; file extension, you can use the &#039;&#039;&#039;k&#039;&#039;&#039; command option,&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;gzip -k&#039;&#039;&#039; &amp;lt;FILE&amp;gt; &lt;br /&gt;
which will compress &amp;lt;FILE&amp;gt; to &amp;lt;FILE&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
You can also just as easily compress multiple files,&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;gzip&#039;&#039;&#039; file1 file2 file3&lt;br /&gt;
which will compress the files; file1, file2 and file3. You can also use &#039;&#039;&#039;gzip&#039;&#039;&#039; to compress every file in a directory, but you need to use the recursive command option, &#039;&#039;&#039;r&#039;&#039;&#039;, otherwise you will get the error &#039;gzip: DIRECTORY/ is a directory -- ignored&#039;, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;gzip -r&#039;&#039;&#039; &amp;lt;DIRECTORY&amp;gt; &lt;br /&gt;
which will go through &amp;lt;DIRECTORY&amp;gt; and compress every file, the end result being a directory filled with compressed files. If you want all of the files to be compressed into one file, you&#039;d need to first create an archive with &#039;&#039;&#039;tar&#039;&#039;&#039; and then compress it with &#039;&#039;&#039;gzip&#039;&#039;&#039;. Lastly, you can set the level for which you want to compress your files, ranging from &#039;&#039;&#039;[1-9]&#039;&#039;&#039;. For instance, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;gzip -1&#039;&#039;&#039; &amp;lt;FILE&amp;gt;&lt;br /&gt;
will compress &amp;lt;FILE&amp;gt; at the highest level. The process, however, is a lot slower than if you had compressed your file at the lowest compression level, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;gzip -9&#039;&#039;&#039; &amp;lt;FILE&amp;gt; &lt;br /&gt;
will compress &amp;lt;FILE&amp;gt; at the lowest level, but the process significantly faster. By default, &#039;&#039;&#039;gzip&#039;&#039;&#039; will compress at the highest compression level, &#039;&#039;&#039;1&#039;&#039;&#039;. &lt;br /&gt;
A compressed file, can be extracted with &#039;&#039;&#039;gunzip&#039;&#039;&#039;, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;gunzip&#039;&#039;&#039; &amp;lt;FILE&amp;gt;&lt;br /&gt;
which will extract &amp;lt;FILE&amp;gt; and return it to its original state. Just like with &#039;&#039;&#039;gzip&#039;&#039;&#039; you can extract multiple files simultaneously, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;gunzip -k&#039;&#039;&#039; file1 file2 file3&lt;br /&gt;
which will extract files; file1, file2 and file3. You can also extract every in a directory by using the &#039;&#039;&#039;r&#039;&#039;&#039; command option, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;gunzip -r&#039;&#039;&#039; &amp;lt;DIRECTORY&amp;gt; &lt;br /&gt;
One of the command options for the &#039;&#039;&#039;tar&#039;&#039;&#039; command allows for simultaneously creating an archive and compressing the files using &#039;&#039;&#039;gzip&#039;&#039;&#039;,&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;tar cvzf&#039;&#039;&#039; &amp;lt;ARCHIVE&amp;gt; &amp;lt;FILES&amp;gt;  &lt;br /&gt;
will create compressed archive, &amp;lt;ARCHIVE&amp;gt;, from &amp;lt;FILES&amp;gt;. A compressed archive can be extracted by typing, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;tar xvzf&#039;&#039;&#039; &amp;lt;Compressed_ARCHIVE&amp;gt; &lt;br /&gt;
which returns the compressed archive to its original state. &lt;br /&gt;
&lt;br /&gt;
You might be wondering what&#039;s the point of using the &#039;&#039;&#039;gzip&#039;&#039;&#039; command if the &#039;&#039;&#039;tar&#039;&#039;&#039; command can be used for compressing files as well. One good reason for this, is that when you use the &#039;&#039;&#039;gzip&#039;&#039;&#039; utility of &#039;&#039;&#039;tar&#039;&#039;&#039; you can only use the default option settings for &#039;&#039;&#039;gzip&#039;&#039;&#039;. &#039;&#039;&#039;gzip&#039;&#039;&#039; offers a range of compression levels from 1 to 9; 1 offers the fastest compression speed but at a lower ratio, and 9 offers the highest compression ratio but at a lower speed. The gzip application uses level 6 by default. Depending on the filetype, there&#039;s often no significant difference in data storage at different compression levels. Conversely, there can be big differences in the time it takes to compress data, hence , it&#039;s often not worth the wait time to compress files at the highest level. &lt;br /&gt;
&lt;br /&gt;
You can pipe the output of &#039;&#039;&#039;tar&#039;&#039;&#039; to &#039;&#039;&#039;gzip&#039;&#039;&#039;, &lt;br /&gt;
 &lt;br /&gt;
[[File:Tar pipe gzip.png|frame|none|Figure 7.1 Piping &#039;&#039;&#039;tar&#039;&#039;&#039; with &#039;&#039;&#039;gzip&#039;&#039;&#039;: The directory, Example, is archived using &#039;&#039;&#039;tar c&#039;&#039;&#039;, which stdout is piped to &#039;&#039;&#039;gzip -9&#039;&#039;&#039;, whereafter the stdout is redirected to the Example.tgz.]] &lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;zip&#039;&#039;&#039; utility actually came out before &#039;&#039;&#039;gzip&#039;&#039;&#039;, but because it was developed commercially by the firm PKWARE, it suffered from patent encumbering for many years which sparked the development of &#039;&#039;&#039;gzip&#039;&#039;&#039;, which was a free compression/decompression software. Both &#039;&#039;&#039;zip&#039;&#039;&#039; and &#039;&#039;&#039;gzip&#039;&#039;&#039;, use the &#039;LZ77 algorithm&#039; for compression/decompression but unlike gzip, it also creates archives of files and gives it the file extension &#039;.zip&#039;. For more information on &#039;&#039;&#039;tar&#039;&#039;&#039;, &#039;&#039;&#039;zip&#039;&#039;&#039; and &#039;&#039;&#039;gzip&#039;&#039;&#039; you can follow this link, [https://itsfoss.com/tar-vs-zip-vs-gz/ Additional information on tar, zip, gzip and some other file compressions]&lt;br /&gt;
&lt;br /&gt;
To use &#039;&#039;&#039;zip&#039;&#039;&#039; and &#039;&#039;&#039;unzip&#039;&#039;&#039; you first need to download and package it, and for this you can use the package managers &#039;&#039;&#039;apt&#039;&#039;&#039; and &#039;&#039;&#039;Homebrew&#039;&#039;&#039; (for Mac OS users).&lt;br /&gt;
&lt;br /&gt;
== Exercise 1: tar and gzip == &lt;br /&gt;
1. Download files or find files on your computer which you think can be compressed significantly. Put them together in a folder.&amp;lt;br&amp;gt;&lt;br /&gt;
2. Archive and compress the folder at default compression level.&amp;lt;br&amp;gt; &lt;br /&gt;
3. Uncompress the folder.&amp;lt;br&amp;gt; &lt;br /&gt;
4. Archive and compress it at the lowest compression level in one line.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Package managing == &lt;br /&gt;
Package managers are software tools that automate installation, updating, configuring and removing packages. An important theme on Linux based systems, is that every program is able to do one simple function, but it does it well. Larger programs on a Linux OS are sort of tailored together by smaller programs and are therefore dependent on smaller programs. This is essentially what&#039;s meant by the &#039;dependencies&#039; of a program, and for the Linux OS many of these small programs been developed in parallel by different organizations. Package managers keep all of these dependencies updated and in check, ensuring functionality and compatibility of all programs. Microsoft is the sole owner of the Windows OS and there are therefore defined procedure for installing programs. Also larger programs are designed to be independent and for the most part they don&#039;t need to be tailored with other small programs for full functionality. But there are some exceptions on a Windows OS which need to be installed externally and you&#039;ve probably heard of; Java, Adobe Flash player, Wizard etc.. You might think that having programs without dependencies is a good idea, but a major weakness is that there&#039;ll be a lot redundancy and wasted disk space.   &lt;br /&gt;
&lt;br /&gt;
The package manager used for Ubuntu is &#039;&#039;&#039;apt&#039;&#039;&#039; short for &#039;Advanced package manager&#039;. In order to use it, you need superuser privileges, which you can get by using the command &#039;&#039;&#039;sudo&#039;&#039;&#039;. The command &#039;&#039;&#039;sudo&#039;&#039;&#039;,  will execute following commands with elevated privileges corresponding to the permissions that the user has. If you&#039;re executing this from your computer, you&#039;ll be granted root privileges which are the highest privileges you can get.&amp;lt;br&amp;gt; &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sudo apt install&#039;&#039;&#039;  &amp;lt;PROGRAM&amp;gt; &lt;br /&gt;
The command &#039;&#039;&#039;apt&#039;&#039;&#039; will download and install &amp;lt;PROGRAM&amp;gt;. &lt;br /&gt;
You can also remove packages,&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sudo apt remove&#039;&#039;&#039; &amp;lt;PROGRAM&amp;gt;&lt;br /&gt;
which will remove &amp;lt;PROGRAM&amp;gt;. If you want to remove package configuration files as well,&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sudo apt purge&#039;&#039;&#039; &amp;lt;PROGRAM&amp;gt; &lt;br /&gt;
will remove &amp;lt;PROGRAM&amp;gt; along with its configuration files. Configuration files contain information about the initial parameters and setting for a program. If you want to update your currently installed packages, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sudo apt upgrade&#039;&#039;&#039; &lt;br /&gt;
will update all of your currently installed packages. It is, however, sometimes the case that the sources from which you download your updates are outdated. You can update these sources,  &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sudo apt update&#039;&#039;&#039; &lt;br /&gt;
which will update all configured sources for your packages. These sources can be found in the directory, &#039;/etc/apt&#039;, in files with the ending &#039;.list&#039;.  &lt;br /&gt;
You can remove packages that are no longer required on your computer by using the &#039;&#039;&#039;autoremove&#039;&#039;&#039; option, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sudo apt autoremove&#039;&#039;&#039; &lt;br /&gt;
You can use the &#039;&#039;&#039;search&#039;&#039;&#039; option to search for packages with a specific feature you might need, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sudo apt search &amp;lt;REGEX&amp;gt;&#039;&#039;&#039; &lt;br /&gt;
will search for packages correlating to the regular expression pattern. &lt;br /&gt;
Lastly, the command option &#039;&#039;&#039;show&#039;&#039;&#039; displays information about packages in the terminal.&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sudo apt show &amp;lt;PACKAGE&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Installing Emacs package example === &lt;br /&gt;
Here we demonstrate how the package for the text editor, emacs, can be installed with &#039;&#039;&#039;apt&#039;&#039;&#039;. &lt;br /&gt;
&lt;br /&gt;
[[File:Apt update&amp;amp;&amp;amp;upgrade.png|none|frame|&#039;&#039;&#039;Figure 7.2 Updating configured sources and upgrade packages:&#039;&#039;&#039; The command &#039;&#039;&#039;sudo apt update &amp;amp;&amp;amp; sudo apt upgrade&#039;&#039;&#039; will execute &#039;&#039;&#039;sudo apt update&#039;&#039;&#039; and &#039;&#039;&#039;sudo apt upgrade&#039;&#039;&#039; consecutively, updating all configured sources and installing available upgrades for installed packages. This is equivalent to waiting for &#039;&#039;&#039;sudo apt update&#039;&#039;&#039; to complete and then executing &#039;&#039;&#039;sudo apt upgrade&#039;&#039;&#039;. The &#039;&#039;&#039;&amp;amp;&amp;amp;&#039;&#039;&#039; is essentially an operator that means &#039;and&#039;.]] &lt;br /&gt;
&lt;br /&gt;
[[File:Apt install.png|none|frame|&#039;&#039;&#039;Figure 7.3 Installing a package:&#039;&#039;&#039; The command &#039;&#039;&#039;apt install emacs&#039;&#039;&#039; is used to install the package, emacs. In this case, we show what it would look like if emacs was already installed, as it&#039;s not possible to show the whole installation process anyway. Also the installation process might take a while, and you&#039;ll have to wait for its completion before you can do anything else. There&#039;s away to avoid this which we&#039;ll learn in the next section when we introduce the concept of background processes.]]&lt;br /&gt;
&lt;br /&gt;
[[File:Apt remove2.png|none|frame|&#039;&#039;&#039;Figure 7.4 Removing a package:&#039;&#039;&#039; The command &#039;&#039;&#039;sudo apt remove -y emacs&#039;&#039;&#039; will remove the package emacs. When a command option &#039;&#039;&#039;-y&#039;&#039;&#039; is used, you won&#039;t be prompted to type the additional &#039;Y&#039; for the removal to proceed.]] &lt;br /&gt;
 &lt;br /&gt;
== Exercise 2: Installing and using Zip == &lt;br /&gt;
1. Use the &#039;&#039;&#039;apt&#039;&#039;&#039; command to install &#039;&#039;&#039;zip&#039;&#039;&#039;.&amp;lt;br&amp;gt;&lt;br /&gt;
2. Use &#039;&#039;&#039;zip&#039;&#039;&#039; to unzip the file folder you compressed in exercise 1.&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/unix/index.php?title=File:Rwx_permissions2.png&amp;diff=48</id>
		<title>File:Rwx permissions2.png</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/unix/index.php?title=File:Rwx_permissions2.png&amp;diff=48"/>
		<updated>2024-03-20T12:13:00Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/unix/index.php?title=File:File_permissions1.png&amp;diff=47</id>
		<title>File:File permissions1.png</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/unix/index.php?title=File:File_permissions1.png&amp;diff=47"/>
		<updated>2024-03-20T12:12:44Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/unix/index.php?title=File_permissions&amp;diff=46</id>
		<title>File permissions</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/unix/index.php?title=File_permissions&amp;diff=46"/>
		<updated>2024-03-20T12:12:23Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: Created page with &amp;quot;__NOTOC__ File permissions (also known as file mode) are an important concept in the Unix (OS), and you might have already seen file permissions without knowing it. You can see them by listing files in long format, using the command &amp;#039;&amp;#039;&amp;#039;ls -l&amp;#039;&amp;#039;&amp;#039; in your working directory. It should look something like &amp;#039;&amp;#039;&amp;#039;figure 5.1&amp;#039;&amp;#039;&amp;#039;, shown in MobaXterm.  File:File permissions1.png|middle|frame|&amp;#039;&amp;#039;&amp;#039;Figure 5.1:&amp;#039;&amp;#039;&amp;#039; A screenshot of a command line interface after having used the command ls...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
File permissions (also known as file mode) are an important concept in the Unix (OS), and you might have already seen file permissions without knowing it. You can see them by listing files in long format, using the command &#039;&#039;&#039;ls -l&#039;&#039;&#039; in your working directory. It should look something like &#039;&#039;&#039;figure 5.1&#039;&#039;&#039;, shown in MobaXterm. &lt;br /&gt;
[[File:File permissions1.png|middle|frame|&#039;&#039;&#039;Figure 5.1:&#039;&#039;&#039; A screenshot of a command line interface after having used the command ls -l.]]&lt;br /&gt;
&lt;br /&gt;
You can make out what most of these columns mean. Starting from the right we have the name of the file/directory, the number of bytes it contains and so on. But what does the column with those weird &#039;-&#039;, &#039;r&#039;,&#039;x&#039; symbols on the far left mean? Well, this is what&#039;s called file permissions, and is what we&#039;ll be learning in this section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
File permissions are what they sound like. It&#039;s what permits or prohibits users to interact with files. In the early days of computing, before computers became cheap and personal, they were expensive and universities would typically have one mainframe and a bunch of terminals from where users could access the mainframe. As users connected to the same mainframe, they could also access each others files, so in order to protect user files, a file permission system was implemented. It is still very relevant today as super computers use file permission systems to determine who should be allowed to access and work with the data stored within.  &lt;br /&gt;
&lt;br /&gt;
[[File:Rwx permissions2.png|right|frame|&#039;&#039;&#039;Figure 5.2&#039;&#039;&#039; Overview over what is used ]] &lt;br /&gt;
&lt;br /&gt;
Let&#039;s go through the file permissions on my_program.sh --&amp;gt; and nothing_here --&amp;gt; in &#039;&#039;&#039;Figure 5.1&#039;&#039;&#039;.&amp;lt;br /&amp;gt;&lt;br /&gt;
The first symbol, &#039;-&#039; for my_program.sh and &#039;d&#039; for nothing_here, is the file type and indicate that this is a regular file and a directory respectively.The next 3 characters are &#039;&#039;&#039;rwx&#039;&#039;&#039; for both my_program.sh and nothing_here.&amp;lt;br /&amp;gt;&lt;br /&gt;
In a Unix (OS) there are 3 things that a user can do with a file, read : &#039;&#039;&#039;r&#039;&#039;&#039; , write : &#039;&#039;&#039;w&#039;&#039;&#039; , and execute : &#039;&#039;&#039;x&#039;&#039;&#039;. So if a file has the file permission, &#039;&#039;&#039;rwx&#039;&#039;&#039;, then the user can read, write and execute the file. Now you might be wondering why there are multiple &#039;r&#039;s, &#039;w&#039;s and &#039;x&#039;s in a file permission. This is simply because we distinguish between 3 types of users; the file owner, group members and other users. When you&#039;ve created a file, you&#039;d typically also be the file owner of the file, but if you&#039;ve made the document collectively with a group of people, you might only be a group member. The last type of user, other users, could be any stranger having a look at your files. Each of these type of users have 3 file permissions, read:r, write:w and execute:x. So counting the character for file type as well, there will in total always be 10 characters in any file permission. The hyphen (This is what &#039;&#039;&#039;-&#039;&#039;&#039; is called in computer language) means that a permission is lacking. &lt;br /&gt;
&lt;br /&gt;
For example, the file permission for my_program.sh, &#039;&#039;&#039;-rwxr--r--&#039;&#039;&#039; translates to:&lt;br /&gt;
*The file is a regular file&lt;br /&gt;
*The file owner can read, write and execute the file&lt;br /&gt;
*Group members and other users can only read the file.&lt;br /&gt;
== Working with file permissions ==&lt;br /&gt;
Now that we have a basic idea of what file permissions are let&#039;s do some work with them. The Unix commands we&#039;ll be learning in this section are shown here. If you&#039;re using Ubuntu WSL, file permission commands won&#039;t work for files located in /mnt/c/*. You have to either go to your home with &#039;&#039;&#039;cd ~&#039;&#039;&#039; or use MobaXterm.    &lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Unix Command&lt;br /&gt;
!Acronym translation&lt;br /&gt;
!Description&lt;br /&gt;
|- &lt;br /&gt;
|&#039;&#039;&#039;chmod&#039;&#039;&#039; [OPTION] [MODE] &amp;lt;FILE&amp;gt;&lt;br /&gt;
|Change mode.&lt;br /&gt;
|Changes file permissions on a file according to the mode given. No need to be confused about [MODE], as it just another term used for file permission. It can be specified with letters or numbers. It&#039;s easier to understand what you&#039;re doing with letters but using numbers can be faster. In the example, we&#039;ll show how to use both. &lt;br /&gt;
|- &lt;br /&gt;
|&#039;&#039;&#039;chown&#039;&#039;&#039; [OPTION] [OWNER][:[GROUP]] &amp;lt;FILE&amp;gt;&lt;br /&gt;
|Change owner. &lt;br /&gt;
|Change file owner and/or group. This can be done separately or simultaneously by typing [OWNER]:[GROUP]. &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;chgrp&#039;&#039;&#039; [OPTION] &amp;lt;FILE&amp;gt;&lt;br /&gt;
|Change group.&lt;br /&gt;
|Change group of a file.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Changing File permissions with chmod ==&lt;br /&gt;
&lt;br /&gt;
=== Using letters === &lt;br /&gt;
In the [MODE] option of &#039;&#039;&#039;chmod&#039;&#039;&#039;, the letters &#039;&#039;&#039;u&#039;&#039;&#039;, &#039;&#039;&#039;g&#039;&#039;&#039; and &#039;&#039;&#039;o&#039;&#039;&#039; are used for user (file owner), group owner and other users respectively. To assign file permissions to users, the symbols &#039;&#039;&#039;+&#039;&#039;&#039; and &#039;&#039;&#039;-&#039;&#039;&#039; are used. So let&#039;s say I wanted to make changes to the file permissions of pictures_of_spiderman.jpg in &#039;&#039;&#039;figure 5.1&#039;&#039;&#039;. &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;chmod g+w&#039;&#039;&#039; pictures_of_spiderman.jpg  &lt;br /&gt;
Assigns file permission, &#039;&#039;&#039;w&#039;&#039;&#039;, to group owners. This makes the file writable for group owners. &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;chmod o+rwx&#039;&#039;&#039; pictures_of_spiderman.jpg &lt;br /&gt;
Assigns the file permissions, &#039;&#039;&#039;rwx&#039;&#039;&#039;, to other users. This makes the file readable, writable and executable for other users.&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;chmod u-rx&#039;&#039;&#039; pictures_of_spiderman.jpg &lt;br /&gt;
Removes file permission, &#039;&#039;&#039;rx&#039;&#039;&#039;, to the file owner, making it only writable for the file owner. &lt;br /&gt;
=== Using numbers ===&lt;br /&gt;
If you want to assign multiple file permissions to multiple users with one command you can use numbers instead. To understand how, you need to think of file permissions as a set binary numbers (one set for each user), which is how your computer interprets them.&amp;lt;br&amp;gt;&lt;br /&gt;
 &#039;&#039;&#039;rwx rwx rwx 111 111 111&#039;&#039;&#039; &lt;br /&gt;
 &#039;&#039;&#039;--- --- --- 000 000 000&#039;&#039;&#039; &lt;br /&gt;
 &#039;&#039;&#039;rw- -wx r-x 110 011 101&#039;&#039;&#039;&lt;br /&gt;
 &#039;&#039;&#039;r-- -w- --x 100 010 001&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In the last section we learned that bit values (reading from right to left) are 1,2 and 4. We can add the numbers together in to get numbers corresponding to a file permission for each user. &lt;br /&gt;
 &#039;&#039;&#039;rwx rwx rwx 111 111 111&#039;&#039;&#039; --&amp;gt; &#039;&#039;&#039;4+2+1 4+2+1 4+2+1&#039;&#039;&#039; --&amp;gt; &#039;&#039;&#039;7 7 7&#039;&#039;&#039;&lt;br /&gt;
 &#039;&#039;&#039;--- --- --- 000 000 000&#039;&#039;&#039; --&amp;gt; &#039;&#039;&#039;0+0+0 0+0+0 0+0+0&#039;&#039;&#039; --&amp;gt; &#039;&#039;&#039;0 0 0&#039;&#039;&#039;&lt;br /&gt;
 &#039;&#039;&#039;rw- -wx r-x 110 011 101&#039;&#039;&#039; --&amp;gt; &#039;&#039;&#039;4+2+0 0+2+1 4+0+1&#039;&#039;&#039; --&amp;gt; &#039;&#039;&#039;6 3 5&#039;&#039;&#039;&lt;br /&gt;
 &#039;&#039;&#039;r-- -w- --x 100 010 001&#039;&#039;&#039; --&amp;gt; &#039;&#039;&#039;4+0+0 0+2+0 0+0+1&#039;&#039;&#039; --&amp;gt; &#039;&#039;&#039;4 2 1&#039;&#039;&#039;&lt;br /&gt;
 &lt;br /&gt;
Let&#039;s say I wanted to make pictures_of_spiderman.jpg available for reading, writing and execution to everyone:&amp;lt;br /&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;chmod 777&#039;&#039;&#039; pictures_of_spiderman.jpg&lt;br /&gt;
&lt;br /&gt;
There&#039;s no need to use &#039;&#039;&#039;u&#039;&#039;&#039;, &#039;&#039;&#039;g&#039;&#039;&#039; and &#039;&#039;&#039;o&#039;&#039;&#039;, as the first spot corresponds to &#039;&#039;&#039;u&#039;&#039;&#039;, the second spot corresponds to &#039;&#039;&#039;g&#039;&#039;&#039; and the third spot corresponds to &#039;&#039;&#039;o&#039;&#039;&#039;. If this was to be done with letters to do this with letters, you would have to have used three commands:&amp;lt;br /&amp;gt;&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;chmod u+rwx&#039;&#039;&#039; pictures_of_spiderman.jpg &amp;lt;br /&amp;gt; &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;chmod g+rwx&#039;&#039;&#039; pictures_of_spiderman.jpg &amp;lt;br /&amp;gt;&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;chmod o+rwx&#039;&#039;&#039; pictures_of_spiderman.jpg &amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When you&#039;re using numbers, it&#039;s important to know that you&#039;re always changing all user file permissions. So if you omit a number at one spot, Unix will assume that its value is 0 and remove all file permissions for this type of user. For example:&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;chmod 75&#039;&#039;&#039; pictures_of_spiderman.jpg &amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will remove &#039;&#039;&#039;rwx&#039;&#039;&#039; permission for the file owner, give rwx file permission to group users and r-x file permission to other users. &lt;br /&gt;
&lt;br /&gt;
A useful command line option for &#039;&#039;&#039;chmod&#039;&#039;&#039; is, &#039;&#039;&#039;R&#039;&#039;&#039;, which allows you to operate file permissions on all files within a directory. &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;chmod&#039;&#039;&#039; -R 777 &amp;lt;DIRECTORY&amp;gt;&lt;br /&gt;
gives all file permissions to all users. &lt;br /&gt;
&lt;br /&gt;
== Changing file ownership with chgrp and chown ==&lt;br /&gt;
The command &#039;&#039;&#039;chgrp&#039;&#039;&#039; is used to change the group ownership of a file and &#039;&#039;&#039;chown&#039;&#039;&#039; can be used change both the file owner and group. As mentioned, every file or directory can be accessed by 3 types of users; the file owner, group users and other users. We&#039;ve just learned how to change file permissions for the 3 different user types using &#039;&#039;&#039;chmod&#039;&#039;&#039;, but we haven&#039;t learned how to change owners and groups.    &lt;br /&gt;
You can change the file owner of a file, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;chown&#039;&#039;&#039; [NewFileOwner] &amp;lt;file&amp;gt; &lt;br /&gt;
which will replace the original owner with [NewFileOwner] if it&#039;s a valid owner. In order to actually test &#039;&#039;&#039;chown&#039;&#039;&#039; and &#039;&#039;&#039;chgrp&#039;&#039;&#039; on your computer you need to actually have different users and groups. As this is probably not something that you have there will be no exercises in using the commands &#039;&#039;&#039;chown&#039;&#039;&#039; and &#039;&#039;&#039;chgrp&#039;&#039;&#039;. You could try to create more file owners and group owners on your computer, but that&#039;s entirely up to you.  &lt;br /&gt;
You can change the group owner of a file, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;chown&#039;&#039;&#039; :[NewGroup] &amp;lt;FILE&amp;gt;&lt;br /&gt;
which will change the group owner to [NewGroup] if it&#039;s a valid group. You can also change group and file owner at the same time, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;chown&#039;&#039;&#039; [NewFileOwner]:[NewGroup] &amp;lt;FILE&amp;gt;&lt;br /&gt;
will change the file owner and group of the &amp;lt;FILE&amp;gt; if [NewFileOwner] and [NewGroup] area valid. &lt;br /&gt;
&lt;br /&gt;
The command &#039;&#039;&#039;chgrp&#039;&#039;&#039; can also be used to change group owners, even though &#039;&#039;&#039;chown&#039;&#039;&#039; can be used for that as well. At first, &#039;&#039;&#039;chown&#039;&#039;&#039; could only be used to change file owner or both file owner and group, hence, &#039;&#039;&#039;chgrp&#039;&#039;&#039; was needed if you only wanted to change the group owner. This, however, is not the case anymore. The best reason for still using &#039;&#039;&#039;chgrp&#039;&#039;&#039; instead of &#039;&#039;&#039;chown&#039;&#039;&#039; is that it lowers the risk of accidentally changing the file owner of a file, which could be problematic. You can change the group of a file by typing, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;chgrp&#039;&#039;&#039; [NewGroup] &amp;lt;FILE&amp;gt;&lt;br /&gt;
will change the group of the &amp;lt;FILE&amp;gt; if [NewGroup] is valid. &lt;br /&gt;
&lt;br /&gt;
In similar manner to &#039;&#039;&#039;chmod&#039;&#039;, the command line option, &#039;&#039;&#039;R&#039;&#039;&#039;, can be used to change ownerships on all files within a directory. &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;chown&#039;&#039;&#039; -R [NewFileOwner] &amp;lt;DIRECTORY&amp;gt;&lt;br /&gt;
will change all ownership of all files in &amp;lt;DIRECTORY&amp;gt; to [NewFileOwner]      &lt;br /&gt;
&lt;br /&gt;
== Exercise 1: Changing file permission with chmod == &lt;br /&gt;
# Create a file called workfile.txt.   &lt;br /&gt;
# Change the file permission of the file to ---xrw-rwx.&lt;br /&gt;
# Change the file permission of the file to -rwx---r-x.&lt;br /&gt;
# Remove all file permission from the file, so that the file permission is ----------. &lt;br /&gt;
# Make a shell script file that upon execution will give your workfile the file permission -rwx--x--x, then  -r-x-w---- and lastly -rwxrwxrw-.&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/unix/index.php?title=Filtering_and_regular_expressions&amp;diff=45</id>
		<title>Filtering and regular expressions</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/unix/index.php?title=Filtering_and_regular_expressions&amp;diff=45"/>
		<updated>2024-03-20T12:11:52Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Exercise 2: Translating ASCII characters to binary and decimal values */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
You can think of regular expressions (regex for short) as a pattern language that can be used to match patterns and filter data. In this section, we&#039;ll be learning so-called &#039;&#039;filter commands&#039;&#039;, some of which utilize regular expressions in order to find and replace patterns. It is therefore important to have a basic understanding of regular expressions. To get you started, follow this link to an introductory video, [https://www.youtube.com/watch?v=KJG1dETacLI Basic Regular Expression Introduction Video], which gives a basic understanding of the concepts of regular expressions. &lt;br /&gt;
&lt;br /&gt;
Next, you can follow this link [https://regexone.com/lesson/introduction_abcs Regex Introduction Exercises], where there&#039;s some exercises on basic regex. The &#039;Practice problems&#039; are a bit more complex, but should still be doable. They are, however, optional.  &lt;br /&gt;
&lt;br /&gt;
[https://www.cheatography.com/davechild/cheat-sheets/regular-expressions/pdf/ Regex cheat sheet]&lt;br /&gt;
&lt;br /&gt;
== Introduction to commands ==  &lt;br /&gt;
Now that you&#039;ve been initiated in regular expressions, we&#039;ll take a look at some Unix commands that can use regular expressions. Underneath we list commands and syntax for the commands that we&#039;ll be using in this section. &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Unix Command&lt;br /&gt;
!Acronym translation &lt;br /&gt;
!Description&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;grep&#039;&#039;&#039; [PATTERN] &amp;lt;FILE&amp;gt;&lt;br /&gt;
|Global regular expression print. &lt;br /&gt;
|Uses regular expressions select lines in a file that matches the pattern. &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;sed&#039;&#039;&#039; [OPTION] &amp;lt;SCRIPT&amp;gt; &amp;lt;FILE&amp;gt;&lt;br /&gt;
|stream editor&lt;br /&gt;
|Allows user to edit files without actually opening the files using regular expressions.&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;tr&#039;&#039;&#039; [OPTION] &amp;lt;SET1&amp;gt; &amp;lt;SET2&amp;gt;&lt;br /&gt;
|Translate&lt;br /&gt;
|Translates characters from the standard input and writes to the standard output.  &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;sort&#039;&#039;&#039; [OPTION] &amp;lt;FILE&amp;gt;&lt;br /&gt;
|&amp;lt;nowiki&amp;gt;-&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|Sorts the content of a file.  &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Datafile 1: [https://teaching.healthtech.dtu.dk/material/unix/Pseudomonas_Aeruginosa_16SrRNA.gb Pseudomonas Aeruginosa 16S rRNA Genebank file]&amp;lt;br&amp;gt; &lt;br /&gt;
Datafile 2: [https://teaching.healthtech.dtu.dk/material/unix/Genebankfiles.gb Genebank files] &amp;lt;br&amp;gt;&lt;br /&gt;
Datafile 3: [https://teaching.healthtech.dtu.dk/material/unix/ASCII_chars.dat ASCII character file]&amp;lt;br&amp;gt;&lt;br /&gt;
Datafile 4: [https://teaching.healthtech.dtu.dk/material/unix/Ex1_7bit_binarydata.dat Binary data file]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== grep ===&lt;br /&gt;
The &#039;&#039;&#039;grep&#039;&#039;&#039; command uses regular expressions as search patterns to capture patterns in files and outputs it to stdout. It has the syntax, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;grep&#039;&#039;&#039; [OPTION] &amp;lt;PATTERN&amp;gt; &amp;lt;FILE&amp;gt;&lt;br /&gt;
In &#039;&#039;&#039;figure 5.1&#039;&#039;&#039;, the &#039;&#039;&#039;grep&#039;&#039;&#039; command is used to capture the line containing the authors of a text, which is then redirected to a text file. &lt;br /&gt;
[[File:Grep example.png|none|frame|&#039;&#039;&#039;Figure 5.1 Using the grep command:&#039;&#039;&#039; Here, &#039;&#039;&#039;grep&#039;&#039;&#039; is used capture the line containing the authors of the file and saving it to &amp;lt;AUTHORFILE.txt&amp;gt;.]]&lt;br /&gt;
&lt;br /&gt;
But before you start using this sections commands you should know that Bash (recall that this is the shell that you&#039;re working in) uses basic regex and not extended regex by default. For example, if you wanted to search for occurrences of &#039;AUTHORS&#039; or &#039;authors&#039;&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;grep&#039;&#039;&#039; &#039;AUTHORS|authors&#039; Pseudomonas_Aeruginosa_16S_rRNA.gb &lt;br /&gt;
there would be no results, as Bash doesn&#039;t interpret &#039;|&#039; as a special character. There are 3 solutions to this problem. &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;grep&#039;&#039;&#039; &#039;AUTHORS\|authors&#039; Pseudomonas_Aeruginosa_16S_rRNA.gb &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;egrep&#039;&#039;&#039; &#039;AUTHORS|authors&#039; Pseudomonas_Aeruginosa_16S_rRNA.gb&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;grep -E&#039;&#039;&#039; &#039;AUTHORS|authors&#039; Pseudomonas_Aeruginosa_16S_rRNA.gb&lt;br /&gt;
In the first solution, we use &#039;\&#039; to designate that &#039;|&#039; is to be interpreted as a special character. The second and third solution are similar, as they both use an extended version of &#039;&#039;&#039;grep&#039;&#039;&#039;, so that Bash interprets extended regex. However, only &#039;&#039;&#039;grep&#039;&#039;&#039; has the &#039;&#039;&#039;-E&#039;&#039;&#039; command line argument and an extended version. So for &#039;&#039;&#039;sed&#039;&#039;&#039;, &#039;&#039;&#039;tr&#039;&#039;&#039; and &#039;&#039;&#039;sort&#039;&#039;&#039; you have to use &#039;&#039;&#039;\&#039;&#039;&#039;. Alternatively, in this instance where we&#039;re interested in the occurrence of uppercase and lowercase versions of a string, &#039;&#039;&#039;grep&#039;&#039;&#039; actually has a command line option for this. &lt;br /&gt;
 &#039;&#039;&#039;grep -i&#039;&#039;&#039; &#039;authors&#039; Pseudomonas_Aeruginosa_16S_rRNA.gb &lt;br /&gt;
would capture both &#039;authors&#039; and &#039;AUTHORS&#039;. It also has the improved effect of capturing stuff like &#039;Authors&#039;, &#039;aUTHORS&#039; etc.. &lt;br /&gt;
&lt;br /&gt;
=== sed === &lt;br /&gt;
The command &#039;&#039;&#039;sed&#039;&#039;&#039; stands for &#039;stream editor&#039;, and is typically used to substitute or delete patterns in files.&amp;lt;br&amp;gt; &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sed&#039;&#039;&#039; &#039;s/good/better/&#039; &amp;lt;FILE&amp;gt;&lt;br /&gt;
substitutes the first occurrence of &#039;good&#039; in each line with &#039;better&#039; in &amp;lt;file&amp;gt;. The &#039;s&#039; is &#039;substitute&#039;. You can also instead type, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sed&#039;&#039;&#039; &#039;s/nice/epic/g&#039; &amp;lt;FILE&amp;gt; &lt;br /&gt;
which substitutes all occurrences of &#039;nice with &#039;epic&#039; in each line. The &#039;g&#039; stands for global replacement. &lt;br /&gt;
&lt;br /&gt;
In the above cases, the changes that are made to &amp;lt;FILE&amp;gt; aren&#039;t saved and the stdout is directed to the terminal. This can be done by using the command option &#039;&#039;&#039;i&#039;&#039;&#039; or by using some redirectional operators, as shown in &#039;&#039;&#039;figure 5.2&#039;&#039;&#039;.  &lt;br /&gt;
&lt;br /&gt;
[[File:Sed example.png|frame|left|&#039;&#039;&#039;Figure 5.2 Using the sed command:&#039;&#039;&#039; The &#039;&#039;&#039;sed&#039;&#039;&#039; command is used to substitute occurrences of &#039;good&#039; with &#039;better&#039; and &#039;better&#039; with &#039;the best. The command option, -i, allows you edit the file in place so that changes are saved. Otherwise, the changes are  simply written to the terminal. You might be thinking that you could instead write &#039;&#039;&#039;sed&#039;&#039;&#039; &#039;s/word1/word2/&#039; sed_example.txt &amp;gt; sed_example.txt but it won&#039;t work. The shell interprets redirectional operations prior to commands, so that &#039;&amp;gt; sed_example.txt&#039; will be interpreted first and a new empty sed_example.txt is created. This effectively overwrites the original file and &#039;&#039;&#039;sed&#039;&#039;&#039; ends up processing an empty file. This sort of thing, where empty files are created, actually poses a problem for supercomputer with giant disk systems as it slows the server down. This can happen, when running automated processes with many intermediate files, where one failed subprocess results in an empty file, affecting other sub processes to produce a multitude of empty files. Therefore, it&#039;s good practice to designate intermediate files with file extensions, that make them easy to locate and delete if something goes wrong. The last example is just another way of doing &#039;&#039;&#039;sed -i&#039;&#039;&#039;, which is shown because not all versions of &#039;&#039;&#039;sed&#039;&#039;&#039; have the &#039;&#039;&#039;-i&#039;&#039;&#039; command option (Mac OS doesn&#039;t for example).]]&lt;br /&gt;
&lt;br /&gt;
You don&#039;t have to use &#039;&#039;&#039;/&#039;&#039;&#039; as the separator that separates pattern from substitution. The &#039;&#039;&#039;sed&#039;&#039;&#039; command just uses whatever is followed by &#039;&#039;&#039;s&#039;&#039;&#039; as a separator, and &#039;&#039;&#039;/&#039;&#039;&#039; just happens to be the most commonly used. You could instead write,&lt;br /&gt;
&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sed&#039;&#039;&#039; &#039;s|good|better|g&#039; &amp;lt;FILE&amp;gt;   &lt;br /&gt;
which would work perfectly fine.&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
It is also possible to specify which lines you would like to have replaced in a file.&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sed&#039;&#039;&#039; &#039;&#039;&#039;666&#039;&#039;&#039; &#039;s/nice/epic/g&#039; &amp;lt;FILE&amp;gt;&lt;br /&gt;
substitutes all occurrences of &#039;nice&#039; with &#039;epic&#039; in line 666. &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sed&#039;&#039;&#039; &#039;&#039;&#039;55,$&#039;&#039;&#039; &#039;s/nice/epic/g&#039; &amp;lt;FILE&amp;gt;&lt;br /&gt;
substitutes all occurrences of &#039;nice&#039; with &#039;epic&#039; from line 55 to the last line of &amp;lt;FILE&amp;gt;. The last line of &amp;lt;FILE&amp;gt; is indicated by the symbol, &#039;&#039;&#039;$&#039;&#039;&#039;.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The command &#039;&#039;&#039;sed&#039;&#039;&#039; can be used to delete whole lines. &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sed&#039;&#039;&#039; &#039;2d&#039; &amp;lt;FILE&amp;gt;&lt;br /&gt;
will delete the second line of &amp;lt;FILE&amp;gt;. The &#039;d&#039; stands for delete. &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sed&#039;&#039;&#039; &#039;2,4d&#039; &amp;lt;FILE&amp;gt;&lt;br /&gt;
will delete the second to fourth lines of &amp;lt;FILE&amp;gt;. &lt;br /&gt;
Lastly, you can also search for a pattern and delete lines wherein the pattern occur.&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sed&#039;&#039;&#039; &#039;/nope/d&#039; &amp;lt;FILE&amp;gt; &lt;br /&gt;
will delete any line with the pattern &#039;nope&#039; in it.  &lt;br /&gt;
&lt;br /&gt;
Lastly, it is also possible to do multiple substitutions using the syntax,&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sed&#039;&#039;&#039; &#039;s/good/better/g ; s/nice/epic/g&#039; &amp;lt;FILE&amp;gt;&lt;br /&gt;
which will all instances of good and nice with better and epic.&lt;br /&gt;
&lt;br /&gt;
=== tr ===&lt;br /&gt;
The command &#039;&#039;&#039;tr&#039;&#039;&#039; stands for translate and does exactly this, however, it can only be used to translate one character at a time. It isn&#039;t supported by regex but some of the syntax is similar. &lt;br /&gt;
A common way of using it, is to translate lowercase characters to uppercase characters. &lt;br /&gt;
&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;tr&#039;&#039;&#039; &#039;[a-z]&#039; &#039;[A-Z]&#039; &#039;&#039;&#039;&amp;lt;&#039;&#039;&#039; &amp;lt;FILE&amp;gt;   &lt;br /&gt;
will translate occurrences of lowercase characters to uppercase characters in &amp;lt;FILE&amp;gt;. &lt;br /&gt;
 Prompt$ echo &amp;quot;Tabs for spaces please&amp;quot; | &#039;&#039;&#039;tr&#039;&#039;&#039; &#039;[:space:]&#039; &#039;\t&#039;&lt;br /&gt;
will translate occurrences of spaces to tabs. &lt;br /&gt;
&lt;br /&gt;
[[File:Tr example.png|frame|none|&#039;&#039;&#039;Figure 5.3 Using the tr command:&#039;&#039;&#039; In the first line, the contents of tr_example.txt is displayed using &#039;&#039;&#039;cat&#039;&#039;&#039;, and in the second line, lowercase characters in tr_example.txt are translated to uppercase characters. In the third line spaces are translated to &#039;_&#039;, and in fourth line digits are translated to &#039;*&#039;.]]&lt;br /&gt;
&lt;br /&gt;
=== Sort === &lt;br /&gt;
The &#039;&#039;&#039;sort&#039;&#039;&#039; command is used to sort lines in files, arrange them in a particular order and output to stdout. By default, without any options given, it will sort according to what&#039;s called the ASCII (American Standard Code for Information Interchange) table. In the ASCII table, characters like &#039;a&#039;, &#039;y&#039;, &#039;n&#039;,&#039;4&#039;,&#039;6&#039; have certain values which can be given in binary, octal, decimal and hexadecimal. It is based upon these values that &#039;&#039;&#039;sort&#039;&#039;&#039;, sorts lines in files. Because &#039;&#039;&#039;sort&#039;&#039;&#039; sorts according to values in the ASCII table, it has the following features: &lt;br /&gt;
&lt;br /&gt;
* Lines starting with numbers appear before lines starting with letters&lt;br /&gt;
* Lines starting with letters will appear in alphabetical order&lt;br /&gt;
* Lines starting with uppercase letters appear before lines starting with lowercase letters &lt;br /&gt;
&lt;br /&gt;
This sorting specifications are illustrated in &#039;&#039;&#039;figure 5.4&#039;&#039;&#039;, where the &#039;&#039;&#039;sort&#039;&#039;&#039; command is used on the file, sort1_testfile.txt.&lt;br /&gt;
&lt;br /&gt;
[[File:Sort1 example.png|none|frame|&#039;&#039;&#039;Figure 5.4 Using the sort command:&#039;&#039;&#039; The lines in the sort1_testfile.txt are sorted according to the values in the ASCII table. Characters with lowest value in ASCII table will appear first, for example, as &#039;&#039;&#039;!&#039;&#039;&#039; has the lowest value it appears first]]&lt;br /&gt;
&lt;br /&gt;
You can sort files in reverse ordering by using the &#039;&#039;&#039;r&#039;&#039;&#039; command option. &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sort -r&#039;&#039;&#039; &amp;lt;FILE&amp;gt; &lt;br /&gt;
will sort the file in reverse order and output to stdout. &lt;br /&gt;
&lt;br /&gt;
When dealing with numerical data, you can use the &#039;&#039;&#039;n&#039;&#039;&#039; command option.&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sort -n&#039;&#039;&#039; &amp;lt;FILE&amp;gt;&lt;br /&gt;
will sort the file numerically and output to stdout. This can be combined with the &#039;&#039;&#039;r&#039;&#039;&#039; command option. &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sort -nr&#039;&#039;&#039; &amp;lt;FILE&amp;gt; &lt;br /&gt;
will sort the file numerically in the reverse order and output to stdout.  &lt;br /&gt;
&lt;br /&gt;
You can check whether a file has already been sorted by using the &#039;&#039;&#039;c&#039;&#039;&#039; command option &lt;br /&gt;
[[File:sort2 example.png|frame|none|&#039;&#039;&#039;Figure 5.5 Using the sort command:&#039;&#039;&#039; If a file isn&#039;t sorted, a message will appear that notifies the user of a disorder in the file. If nothing appears then the file is already sorted]]&lt;br /&gt;
&lt;br /&gt;
If you want to sort a file while also removing duplicates you can use the &#039;&#039;&#039;u&#039;&#039;&#039; command option.&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sort -u&#039;&#039;&#039; &amp;lt;FILE&amp;gt;&lt;br /&gt;
will sort the file and remove any duplicates. &lt;br /&gt;
&lt;br /&gt;
Lastly, you can sort lines in a file according to the values of one column with the &#039;&#039;&#039;k&#039;&#039;&#039; command option. For instance, if you wanted to sort according to column 4, &#039;&#039;&#039;sort -k4&#039;&#039;&#039; &amp;lt;FILE&amp;gt; in the command line. In figure 5.6, we show how one can sort numerically and according to a column.&lt;br /&gt;
&lt;br /&gt;
[[File:sort3 example.png|frame|none|&#039;&#039;&#039;Figure 5.6 Using the sort command:&#039;&#039;&#039; Here, sort2_testfile.txt is sorted numerically and according to column 2 by combining command options &#039;&#039;&#039;r&#039;&#039;&#039; and &#039;&#039;&#039;k2&#039;&#039;&#039;.]]&lt;br /&gt;
&lt;br /&gt;
=== ASCII table and numeral systems === &lt;br /&gt;
To understand how &#039;&#039;&#039;sort&#039;&#039;&#039; works, we need to clarify what is meant by binary, octal, decimal, hexadecimal systems and finally how this relates to the ASCII table. &lt;br /&gt;
&lt;br /&gt;
You&#039;re already familiar with decimal systems, as its the system most commonly used for math and anything to do with numbers. As you know, it consists of 10 unique character; 0,1,2,3,4,5,6,7,8, 9. The amount of unique characters in a numeral system is called its base or radix. Here&#039;s a video that gives a quick explanation of base systems, and how a binary system is different from a decimal system.&amp;lt;br&amp;gt; &lt;br /&gt;
[https://www.youtube.com/watch?v=LpuPe81bc2w Base systems and binary]&amp;lt;br&amp;gt; &lt;br /&gt;
When a number exceeds what you can write with these 10 characters, you simply add another slot. For instance with the number, 16, you&#039;ve added the &#039;1&#039; to the second slot and the second slot represent 10&#039;s. The reason why the decimal system is so widely used today is most likely because we humans tend to use our fingers to count, and since we have 10 fingers, the decimal system was the most logical choice.&lt;br /&gt;
&lt;br /&gt;
Binary (2), octal (8) and hexadecimal (16) base systems, are simply systems that have different bases. The binary value system consists of 2 characters, 0 and 1, and this is the system that all computers use. In computing, the 0 often corresponds to a unit being turned off, and 1 corresponds to a unit being turned on. Because the binary system only consists of 2 characters, you have to change slots more often than you would in the decimal system. In the binary system, these slots are in fact what&#039;s called &#039;&#039;bits&#039;&#039;, something you might have heard about but not actually known what meant. The number of bits can vary, for instance, you might&#039;ve heard about operating systems being 32 bit or 64 bit.  &lt;br /&gt;
&lt;br /&gt;
Let&#039;s learn by example by translating decimal values to binary values. The ASCII table uses 7 bits, which we&#039;ll use as well. The values of each bit in a binary system is; 64(7), 32(6), 16(5), 8(4), 4(3), 2(2), 1(1) . To clarify, these bit values are what would correspond to the slot values; 100.0000(7), 100.000(6), 10.000(5), 1000(4), 100(3), 10(2), 1(1) in the decimal value system.&amp;lt;br&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
In the table underneath there are 4 examples ASCII characters with corresponding decimal and binary combination. When summed, every binary combination results in a unique decimal value. &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Binary value (7 bits): 64 32 16 8 4 2 1 &lt;br /&gt;
!Decimal value&lt;br /&gt;
!Character in ASCII table&lt;br /&gt;
|-&lt;br /&gt;
|0 0 1 0 1 0 1&lt;br /&gt;
|0+0+16+0+4+0+1=21&lt;br /&gt;
|!&lt;br /&gt;
|-&lt;br /&gt;
|1 0 0 0 0 0 1&lt;br /&gt;
|64+0+0+0+0+0+1=65&lt;br /&gt;
|A&lt;br /&gt;
|-&lt;br /&gt;
|0 1 1 0 1 1 0&lt;br /&gt;
|0+32+16+0+4+2+0=54&lt;br /&gt;
|6  &lt;br /&gt;
|-&lt;br /&gt;
|1 1 1 1 1 1 1&lt;br /&gt;
|64+32+16+8+4+2+1=127&lt;br /&gt;
|Del  &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The ASCII table has 127 characters, a limit that is set by it having 7 bits which amounts to 127 combinations. It includes the characters A-Z, a-z, 0-9 and other characters which you can see by using the &#039;&#039;&#039;man&#039;&#039;&#039; command, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;man&#039;&#039;&#039; ascii&lt;br /&gt;
This will show you a table of all 127 characters, the binary values however, are not shown. Instead only the octal, decimal and hexadecimal values are shown. &lt;br /&gt;
&lt;br /&gt;
The octal system consists of 8 unique characters; 0,1,2,3,4,5,6,7. Therefore, a value exceeding this, for instance 8 in decimal value, would be translated to 010 in the octal system. The octal system is used in computer software to simplify binary input, but interestingly, it has also been used by the indigenous american yuki people who used the space between their fingers to count.&lt;br /&gt;
&lt;br /&gt;
The hexadecimal system consists of 16 unique characters; 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F. As the hexadecimal system uses 6 more unique characters than the decimal system, then changing slots happens less frequently. For instance, a decimal value of 12 would translate to 0B in the hexadecimal system.&lt;br /&gt;
&lt;br /&gt;
The ASCII table only covers 127 characters but there exists a lot more characters than this, therefore, another system with more bits called &#039;&#039;Unicode&#039;&#039; is often used. If you&#039;re interested, here&#039;s a five minute introductory video explaining ASCII and Unicode [https://www.youtube.com/watch?v=5aJKKgSEUnY Introductory video on ASCII and Unicode].&lt;br /&gt;
&lt;br /&gt;
== Exercise 1: Extracting and sorting data from a Gene Bank files == &lt;br /&gt;
You&#039;ve been given the task to extract and sort data from some genebank files, [https://teaching.healthtech.dtu.dk/material/unix/Genebankfiles.gb Genebank files]. More specifically, you need to extract the authors, accession number and the name of the organism and save in 3 different files.     &lt;br /&gt;
&lt;br /&gt;
1. Extract the lines with authors from Genebankfiles.gb, sort it and save the output to one file.&amp;lt;br&amp;gt;&lt;br /&gt;
2. Extract the lines with accession numbers from Genebankfiles.gb, sort it and save the output to a second file.&amp;lt;br&amp;gt;&lt;br /&gt;
3. Extract the lines with organisms from Genebankfiles.gb, sort it, and save the output to a third file.&amp;lt;br&amp;gt;&lt;br /&gt;
4. As you don&#039;t know when you&#039;re going to need to do this again, you want to write a shell script that does the functions of questions 1-3. Make a simple shell script that appends authors, accession numbers and organisms to the files you made in questions 1-3.&lt;br /&gt;
&lt;br /&gt;
== Exercise 2: Translating ASCII characters to binary and decimal values ==&lt;br /&gt;
In this exercise, you&#039;ll be working with [https://teaching.healthtech.dtu.dk/material/unix/ASCII_chars.dat ASCII character file]&amp;lt;br&amp;gt;, which contains ASCII characters, and [https://teaching.healthtech.dtu.dk/material/unix/Binary.dat Binary data file] which contains corresponding binary data. The ASCII characters --&amp;gt; corresponding decimal values are listed hereunder:&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;{&#039;&#039;&#039; --&amp;gt; &#039;&#039;&#039;125&#039;&#039;&#039;&amp;lt;br&amp;gt; &#039;&#039;&#039;a&#039;&#039;&#039; --&amp;gt; &#039;&#039;&#039;97&#039;&#039;&#039;&amp;lt;br&amp;gt; &#039;&#039;&#039;p&#039;&#039;&#039; --&amp;gt; &#039;&#039;&#039;112&#039;&#039;&#039;&amp;lt;br&amp;gt; &#039;&#039;&#039;X&#039;&#039;&#039;--&amp;gt; &#039;&#039;&#039;88&#039;&#039;&#039;&amp;lt;br&amp;gt;&#039;&#039;&#039;+&#039;&#039;&#039; --&amp;gt; &#039;&#039;&#039;43&#039;&#039;&#039;&amp;lt;br&amp;gt;&#039;&#039;&#039;/&#039;&#039;&#039; --&amp;gt; &#039;&#039;&#039;47&#039;&#039;&#039;&amp;lt;br&amp;gt; &#039;&#039;&#039;$&#039;&#039;&#039; --&amp;gt; &#039;&#039;&#039;36&#039;&#039;&#039;&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
1. Translate all the ASCII characters to decimal values and save the output to Decimals.dat (See &#039;&#039;&#039;Hint 1&#039;&#039;&#039;).&amp;lt;br&amp;gt;&lt;br /&gt;
2. Merge ASCII_chars.dat, Binary.dat and Decimals.dat so that column 1; ASCII chars, column 2; Binary data and column 3; Decimal values. Save the output to Merge.dat and then delete Decimals.dat. &amp;lt;br&amp;gt;&lt;br /&gt;
3. Sort Merge.dat based on the decimal values.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Hint 1:&#039;&#039;&#039; This is tedious problem, as there are a lot of ASCII characters that need to be translated. The best way to do this with your current skill level is to use &#039;&#039;&#039;sed&#039;&#039;&#039; &#039;s/blah1/blah2/g ; s/blah3/blah4/g ; ... s/blah98/blah99/g&#039; &#039;&#039;&#039;&amp;gt;&#039;&#039;&#039; Decimals.dat). Also, remember to use &#039;&#039;&#039;\&#039;&#039;&#039; for special characters like &#039;&#039;&#039;$&#039;&#039;&#039;.&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/unix/index.php?title=Filtering_and_regular_expressions&amp;diff=44</id>
		<title>Filtering and regular expressions</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/unix/index.php?title=Filtering_and_regular_expressions&amp;diff=44"/>
		<updated>2024-03-20T12:11:29Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Exercise 1: Extracting and sorting data from a Gene Bank files */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
You can think of regular expressions (regex for short) as a pattern language that can be used to match patterns and filter data. In this section, we&#039;ll be learning so-called &#039;&#039;filter commands&#039;&#039;, some of which utilize regular expressions in order to find and replace patterns. It is therefore important to have a basic understanding of regular expressions. To get you started, follow this link to an introductory video, [https://www.youtube.com/watch?v=KJG1dETacLI Basic Regular Expression Introduction Video], which gives a basic understanding of the concepts of regular expressions. &lt;br /&gt;
&lt;br /&gt;
Next, you can follow this link [https://regexone.com/lesson/introduction_abcs Regex Introduction Exercises], where there&#039;s some exercises on basic regex. The &#039;Practice problems&#039; are a bit more complex, but should still be doable. They are, however, optional.  &lt;br /&gt;
&lt;br /&gt;
[https://www.cheatography.com/davechild/cheat-sheets/regular-expressions/pdf/ Regex cheat sheet]&lt;br /&gt;
&lt;br /&gt;
== Introduction to commands ==  &lt;br /&gt;
Now that you&#039;ve been initiated in regular expressions, we&#039;ll take a look at some Unix commands that can use regular expressions. Underneath we list commands and syntax for the commands that we&#039;ll be using in this section. &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Unix Command&lt;br /&gt;
!Acronym translation &lt;br /&gt;
!Description&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;grep&#039;&#039;&#039; [PATTERN] &amp;lt;FILE&amp;gt;&lt;br /&gt;
|Global regular expression print. &lt;br /&gt;
|Uses regular expressions select lines in a file that matches the pattern. &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;sed&#039;&#039;&#039; [OPTION] &amp;lt;SCRIPT&amp;gt; &amp;lt;FILE&amp;gt;&lt;br /&gt;
|stream editor&lt;br /&gt;
|Allows user to edit files without actually opening the files using regular expressions.&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;tr&#039;&#039;&#039; [OPTION] &amp;lt;SET1&amp;gt; &amp;lt;SET2&amp;gt;&lt;br /&gt;
|Translate&lt;br /&gt;
|Translates characters from the standard input and writes to the standard output.  &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;sort&#039;&#039;&#039; [OPTION] &amp;lt;FILE&amp;gt;&lt;br /&gt;
|&amp;lt;nowiki&amp;gt;-&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|Sorts the content of a file.  &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Datafile 1: [https://teaching.healthtech.dtu.dk/material/unix/Pseudomonas_Aeruginosa_16SrRNA.gb Pseudomonas Aeruginosa 16S rRNA Genebank file]&amp;lt;br&amp;gt; &lt;br /&gt;
Datafile 2: [https://teaching.healthtech.dtu.dk/material/unix/Genebankfiles.gb Genebank files] &amp;lt;br&amp;gt;&lt;br /&gt;
Datafile 3: [https://teaching.healthtech.dtu.dk/material/unix/ASCII_chars.dat ASCII character file]&amp;lt;br&amp;gt;&lt;br /&gt;
Datafile 4: [https://teaching.healthtech.dtu.dk/material/unix/Ex1_7bit_binarydata.dat Binary data file]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== grep ===&lt;br /&gt;
The &#039;&#039;&#039;grep&#039;&#039;&#039; command uses regular expressions as search patterns to capture patterns in files and outputs it to stdout. It has the syntax, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;grep&#039;&#039;&#039; [OPTION] &amp;lt;PATTERN&amp;gt; &amp;lt;FILE&amp;gt;&lt;br /&gt;
In &#039;&#039;&#039;figure 5.1&#039;&#039;&#039;, the &#039;&#039;&#039;grep&#039;&#039;&#039; command is used to capture the line containing the authors of a text, which is then redirected to a text file. &lt;br /&gt;
[[File:Grep example.png|none|frame|&#039;&#039;&#039;Figure 5.1 Using the grep command:&#039;&#039;&#039; Here, &#039;&#039;&#039;grep&#039;&#039;&#039; is used capture the line containing the authors of the file and saving it to &amp;lt;AUTHORFILE.txt&amp;gt;.]]&lt;br /&gt;
&lt;br /&gt;
But before you start using this sections commands you should know that Bash (recall that this is the shell that you&#039;re working in) uses basic regex and not extended regex by default. For example, if you wanted to search for occurrences of &#039;AUTHORS&#039; or &#039;authors&#039;&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;grep&#039;&#039;&#039; &#039;AUTHORS|authors&#039; Pseudomonas_Aeruginosa_16S_rRNA.gb &lt;br /&gt;
there would be no results, as Bash doesn&#039;t interpret &#039;|&#039; as a special character. There are 3 solutions to this problem. &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;grep&#039;&#039;&#039; &#039;AUTHORS\|authors&#039; Pseudomonas_Aeruginosa_16S_rRNA.gb &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;egrep&#039;&#039;&#039; &#039;AUTHORS|authors&#039; Pseudomonas_Aeruginosa_16S_rRNA.gb&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;grep -E&#039;&#039;&#039; &#039;AUTHORS|authors&#039; Pseudomonas_Aeruginosa_16S_rRNA.gb&lt;br /&gt;
In the first solution, we use &#039;\&#039; to designate that &#039;|&#039; is to be interpreted as a special character. The second and third solution are similar, as they both use an extended version of &#039;&#039;&#039;grep&#039;&#039;&#039;, so that Bash interprets extended regex. However, only &#039;&#039;&#039;grep&#039;&#039;&#039; has the &#039;&#039;&#039;-E&#039;&#039;&#039; command line argument and an extended version. So for &#039;&#039;&#039;sed&#039;&#039;&#039;, &#039;&#039;&#039;tr&#039;&#039;&#039; and &#039;&#039;&#039;sort&#039;&#039;&#039; you have to use &#039;&#039;&#039;\&#039;&#039;&#039;. Alternatively, in this instance where we&#039;re interested in the occurrence of uppercase and lowercase versions of a string, &#039;&#039;&#039;grep&#039;&#039;&#039; actually has a command line option for this. &lt;br /&gt;
 &#039;&#039;&#039;grep -i&#039;&#039;&#039; &#039;authors&#039; Pseudomonas_Aeruginosa_16S_rRNA.gb &lt;br /&gt;
would capture both &#039;authors&#039; and &#039;AUTHORS&#039;. It also has the improved effect of capturing stuff like &#039;Authors&#039;, &#039;aUTHORS&#039; etc.. &lt;br /&gt;
&lt;br /&gt;
=== sed === &lt;br /&gt;
The command &#039;&#039;&#039;sed&#039;&#039;&#039; stands for &#039;stream editor&#039;, and is typically used to substitute or delete patterns in files.&amp;lt;br&amp;gt; &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sed&#039;&#039;&#039; &#039;s/good/better/&#039; &amp;lt;FILE&amp;gt;&lt;br /&gt;
substitutes the first occurrence of &#039;good&#039; in each line with &#039;better&#039; in &amp;lt;file&amp;gt;. The &#039;s&#039; is &#039;substitute&#039;. You can also instead type, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sed&#039;&#039;&#039; &#039;s/nice/epic/g&#039; &amp;lt;FILE&amp;gt; &lt;br /&gt;
which substitutes all occurrences of &#039;nice with &#039;epic&#039; in each line. The &#039;g&#039; stands for global replacement. &lt;br /&gt;
&lt;br /&gt;
In the above cases, the changes that are made to &amp;lt;FILE&amp;gt; aren&#039;t saved and the stdout is directed to the terminal. This can be done by using the command option &#039;&#039;&#039;i&#039;&#039;&#039; or by using some redirectional operators, as shown in &#039;&#039;&#039;figure 5.2&#039;&#039;&#039;.  &lt;br /&gt;
&lt;br /&gt;
[[File:Sed example.png|frame|left|&#039;&#039;&#039;Figure 5.2 Using the sed command:&#039;&#039;&#039; The &#039;&#039;&#039;sed&#039;&#039;&#039; command is used to substitute occurrences of &#039;good&#039; with &#039;better&#039; and &#039;better&#039; with &#039;the best. The command option, -i, allows you edit the file in place so that changes are saved. Otherwise, the changes are  simply written to the terminal. You might be thinking that you could instead write &#039;&#039;&#039;sed&#039;&#039;&#039; &#039;s/word1/word2/&#039; sed_example.txt &amp;gt; sed_example.txt but it won&#039;t work. The shell interprets redirectional operations prior to commands, so that &#039;&amp;gt; sed_example.txt&#039; will be interpreted first and a new empty sed_example.txt is created. This effectively overwrites the original file and &#039;&#039;&#039;sed&#039;&#039;&#039; ends up processing an empty file. This sort of thing, where empty files are created, actually poses a problem for supercomputer with giant disk systems as it slows the server down. This can happen, when running automated processes with many intermediate files, where one failed subprocess results in an empty file, affecting other sub processes to produce a multitude of empty files. Therefore, it&#039;s good practice to designate intermediate files with file extensions, that make them easy to locate and delete if something goes wrong. The last example is just another way of doing &#039;&#039;&#039;sed -i&#039;&#039;&#039;, which is shown because not all versions of &#039;&#039;&#039;sed&#039;&#039;&#039; have the &#039;&#039;&#039;-i&#039;&#039;&#039; command option (Mac OS doesn&#039;t for example).]]&lt;br /&gt;
&lt;br /&gt;
You don&#039;t have to use &#039;&#039;&#039;/&#039;&#039;&#039; as the separator that separates pattern from substitution. The &#039;&#039;&#039;sed&#039;&#039;&#039; command just uses whatever is followed by &#039;&#039;&#039;s&#039;&#039;&#039; as a separator, and &#039;&#039;&#039;/&#039;&#039;&#039; just happens to be the most commonly used. You could instead write,&lt;br /&gt;
&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sed&#039;&#039;&#039; &#039;s|good|better|g&#039; &amp;lt;FILE&amp;gt;   &lt;br /&gt;
which would work perfectly fine.&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
It is also possible to specify which lines you would like to have replaced in a file.&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sed&#039;&#039;&#039; &#039;&#039;&#039;666&#039;&#039;&#039; &#039;s/nice/epic/g&#039; &amp;lt;FILE&amp;gt;&lt;br /&gt;
substitutes all occurrences of &#039;nice&#039; with &#039;epic&#039; in line 666. &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sed&#039;&#039;&#039; &#039;&#039;&#039;55,$&#039;&#039;&#039; &#039;s/nice/epic/g&#039; &amp;lt;FILE&amp;gt;&lt;br /&gt;
substitutes all occurrences of &#039;nice&#039; with &#039;epic&#039; from line 55 to the last line of &amp;lt;FILE&amp;gt;. The last line of &amp;lt;FILE&amp;gt; is indicated by the symbol, &#039;&#039;&#039;$&#039;&#039;&#039;.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The command &#039;&#039;&#039;sed&#039;&#039;&#039; can be used to delete whole lines. &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sed&#039;&#039;&#039; &#039;2d&#039; &amp;lt;FILE&amp;gt;&lt;br /&gt;
will delete the second line of &amp;lt;FILE&amp;gt;. The &#039;d&#039; stands for delete. &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sed&#039;&#039;&#039; &#039;2,4d&#039; &amp;lt;FILE&amp;gt;&lt;br /&gt;
will delete the second to fourth lines of &amp;lt;FILE&amp;gt;. &lt;br /&gt;
Lastly, you can also search for a pattern and delete lines wherein the pattern occur.&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sed&#039;&#039;&#039; &#039;/nope/d&#039; &amp;lt;FILE&amp;gt; &lt;br /&gt;
will delete any line with the pattern &#039;nope&#039; in it.  &lt;br /&gt;
&lt;br /&gt;
Lastly, it is also possible to do multiple substitutions using the syntax,&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sed&#039;&#039;&#039; &#039;s/good/better/g ; s/nice/epic/g&#039; &amp;lt;FILE&amp;gt;&lt;br /&gt;
which will all instances of good and nice with better and epic.&lt;br /&gt;
&lt;br /&gt;
=== tr ===&lt;br /&gt;
The command &#039;&#039;&#039;tr&#039;&#039;&#039; stands for translate and does exactly this, however, it can only be used to translate one character at a time. It isn&#039;t supported by regex but some of the syntax is similar. &lt;br /&gt;
A common way of using it, is to translate lowercase characters to uppercase characters. &lt;br /&gt;
&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;tr&#039;&#039;&#039; &#039;[a-z]&#039; &#039;[A-Z]&#039; &#039;&#039;&#039;&amp;lt;&#039;&#039;&#039; &amp;lt;FILE&amp;gt;   &lt;br /&gt;
will translate occurrences of lowercase characters to uppercase characters in &amp;lt;FILE&amp;gt;. &lt;br /&gt;
 Prompt$ echo &amp;quot;Tabs for spaces please&amp;quot; | &#039;&#039;&#039;tr&#039;&#039;&#039; &#039;[:space:]&#039; &#039;\t&#039;&lt;br /&gt;
will translate occurrences of spaces to tabs. &lt;br /&gt;
&lt;br /&gt;
[[File:Tr example.png|frame|none|&#039;&#039;&#039;Figure 5.3 Using the tr command:&#039;&#039;&#039; In the first line, the contents of tr_example.txt is displayed using &#039;&#039;&#039;cat&#039;&#039;&#039;, and in the second line, lowercase characters in tr_example.txt are translated to uppercase characters. In the third line spaces are translated to &#039;_&#039;, and in fourth line digits are translated to &#039;*&#039;.]]&lt;br /&gt;
&lt;br /&gt;
=== Sort === &lt;br /&gt;
The &#039;&#039;&#039;sort&#039;&#039;&#039; command is used to sort lines in files, arrange them in a particular order and output to stdout. By default, without any options given, it will sort according to what&#039;s called the ASCII (American Standard Code for Information Interchange) table. In the ASCII table, characters like &#039;a&#039;, &#039;y&#039;, &#039;n&#039;,&#039;4&#039;,&#039;6&#039; have certain values which can be given in binary, octal, decimal and hexadecimal. It is based upon these values that &#039;&#039;&#039;sort&#039;&#039;&#039;, sorts lines in files. Because &#039;&#039;&#039;sort&#039;&#039;&#039; sorts according to values in the ASCII table, it has the following features: &lt;br /&gt;
&lt;br /&gt;
* Lines starting with numbers appear before lines starting with letters&lt;br /&gt;
* Lines starting with letters will appear in alphabetical order&lt;br /&gt;
* Lines starting with uppercase letters appear before lines starting with lowercase letters &lt;br /&gt;
&lt;br /&gt;
This sorting specifications are illustrated in &#039;&#039;&#039;figure 5.4&#039;&#039;&#039;, where the &#039;&#039;&#039;sort&#039;&#039;&#039; command is used on the file, sort1_testfile.txt.&lt;br /&gt;
&lt;br /&gt;
[[File:Sort1 example.png|none|frame|&#039;&#039;&#039;Figure 5.4 Using the sort command:&#039;&#039;&#039; The lines in the sort1_testfile.txt are sorted according to the values in the ASCII table. Characters with lowest value in ASCII table will appear first, for example, as &#039;&#039;&#039;!&#039;&#039;&#039; has the lowest value it appears first]]&lt;br /&gt;
&lt;br /&gt;
You can sort files in reverse ordering by using the &#039;&#039;&#039;r&#039;&#039;&#039; command option. &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sort -r&#039;&#039;&#039; &amp;lt;FILE&amp;gt; &lt;br /&gt;
will sort the file in reverse order and output to stdout. &lt;br /&gt;
&lt;br /&gt;
When dealing with numerical data, you can use the &#039;&#039;&#039;n&#039;&#039;&#039; command option.&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sort -n&#039;&#039;&#039; &amp;lt;FILE&amp;gt;&lt;br /&gt;
will sort the file numerically and output to stdout. This can be combined with the &#039;&#039;&#039;r&#039;&#039;&#039; command option. &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sort -nr&#039;&#039;&#039; &amp;lt;FILE&amp;gt; &lt;br /&gt;
will sort the file numerically in the reverse order and output to stdout.  &lt;br /&gt;
&lt;br /&gt;
You can check whether a file has already been sorted by using the &#039;&#039;&#039;c&#039;&#039;&#039; command option &lt;br /&gt;
[[File:sort2 example.png|frame|none|&#039;&#039;&#039;Figure 5.5 Using the sort command:&#039;&#039;&#039; If a file isn&#039;t sorted, a message will appear that notifies the user of a disorder in the file. If nothing appears then the file is already sorted]]&lt;br /&gt;
&lt;br /&gt;
If you want to sort a file while also removing duplicates you can use the &#039;&#039;&#039;u&#039;&#039;&#039; command option.&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sort -u&#039;&#039;&#039; &amp;lt;FILE&amp;gt;&lt;br /&gt;
will sort the file and remove any duplicates. &lt;br /&gt;
&lt;br /&gt;
Lastly, you can sort lines in a file according to the values of one column with the &#039;&#039;&#039;k&#039;&#039;&#039; command option. For instance, if you wanted to sort according to column 4, &#039;&#039;&#039;sort -k4&#039;&#039;&#039; &amp;lt;FILE&amp;gt; in the command line. In figure 5.6, we show how one can sort numerically and according to a column.&lt;br /&gt;
&lt;br /&gt;
[[File:sort3 example.png|frame|none|&#039;&#039;&#039;Figure 5.6 Using the sort command:&#039;&#039;&#039; Here, sort2_testfile.txt is sorted numerically and according to column 2 by combining command options &#039;&#039;&#039;r&#039;&#039;&#039; and &#039;&#039;&#039;k2&#039;&#039;&#039;.]]&lt;br /&gt;
&lt;br /&gt;
=== ASCII table and numeral systems === &lt;br /&gt;
To understand how &#039;&#039;&#039;sort&#039;&#039;&#039; works, we need to clarify what is meant by binary, octal, decimal, hexadecimal systems and finally how this relates to the ASCII table. &lt;br /&gt;
&lt;br /&gt;
You&#039;re already familiar with decimal systems, as its the system most commonly used for math and anything to do with numbers. As you know, it consists of 10 unique character; 0,1,2,3,4,5,6,7,8, 9. The amount of unique characters in a numeral system is called its base or radix. Here&#039;s a video that gives a quick explanation of base systems, and how a binary system is different from a decimal system.&amp;lt;br&amp;gt; &lt;br /&gt;
[https://www.youtube.com/watch?v=LpuPe81bc2w Base systems and binary]&amp;lt;br&amp;gt; &lt;br /&gt;
When a number exceeds what you can write with these 10 characters, you simply add another slot. For instance with the number, 16, you&#039;ve added the &#039;1&#039; to the second slot and the second slot represent 10&#039;s. The reason why the decimal system is so widely used today is most likely because we humans tend to use our fingers to count, and since we have 10 fingers, the decimal system was the most logical choice.&lt;br /&gt;
&lt;br /&gt;
Binary (2), octal (8) and hexadecimal (16) base systems, are simply systems that have different bases. The binary value system consists of 2 characters, 0 and 1, and this is the system that all computers use. In computing, the 0 often corresponds to a unit being turned off, and 1 corresponds to a unit being turned on. Because the binary system only consists of 2 characters, you have to change slots more often than you would in the decimal system. In the binary system, these slots are in fact what&#039;s called &#039;&#039;bits&#039;&#039;, something you might have heard about but not actually known what meant. The number of bits can vary, for instance, you might&#039;ve heard about operating systems being 32 bit or 64 bit.  &lt;br /&gt;
&lt;br /&gt;
Let&#039;s learn by example by translating decimal values to binary values. The ASCII table uses 7 bits, which we&#039;ll use as well. The values of each bit in a binary system is; 64(7), 32(6), 16(5), 8(4), 4(3), 2(2), 1(1) . To clarify, these bit values are what would correspond to the slot values; 100.0000(7), 100.000(6), 10.000(5), 1000(4), 100(3), 10(2), 1(1) in the decimal value system.&amp;lt;br&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
In the table underneath there are 4 examples ASCII characters with corresponding decimal and binary combination. When summed, every binary combination results in a unique decimal value. &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Binary value (7 bits): 64 32 16 8 4 2 1 &lt;br /&gt;
!Decimal value&lt;br /&gt;
!Character in ASCII table&lt;br /&gt;
|-&lt;br /&gt;
|0 0 1 0 1 0 1&lt;br /&gt;
|0+0+16+0+4+0+1=21&lt;br /&gt;
|!&lt;br /&gt;
|-&lt;br /&gt;
|1 0 0 0 0 0 1&lt;br /&gt;
|64+0+0+0+0+0+1=65&lt;br /&gt;
|A&lt;br /&gt;
|-&lt;br /&gt;
|0 1 1 0 1 1 0&lt;br /&gt;
|0+32+16+0+4+2+0=54&lt;br /&gt;
|6  &lt;br /&gt;
|-&lt;br /&gt;
|1 1 1 1 1 1 1&lt;br /&gt;
|64+32+16+8+4+2+1=127&lt;br /&gt;
|Del  &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The ASCII table has 127 characters, a limit that is set by it having 7 bits which amounts to 127 combinations. It includes the characters A-Z, a-z, 0-9 and other characters which you can see by using the &#039;&#039;&#039;man&#039;&#039;&#039; command, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;man&#039;&#039;&#039; ascii&lt;br /&gt;
This will show you a table of all 127 characters, the binary values however, are not shown. Instead only the octal, decimal and hexadecimal values are shown. &lt;br /&gt;
&lt;br /&gt;
The octal system consists of 8 unique characters; 0,1,2,3,4,5,6,7. Therefore, a value exceeding this, for instance 8 in decimal value, would be translated to 010 in the octal system. The octal system is used in computer software to simplify binary input, but interestingly, it has also been used by the indigenous american yuki people who used the space between their fingers to count.&lt;br /&gt;
&lt;br /&gt;
The hexadecimal system consists of 16 unique characters; 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F. As the hexadecimal system uses 6 more unique characters than the decimal system, then changing slots happens less frequently. For instance, a decimal value of 12 would translate to 0B in the hexadecimal system.&lt;br /&gt;
&lt;br /&gt;
The ASCII table only covers 127 characters but there exists a lot more characters than this, therefore, another system with more bits called &#039;&#039;Unicode&#039;&#039; is often used. If you&#039;re interested, here&#039;s a five minute introductory video explaining ASCII and Unicode [https://www.youtube.com/watch?v=5aJKKgSEUnY Introductory video on ASCII and Unicode].&lt;br /&gt;
&lt;br /&gt;
== Exercise 1: Extracting and sorting data from a Gene Bank files == &lt;br /&gt;
You&#039;ve been given the task to extract and sort data from some genebank files, [https://teaching.healthtech.dtu.dk/material/unix/Genebankfiles.gb Genebank files]. More specifically, you need to extract the authors, accession number and the name of the organism and save in 3 different files.     &lt;br /&gt;
&lt;br /&gt;
1. Extract the lines with authors from Genebankfiles.gb, sort it and save the output to one file.&amp;lt;br&amp;gt;&lt;br /&gt;
2. Extract the lines with accession numbers from Genebankfiles.gb, sort it and save the output to a second file.&amp;lt;br&amp;gt;&lt;br /&gt;
3. Extract the lines with organisms from Genebankfiles.gb, sort it, and save the output to a third file.&amp;lt;br&amp;gt;&lt;br /&gt;
4. As you don&#039;t know when you&#039;re going to need to do this again, you want to write a shell script that does the functions of questions 1-3. Make a simple shell script that appends authors, accession numbers and organisms to the files you made in questions 1-3.&lt;br /&gt;
&lt;br /&gt;
== Exercise 2: Translating ASCII characters to binary and decimal values ==&lt;br /&gt;
In this exercise, you&#039;ll be working with [http://teaching.healthtech.dtu.dk/material/unix/ASCII_chars.dat ASCII character file]&amp;lt;br&amp;gt;, which contains ASCII characters, and [http://teaching.healthtech.dtu.dk/material/unix/Binary.dat Binary data file] which contains corresponding binary data. The ASCII characters --&amp;gt; corresponding decimal values are listed hereunder:&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;{&#039;&#039;&#039; --&amp;gt; &#039;&#039;&#039;125&#039;&#039;&#039;&amp;lt;br&amp;gt; &#039;&#039;&#039;a&#039;&#039;&#039; --&amp;gt; &#039;&#039;&#039;97&#039;&#039;&#039;&amp;lt;br&amp;gt; &#039;&#039;&#039;p&#039;&#039;&#039; --&amp;gt; &#039;&#039;&#039;112&#039;&#039;&#039;&amp;lt;br&amp;gt; &#039;&#039;&#039;X&#039;&#039;&#039;--&amp;gt; &#039;&#039;&#039;88&#039;&#039;&#039;&amp;lt;br&amp;gt;&#039;&#039;&#039;+&#039;&#039;&#039; --&amp;gt; &#039;&#039;&#039;43&#039;&#039;&#039;&amp;lt;br&amp;gt;&#039;&#039;&#039;/&#039;&#039;&#039; --&amp;gt; &#039;&#039;&#039;47&#039;&#039;&#039;&amp;lt;br&amp;gt; &#039;&#039;&#039;$&#039;&#039;&#039; --&amp;gt; &#039;&#039;&#039;36&#039;&#039;&#039;&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
1. Translate all the ASCII characters to decimal values and save the output to Decimals.dat (See &#039;&#039;&#039;Hint 1&#039;&#039;&#039;).&amp;lt;br&amp;gt;&lt;br /&gt;
2. Merge ASCII_chars.dat, Binary.dat and Decimals.dat so that column 1; ASCII chars, column 2; Binary data and column 3; Decimal values. Save the output to Merge.dat and then delete Decimals.dat. &amp;lt;br&amp;gt;&lt;br /&gt;
3. Sort Merge.dat based on the decimal values.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Hint 1:&#039;&#039;&#039; This is tedious problem, as there are a lot of ASCII characters that need to be translated. The best way to do this with your current skill level is to use &#039;&#039;&#039;sed&#039;&#039;&#039; &#039;s/blah1/blah2/g ; s/blah3/blah4/g ; ... s/blah98/blah99/g&#039; &#039;&#039;&#039;&amp;gt;&#039;&#039;&#039; Decimals.dat). Also, remember to use &#039;&#039;&#039;\&#039;&#039;&#039; for special characters like &#039;&#039;&#039;$&#039;&#039;&#039;.&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/unix/index.php?title=File:Sort3_example.png&amp;diff=43</id>
		<title>File:Sort3 example.png</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/unix/index.php?title=File:Sort3_example.png&amp;diff=43"/>
		<updated>2024-03-20T12:10:58Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/unix/index.php?title=File:Sort2_example.png&amp;diff=42</id>
		<title>File:Sort2 example.png</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/unix/index.php?title=File:Sort2_example.png&amp;diff=42"/>
		<updated>2024-03-20T12:10:38Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/unix/index.php?title=File:Sort1_example.png&amp;diff=41</id>
		<title>File:Sort1 example.png</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/unix/index.php?title=File:Sort1_example.png&amp;diff=41"/>
		<updated>2024-03-20T12:10:18Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/unix/index.php?title=File:Tr_example.png&amp;diff=40</id>
		<title>File:Tr example.png</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/unix/index.php?title=File:Tr_example.png&amp;diff=40"/>
		<updated>2024-03-20T12:09:54Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/unix/index.php?title=File:Sed_example.png&amp;diff=39</id>
		<title>File:Sed example.png</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/unix/index.php?title=File:Sed_example.png&amp;diff=39"/>
		<updated>2024-03-20T12:09:31Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/unix/index.php?title=File:Grep_example.png&amp;diff=38</id>
		<title>File:Grep example.png</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/unix/index.php?title=File:Grep_example.png&amp;diff=38"/>
		<updated>2024-03-20T12:09:08Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/unix/index.php?title=Filtering_and_regular_expressions&amp;diff=37</id>
		<title>Filtering and regular expressions</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/unix/index.php?title=Filtering_and_regular_expressions&amp;diff=37"/>
		<updated>2024-03-20T12:08:33Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Introduction to commands */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
You can think of regular expressions (regex for short) as a pattern language that can be used to match patterns and filter data. In this section, we&#039;ll be learning so-called &#039;&#039;filter commands&#039;&#039;, some of which utilize regular expressions in order to find and replace patterns. It is therefore important to have a basic understanding of regular expressions. To get you started, follow this link to an introductory video, [https://www.youtube.com/watch?v=KJG1dETacLI Basic Regular Expression Introduction Video], which gives a basic understanding of the concepts of regular expressions. &lt;br /&gt;
&lt;br /&gt;
Next, you can follow this link [https://regexone.com/lesson/introduction_abcs Regex Introduction Exercises], where there&#039;s some exercises on basic regex. The &#039;Practice problems&#039; are a bit more complex, but should still be doable. They are, however, optional.  &lt;br /&gt;
&lt;br /&gt;
[https://www.cheatography.com/davechild/cheat-sheets/regular-expressions/pdf/ Regex cheat sheet]&lt;br /&gt;
&lt;br /&gt;
== Introduction to commands ==  &lt;br /&gt;
Now that you&#039;ve been initiated in regular expressions, we&#039;ll take a look at some Unix commands that can use regular expressions. Underneath we list commands and syntax for the commands that we&#039;ll be using in this section. &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Unix Command&lt;br /&gt;
!Acronym translation &lt;br /&gt;
!Description&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;grep&#039;&#039;&#039; [PATTERN] &amp;lt;FILE&amp;gt;&lt;br /&gt;
|Global regular expression print. &lt;br /&gt;
|Uses regular expressions select lines in a file that matches the pattern. &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;sed&#039;&#039;&#039; [OPTION] &amp;lt;SCRIPT&amp;gt; &amp;lt;FILE&amp;gt;&lt;br /&gt;
|stream editor&lt;br /&gt;
|Allows user to edit files without actually opening the files using regular expressions.&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;tr&#039;&#039;&#039; [OPTION] &amp;lt;SET1&amp;gt; &amp;lt;SET2&amp;gt;&lt;br /&gt;
|Translate&lt;br /&gt;
|Translates characters from the standard input and writes to the standard output.  &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;sort&#039;&#039;&#039; [OPTION] &amp;lt;FILE&amp;gt;&lt;br /&gt;
|&amp;lt;nowiki&amp;gt;-&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|Sorts the content of a file.  &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Datafile 1: [https://teaching.healthtech.dtu.dk/material/unix/Pseudomonas_Aeruginosa_16SrRNA.gb Pseudomonas Aeruginosa 16S rRNA Genebank file]&amp;lt;br&amp;gt; &lt;br /&gt;
Datafile 2: [https://teaching.healthtech.dtu.dk/material/unix/Genebankfiles.gb Genebank files] &amp;lt;br&amp;gt;&lt;br /&gt;
Datafile 3: [https://teaching.healthtech.dtu.dk/material/unix/ASCII_chars.dat ASCII character file]&amp;lt;br&amp;gt;&lt;br /&gt;
Datafile 4: [https://teaching.healthtech.dtu.dk/material/unix/Ex1_7bit_binarydata.dat Binary data file]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== grep ===&lt;br /&gt;
The &#039;&#039;&#039;grep&#039;&#039;&#039; command uses regular expressions as search patterns to capture patterns in files and outputs it to stdout. It has the syntax, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;grep&#039;&#039;&#039; [OPTION] &amp;lt;PATTERN&amp;gt; &amp;lt;FILE&amp;gt;&lt;br /&gt;
In &#039;&#039;&#039;figure 5.1&#039;&#039;&#039;, the &#039;&#039;&#039;grep&#039;&#039;&#039; command is used to capture the line containing the authors of a text, which is then redirected to a text file. &lt;br /&gt;
[[File:Grep example.png|none|frame|&#039;&#039;&#039;Figure 5.1 Using the grep command:&#039;&#039;&#039; Here, &#039;&#039;&#039;grep&#039;&#039;&#039; is used capture the line containing the authors of the file and saving it to &amp;lt;AUTHORFILE.txt&amp;gt;.]]&lt;br /&gt;
&lt;br /&gt;
But before you start using this sections commands you should know that Bash (recall that this is the shell that you&#039;re working in) uses basic regex and not extended regex by default. For example, if you wanted to search for occurrences of &#039;AUTHORS&#039; or &#039;authors&#039;&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;grep&#039;&#039;&#039; &#039;AUTHORS|authors&#039; Pseudomonas_Aeruginosa_16S_rRNA.gb &lt;br /&gt;
there would be no results, as Bash doesn&#039;t interpret &#039;|&#039; as a special character. There are 3 solutions to this problem. &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;grep&#039;&#039;&#039; &#039;AUTHORS\|authors&#039; Pseudomonas_Aeruginosa_16S_rRNA.gb &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;egrep&#039;&#039;&#039; &#039;AUTHORS|authors&#039; Pseudomonas_Aeruginosa_16S_rRNA.gb&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;grep -E&#039;&#039;&#039; &#039;AUTHORS|authors&#039; Pseudomonas_Aeruginosa_16S_rRNA.gb&lt;br /&gt;
In the first solution, we use &#039;\&#039; to designate that &#039;|&#039; is to be interpreted as a special character. The second and third solution are similar, as they both use an extended version of &#039;&#039;&#039;grep&#039;&#039;&#039;, so that Bash interprets extended regex. However, only &#039;&#039;&#039;grep&#039;&#039;&#039; has the &#039;&#039;&#039;-E&#039;&#039;&#039; command line argument and an extended version. So for &#039;&#039;&#039;sed&#039;&#039;&#039;, &#039;&#039;&#039;tr&#039;&#039;&#039; and &#039;&#039;&#039;sort&#039;&#039;&#039; you have to use &#039;&#039;&#039;\&#039;&#039;&#039;. Alternatively, in this instance where we&#039;re interested in the occurrence of uppercase and lowercase versions of a string, &#039;&#039;&#039;grep&#039;&#039;&#039; actually has a command line option for this. &lt;br /&gt;
 &#039;&#039;&#039;grep -i&#039;&#039;&#039; &#039;authors&#039; Pseudomonas_Aeruginosa_16S_rRNA.gb &lt;br /&gt;
would capture both &#039;authors&#039; and &#039;AUTHORS&#039;. It also has the improved effect of capturing stuff like &#039;Authors&#039;, &#039;aUTHORS&#039; etc.. &lt;br /&gt;
&lt;br /&gt;
=== sed === &lt;br /&gt;
The command &#039;&#039;&#039;sed&#039;&#039;&#039; stands for &#039;stream editor&#039;, and is typically used to substitute or delete patterns in files.&amp;lt;br&amp;gt; &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sed&#039;&#039;&#039; &#039;s/good/better/&#039; &amp;lt;FILE&amp;gt;&lt;br /&gt;
substitutes the first occurrence of &#039;good&#039; in each line with &#039;better&#039; in &amp;lt;file&amp;gt;. The &#039;s&#039; is &#039;substitute&#039;. You can also instead type, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sed&#039;&#039;&#039; &#039;s/nice/epic/g&#039; &amp;lt;FILE&amp;gt; &lt;br /&gt;
which substitutes all occurrences of &#039;nice with &#039;epic&#039; in each line. The &#039;g&#039; stands for global replacement. &lt;br /&gt;
&lt;br /&gt;
In the above cases, the changes that are made to &amp;lt;FILE&amp;gt; aren&#039;t saved and the stdout is directed to the terminal. This can be done by using the command option &#039;&#039;&#039;i&#039;&#039;&#039; or by using some redirectional operators, as shown in &#039;&#039;&#039;figure 5.2&#039;&#039;&#039;.  &lt;br /&gt;
&lt;br /&gt;
[[File:Sed example.png|frame|left|&#039;&#039;&#039;Figure 5.2 Using the sed command:&#039;&#039;&#039; The &#039;&#039;&#039;sed&#039;&#039;&#039; command is used to substitute occurrences of &#039;good&#039; with &#039;better&#039; and &#039;better&#039; with &#039;the best. The command option, -i, allows you edit the file in place so that changes are saved. Otherwise, the changes are  simply written to the terminal. You might be thinking that you could instead write &#039;&#039;&#039;sed&#039;&#039;&#039; &#039;s/word1/word2/&#039; sed_example.txt &amp;gt; sed_example.txt but it won&#039;t work. The shell interprets redirectional operations prior to commands, so that &#039;&amp;gt; sed_example.txt&#039; will be interpreted first and a new empty sed_example.txt is created. This effectively overwrites the original file and &#039;&#039;&#039;sed&#039;&#039;&#039; ends up processing an empty file. This sort of thing, where empty files are created, actually poses a problem for supercomputer with giant disk systems as it slows the server down. This can happen, when running automated processes with many intermediate files, where one failed subprocess results in an empty file, affecting other sub processes to produce a multitude of empty files. Therefore, it&#039;s good practice to designate intermediate files with file extensions, that make them easy to locate and delete if something goes wrong. The last example is just another way of doing &#039;&#039;&#039;sed -i&#039;&#039;&#039;, which is shown because not all versions of &#039;&#039;&#039;sed&#039;&#039;&#039; have the &#039;&#039;&#039;-i&#039;&#039;&#039; command option (Mac OS doesn&#039;t for example).]]&lt;br /&gt;
&lt;br /&gt;
You don&#039;t have to use &#039;&#039;&#039;/&#039;&#039;&#039; as the separator that separates pattern from substitution. The &#039;&#039;&#039;sed&#039;&#039;&#039; command just uses whatever is followed by &#039;&#039;&#039;s&#039;&#039;&#039; as a separator, and &#039;&#039;&#039;/&#039;&#039;&#039; just happens to be the most commonly used. You could instead write,&lt;br /&gt;
&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sed&#039;&#039;&#039; &#039;s|good|better|g&#039; &amp;lt;FILE&amp;gt;   &lt;br /&gt;
which would work perfectly fine.&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
It is also possible to specify which lines you would like to have replaced in a file.&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sed&#039;&#039;&#039; &#039;&#039;&#039;666&#039;&#039;&#039; &#039;s/nice/epic/g&#039; &amp;lt;FILE&amp;gt;&lt;br /&gt;
substitutes all occurrences of &#039;nice&#039; with &#039;epic&#039; in line 666. &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sed&#039;&#039;&#039; &#039;&#039;&#039;55,$&#039;&#039;&#039; &#039;s/nice/epic/g&#039; &amp;lt;FILE&amp;gt;&lt;br /&gt;
substitutes all occurrences of &#039;nice&#039; with &#039;epic&#039; from line 55 to the last line of &amp;lt;FILE&amp;gt;. The last line of &amp;lt;FILE&amp;gt; is indicated by the symbol, &#039;&#039;&#039;$&#039;&#039;&#039;.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The command &#039;&#039;&#039;sed&#039;&#039;&#039; can be used to delete whole lines. &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sed&#039;&#039;&#039; &#039;2d&#039; &amp;lt;FILE&amp;gt;&lt;br /&gt;
will delete the second line of &amp;lt;FILE&amp;gt;. The &#039;d&#039; stands for delete. &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sed&#039;&#039;&#039; &#039;2,4d&#039; &amp;lt;FILE&amp;gt;&lt;br /&gt;
will delete the second to fourth lines of &amp;lt;FILE&amp;gt;. &lt;br /&gt;
Lastly, you can also search for a pattern and delete lines wherein the pattern occur.&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sed&#039;&#039;&#039; &#039;/nope/d&#039; &amp;lt;FILE&amp;gt; &lt;br /&gt;
will delete any line with the pattern &#039;nope&#039; in it.  &lt;br /&gt;
&lt;br /&gt;
Lastly, it is also possible to do multiple substitutions using the syntax,&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sed&#039;&#039;&#039; &#039;s/good/better/g ; s/nice/epic/g&#039; &amp;lt;FILE&amp;gt;&lt;br /&gt;
which will all instances of good and nice with better and epic.&lt;br /&gt;
&lt;br /&gt;
=== tr ===&lt;br /&gt;
The command &#039;&#039;&#039;tr&#039;&#039;&#039; stands for translate and does exactly this, however, it can only be used to translate one character at a time. It isn&#039;t supported by regex but some of the syntax is similar. &lt;br /&gt;
A common way of using it, is to translate lowercase characters to uppercase characters. &lt;br /&gt;
&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;tr&#039;&#039;&#039; &#039;[a-z]&#039; &#039;[A-Z]&#039; &#039;&#039;&#039;&amp;lt;&#039;&#039;&#039; &amp;lt;FILE&amp;gt;   &lt;br /&gt;
will translate occurrences of lowercase characters to uppercase characters in &amp;lt;FILE&amp;gt;. &lt;br /&gt;
 Prompt$ echo &amp;quot;Tabs for spaces please&amp;quot; | &#039;&#039;&#039;tr&#039;&#039;&#039; &#039;[:space:]&#039; &#039;\t&#039;&lt;br /&gt;
will translate occurrences of spaces to tabs. &lt;br /&gt;
&lt;br /&gt;
[[File:Tr example.png|frame|none|&#039;&#039;&#039;Figure 5.3 Using the tr command:&#039;&#039;&#039; In the first line, the contents of tr_example.txt is displayed using &#039;&#039;&#039;cat&#039;&#039;&#039;, and in the second line, lowercase characters in tr_example.txt are translated to uppercase characters. In the third line spaces are translated to &#039;_&#039;, and in fourth line digits are translated to &#039;*&#039;.]]&lt;br /&gt;
&lt;br /&gt;
=== Sort === &lt;br /&gt;
The &#039;&#039;&#039;sort&#039;&#039;&#039; command is used to sort lines in files, arrange them in a particular order and output to stdout. By default, without any options given, it will sort according to what&#039;s called the ASCII (American Standard Code for Information Interchange) table. In the ASCII table, characters like &#039;a&#039;, &#039;y&#039;, &#039;n&#039;,&#039;4&#039;,&#039;6&#039; have certain values which can be given in binary, octal, decimal and hexadecimal. It is based upon these values that &#039;&#039;&#039;sort&#039;&#039;&#039;, sorts lines in files. Because &#039;&#039;&#039;sort&#039;&#039;&#039; sorts according to values in the ASCII table, it has the following features: &lt;br /&gt;
&lt;br /&gt;
* Lines starting with numbers appear before lines starting with letters&lt;br /&gt;
* Lines starting with letters will appear in alphabetical order&lt;br /&gt;
* Lines starting with uppercase letters appear before lines starting with lowercase letters &lt;br /&gt;
&lt;br /&gt;
This sorting specifications are illustrated in &#039;&#039;&#039;figure 5.4&#039;&#039;&#039;, where the &#039;&#039;&#039;sort&#039;&#039;&#039; command is used on the file, sort1_testfile.txt.&lt;br /&gt;
&lt;br /&gt;
[[File:Sort1 example.png|none|frame|&#039;&#039;&#039;Figure 5.4 Using the sort command:&#039;&#039;&#039; The lines in the sort1_testfile.txt are sorted according to the values in the ASCII table. Characters with lowest value in ASCII table will appear first, for example, as &#039;&#039;&#039;!&#039;&#039;&#039; has the lowest value it appears first]]&lt;br /&gt;
&lt;br /&gt;
You can sort files in reverse ordering by using the &#039;&#039;&#039;r&#039;&#039;&#039; command option. &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sort -r&#039;&#039;&#039; &amp;lt;FILE&amp;gt; &lt;br /&gt;
will sort the file in reverse order and output to stdout. &lt;br /&gt;
&lt;br /&gt;
When dealing with numerical data, you can use the &#039;&#039;&#039;n&#039;&#039;&#039; command option.&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sort -n&#039;&#039;&#039; &amp;lt;FILE&amp;gt;&lt;br /&gt;
will sort the file numerically and output to stdout. This can be combined with the &#039;&#039;&#039;r&#039;&#039;&#039; command option. &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sort -nr&#039;&#039;&#039; &amp;lt;FILE&amp;gt; &lt;br /&gt;
will sort the file numerically in the reverse order and output to stdout.  &lt;br /&gt;
&lt;br /&gt;
You can check whether a file has already been sorted by using the &#039;&#039;&#039;c&#039;&#039;&#039; command option &lt;br /&gt;
[[File:sort2 example.png|frame|none|&#039;&#039;&#039;Figure 5.5 Using the sort command:&#039;&#039;&#039; If a file isn&#039;t sorted, a message will appear that notifies the user of a disorder in the file. If nothing appears then the file is already sorted]]&lt;br /&gt;
&lt;br /&gt;
If you want to sort a file while also removing duplicates you can use the &#039;&#039;&#039;u&#039;&#039;&#039; command option.&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sort -u&#039;&#039;&#039; &amp;lt;FILE&amp;gt;&lt;br /&gt;
will sort the file and remove any duplicates. &lt;br /&gt;
&lt;br /&gt;
Lastly, you can sort lines in a file according to the values of one column with the &#039;&#039;&#039;k&#039;&#039;&#039; command option. For instance, if you wanted to sort according to column 4, &#039;&#039;&#039;sort -k4&#039;&#039;&#039; &amp;lt;FILE&amp;gt; in the command line. In figure 5.6, we show how one can sort numerically and according to a column.&lt;br /&gt;
&lt;br /&gt;
[[File:sort3 example.png|frame|none|&#039;&#039;&#039;Figure 5.6 Using the sort command:&#039;&#039;&#039; Here, sort2_testfile.txt is sorted numerically and according to column 2 by combining command options &#039;&#039;&#039;r&#039;&#039;&#039; and &#039;&#039;&#039;k2&#039;&#039;&#039;.]]&lt;br /&gt;
&lt;br /&gt;
=== ASCII table and numeral systems === &lt;br /&gt;
To understand how &#039;&#039;&#039;sort&#039;&#039;&#039; works, we need to clarify what is meant by binary, octal, decimal, hexadecimal systems and finally how this relates to the ASCII table. &lt;br /&gt;
&lt;br /&gt;
You&#039;re already familiar with decimal systems, as its the system most commonly used for math and anything to do with numbers. As you know, it consists of 10 unique character; 0,1,2,3,4,5,6,7,8, 9. The amount of unique characters in a numeral system is called its base or radix. Here&#039;s a video that gives a quick explanation of base systems, and how a binary system is different from a decimal system.&amp;lt;br&amp;gt; &lt;br /&gt;
[https://www.youtube.com/watch?v=LpuPe81bc2w Base systems and binary]&amp;lt;br&amp;gt; &lt;br /&gt;
When a number exceeds what you can write with these 10 characters, you simply add another slot. For instance with the number, 16, you&#039;ve added the &#039;1&#039; to the second slot and the second slot represent 10&#039;s. The reason why the decimal system is so widely used today is most likely because we humans tend to use our fingers to count, and since we have 10 fingers, the decimal system was the most logical choice.&lt;br /&gt;
&lt;br /&gt;
Binary (2), octal (8) and hexadecimal (16) base systems, are simply systems that have different bases. The binary value system consists of 2 characters, 0 and 1, and this is the system that all computers use. In computing, the 0 often corresponds to a unit being turned off, and 1 corresponds to a unit being turned on. Because the binary system only consists of 2 characters, you have to change slots more often than you would in the decimal system. In the binary system, these slots are in fact what&#039;s called &#039;&#039;bits&#039;&#039;, something you might have heard about but not actually known what meant. The number of bits can vary, for instance, you might&#039;ve heard about operating systems being 32 bit or 64 bit.  &lt;br /&gt;
&lt;br /&gt;
Let&#039;s learn by example by translating decimal values to binary values. The ASCII table uses 7 bits, which we&#039;ll use as well. The values of each bit in a binary system is; 64(7), 32(6), 16(5), 8(4), 4(3), 2(2), 1(1) . To clarify, these bit values are what would correspond to the slot values; 100.0000(7), 100.000(6), 10.000(5), 1000(4), 100(3), 10(2), 1(1) in the decimal value system.&amp;lt;br&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
In the table underneath there are 4 examples ASCII characters with corresponding decimal and binary combination. When summed, every binary combination results in a unique decimal value. &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Binary value (7 bits): 64 32 16 8 4 2 1 &lt;br /&gt;
!Decimal value&lt;br /&gt;
!Character in ASCII table&lt;br /&gt;
|-&lt;br /&gt;
|0 0 1 0 1 0 1&lt;br /&gt;
|0+0+16+0+4+0+1=21&lt;br /&gt;
|!&lt;br /&gt;
|-&lt;br /&gt;
|1 0 0 0 0 0 1&lt;br /&gt;
|64+0+0+0+0+0+1=65&lt;br /&gt;
|A&lt;br /&gt;
|-&lt;br /&gt;
|0 1 1 0 1 1 0&lt;br /&gt;
|0+32+16+0+4+2+0=54&lt;br /&gt;
|6  &lt;br /&gt;
|-&lt;br /&gt;
|1 1 1 1 1 1 1&lt;br /&gt;
|64+32+16+8+4+2+1=127&lt;br /&gt;
|Del  &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The ASCII table has 127 characters, a limit that is set by it having 7 bits which amounts to 127 combinations. It includes the characters A-Z, a-z, 0-9 and other characters which you can see by using the &#039;&#039;&#039;man&#039;&#039;&#039; command, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;man&#039;&#039;&#039; ascii&lt;br /&gt;
This will show you a table of all 127 characters, the binary values however, are not shown. Instead only the octal, decimal and hexadecimal values are shown. &lt;br /&gt;
&lt;br /&gt;
The octal system consists of 8 unique characters; 0,1,2,3,4,5,6,7. Therefore, a value exceeding this, for instance 8 in decimal value, would be translated to 010 in the octal system. The octal system is used in computer software to simplify binary input, but interestingly, it has also been used by the indigenous american yuki people who used the space between their fingers to count.&lt;br /&gt;
&lt;br /&gt;
The hexadecimal system consists of 16 unique characters; 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F. As the hexadecimal system uses 6 more unique characters than the decimal system, then changing slots happens less frequently. For instance, a decimal value of 12 would translate to 0B in the hexadecimal system.&lt;br /&gt;
&lt;br /&gt;
The ASCII table only covers 127 characters but there exists a lot more characters than this, therefore, another system with more bits called &#039;&#039;Unicode&#039;&#039; is often used. If you&#039;re interested, here&#039;s a five minute introductory video explaining ASCII and Unicode [https://www.youtube.com/watch?v=5aJKKgSEUnY Introductory video on ASCII and Unicode].&lt;br /&gt;
&lt;br /&gt;
== Exercise 1: Extracting and sorting data from a Gene Bank files == &lt;br /&gt;
You&#039;ve been given the task to extract and sort data from some genebank files, [http://teaching.healthtech.dtu.dk/material/unix/Genebankfiles.gb Genebank files]. More specifically, you need to extract the authors, accession number and the name of the organism and save in 3 different files.     &lt;br /&gt;
&lt;br /&gt;
1. Extract the lines with authors from Genebankfiles.gb, sort it and save the output to one file.&amp;lt;br&amp;gt;&lt;br /&gt;
2. Extract the lines with accession numbers from Genebankfiles.gb, sort it and save the output to a second file.&amp;lt;br&amp;gt;&lt;br /&gt;
3. Extract the lines with organisms from Genebankfiles.gb, sort it, and save the output to a third file.&amp;lt;br&amp;gt;&lt;br /&gt;
4. As you don&#039;t know when you&#039;re going to need to do this again, you want to write a shell script that does the functions of questions 1-3. Make a simple shell script that appends authors, accession numbers and organisms to the files you made in questions 1-3.      &lt;br /&gt;
&lt;br /&gt;
== Exercise 2: Translating ASCII characters to binary and decimal values ==&lt;br /&gt;
In this exercise, you&#039;ll be working with [http://teaching.healthtech.dtu.dk/material/unix/ASCII_chars.dat ASCII character file]&amp;lt;br&amp;gt;, which contains ASCII characters, and [http://teaching.healthtech.dtu.dk/material/unix/Binary.dat Binary data file] which contains corresponding binary data. The ASCII characters --&amp;gt; corresponding decimal values are listed hereunder:&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;{&#039;&#039;&#039; --&amp;gt; &#039;&#039;&#039;125&#039;&#039;&#039;&amp;lt;br&amp;gt; &#039;&#039;&#039;a&#039;&#039;&#039; --&amp;gt; &#039;&#039;&#039;97&#039;&#039;&#039;&amp;lt;br&amp;gt; &#039;&#039;&#039;p&#039;&#039;&#039; --&amp;gt; &#039;&#039;&#039;112&#039;&#039;&#039;&amp;lt;br&amp;gt; &#039;&#039;&#039;X&#039;&#039;&#039;--&amp;gt; &#039;&#039;&#039;88&#039;&#039;&#039;&amp;lt;br&amp;gt;&#039;&#039;&#039;+&#039;&#039;&#039; --&amp;gt; &#039;&#039;&#039;43&#039;&#039;&#039;&amp;lt;br&amp;gt;&#039;&#039;&#039;/&#039;&#039;&#039; --&amp;gt; &#039;&#039;&#039;47&#039;&#039;&#039;&amp;lt;br&amp;gt; &#039;&#039;&#039;$&#039;&#039;&#039; --&amp;gt; &#039;&#039;&#039;36&#039;&#039;&#039;&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
1. Translate all the ASCII characters to decimal values and save the output to Decimals.dat (See &#039;&#039;&#039;Hint 1&#039;&#039;&#039;).&amp;lt;br&amp;gt;&lt;br /&gt;
2. Merge ASCII_chars.dat, Binary.dat and Decimals.dat so that column 1; ASCII chars, column 2; Binary data and column 3; Decimal values. Save the output to Merge.dat and then delete Decimals.dat. &amp;lt;br&amp;gt;&lt;br /&gt;
3. Sort Merge.dat based on the decimal values.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Hint 1:&#039;&#039;&#039; This is tedious problem, as there are a lot of ASCII characters that need to be translated. The best way to do this with your current skill level is to use &#039;&#039;&#039;sed&#039;&#039;&#039; &#039;s/blah1/blah2/g ; s/blah3/blah4/g ; ... s/blah98/blah99/g&#039; &#039;&#039;&#039;&amp;gt;&#039;&#039;&#039; Decimals.dat). Also, remember to use &#039;&#039;&#039;\&#039;&#039;&#039; for special characters like &#039;&#039;&#039;$&#039;&#039;&#039;.&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/unix/index.php?title=Filtering_and_regular_expressions&amp;diff=36</id>
		<title>Filtering and regular expressions</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/unix/index.php?title=Filtering_and_regular_expressions&amp;diff=36"/>
		<updated>2024-03-20T12:07:51Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: Created page with &amp;quot;__NOTOC__ You can think of regular expressions (regex for short) as a pattern language that can be used to match patterns and filter data. In this section, we&amp;#039;ll be learning so-called &amp;#039;&amp;#039;filter commands&amp;#039;&amp;#039;, some of which utilize regular expressions in order to find and replace patterns. It is therefore important to have a basic understanding of regular expressions. To get you started, follow this link to an introductory video, [https://www.youtube.com/watch?v=KJG1dETacLI B...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
You can think of regular expressions (regex for short) as a pattern language that can be used to match patterns and filter data. In this section, we&#039;ll be learning so-called &#039;&#039;filter commands&#039;&#039;, some of which utilize regular expressions in order to find and replace patterns. It is therefore important to have a basic understanding of regular expressions. To get you started, follow this link to an introductory video, [https://www.youtube.com/watch?v=KJG1dETacLI Basic Regular Expression Introduction Video], which gives a basic understanding of the concepts of regular expressions. &lt;br /&gt;
&lt;br /&gt;
Next, you can follow this link [https://regexone.com/lesson/introduction_abcs Regex Introduction Exercises], where there&#039;s some exercises on basic regex. The &#039;Practice problems&#039; are a bit more complex, but should still be doable. They are, however, optional.  &lt;br /&gt;
&lt;br /&gt;
[https://www.cheatography.com/davechild/cheat-sheets/regular-expressions/pdf/ Regex cheat sheet]&lt;br /&gt;
&lt;br /&gt;
== Introduction to commands ==  &lt;br /&gt;
Now that you&#039;ve been initiated in regular expressions, we&#039;ll take a look at some Unix commands that can use regular expressions. Underneath we list commands and syntax for the commands that we&#039;ll be using in this section. &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Unix Command&lt;br /&gt;
!Acronym translation &lt;br /&gt;
!Description&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;grep&#039;&#039;&#039; [PATTERN] &amp;lt;FILE&amp;gt;&lt;br /&gt;
|Global regular expression print. &lt;br /&gt;
|Uses regular expressions select lines in a file that matches the pattern. &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;sed&#039;&#039;&#039; [OPTION] &amp;lt;SCRIPT&amp;gt; &amp;lt;FILE&amp;gt;&lt;br /&gt;
|stream editor&lt;br /&gt;
|Allows user to edit files without actually opening the files using regular expressions.&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;tr&#039;&#039;&#039; [OPTION] &amp;lt;SET1&amp;gt; &amp;lt;SET2&amp;gt;&lt;br /&gt;
|Translate&lt;br /&gt;
|Translates characters from the standard input and writes to the standard output.  &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;sort&#039;&#039;&#039; [OPTION] &amp;lt;FILE&amp;gt;&lt;br /&gt;
|&amp;lt;nowiki&amp;gt;-&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|Sorts the content of a file.  &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Datafile 1: [http://teaching.healthtech.dtu.dk/material/unix/Pseudomonas_Aeruginosa_16SrRNA.gb Pseudomonas Aeruginosa 16S rRNA Genebank file]&amp;lt;br&amp;gt; &lt;br /&gt;
Datafile 2: [http://teaching.healthtech.dtu.dk/material/unix/Genebankfiles.gb Genebank files] &amp;lt;br&amp;gt;&lt;br /&gt;
Datafile 3: [http://teaching.healthtech.dtu.dk/material/unix/ASCII_chars.dat ASCII character file]&amp;lt;br&amp;gt;&lt;br /&gt;
Datafile 4: [http://teaching.healthtech.dtu.dk/material/unix/Ex1_7bit_binarydata.dat Binary data file]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== grep ===&lt;br /&gt;
The &#039;&#039;&#039;grep&#039;&#039;&#039; command uses regular expressions as search patterns to capture patterns in files and outputs it to stdout. It has the syntax, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;grep&#039;&#039;&#039; [OPTION] &amp;lt;PATTERN&amp;gt; &amp;lt;FILE&amp;gt;&lt;br /&gt;
In &#039;&#039;&#039;figure 5.1&#039;&#039;&#039;, the &#039;&#039;&#039;grep&#039;&#039;&#039; command is used to capture the line containing the authors of a text, which is then redirected to a text file. &lt;br /&gt;
[[File:Grep example.png|none|frame|&#039;&#039;&#039;Figure 5.1 Using the grep command:&#039;&#039;&#039; Here, &#039;&#039;&#039;grep&#039;&#039;&#039; is used capture the line containing the authors of the file and saving it to &amp;lt;AUTHORFILE.txt&amp;gt;.]]&lt;br /&gt;
&lt;br /&gt;
But before you start using this sections commands you should know that Bash (recall that this is the shell that you&#039;re working in) uses basic regex and not extended regex by default. For example, if you wanted to search for occurrences of &#039;AUTHORS&#039; or &#039;authors&#039;&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;grep&#039;&#039;&#039; &#039;AUTHORS|authors&#039; Pseudomonas_Aeruginosa_16S_rRNA.gb &lt;br /&gt;
there would be no results, as Bash doesn&#039;t interpret &#039;|&#039; as a special character. There are 3 solutions to this problem. &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;grep&#039;&#039;&#039; &#039;AUTHORS\|authors&#039; Pseudomonas_Aeruginosa_16S_rRNA.gb &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;egrep&#039;&#039;&#039; &#039;AUTHORS|authors&#039; Pseudomonas_Aeruginosa_16S_rRNA.gb&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;grep -E&#039;&#039;&#039; &#039;AUTHORS|authors&#039; Pseudomonas_Aeruginosa_16S_rRNA.gb&lt;br /&gt;
In the first solution, we use &#039;\&#039; to designate that &#039;|&#039; is to be interpreted as a special character. The second and third solution are similar, as they both use an extended version of &#039;&#039;&#039;grep&#039;&#039;&#039;, so that Bash interprets extended regex. However, only &#039;&#039;&#039;grep&#039;&#039;&#039; has the &#039;&#039;&#039;-E&#039;&#039;&#039; command line argument and an extended version. So for &#039;&#039;&#039;sed&#039;&#039;&#039;, &#039;&#039;&#039;tr&#039;&#039;&#039; and &#039;&#039;&#039;sort&#039;&#039;&#039; you have to use &#039;&#039;&#039;\&#039;&#039;&#039;. Alternatively, in this instance where we&#039;re interested in the occurrence of uppercase and lowercase versions of a string, &#039;&#039;&#039;grep&#039;&#039;&#039; actually has a command line option for this. &lt;br /&gt;
 &#039;&#039;&#039;grep -i&#039;&#039;&#039; &#039;authors&#039; Pseudomonas_Aeruginosa_16S_rRNA.gb &lt;br /&gt;
would capture both &#039;authors&#039; and &#039;AUTHORS&#039;. It also has the improved effect of capturing stuff like &#039;Authors&#039;, &#039;aUTHORS&#039; etc.. &lt;br /&gt;
&lt;br /&gt;
=== sed === &lt;br /&gt;
The command &#039;&#039;&#039;sed&#039;&#039;&#039; stands for &#039;stream editor&#039;, and is typically used to substitute or delete patterns in files.&amp;lt;br&amp;gt; &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sed&#039;&#039;&#039; &#039;s/good/better/&#039; &amp;lt;FILE&amp;gt;&lt;br /&gt;
substitutes the first occurrence of &#039;good&#039; in each line with &#039;better&#039; in &amp;lt;file&amp;gt;. The &#039;s&#039; is &#039;substitute&#039;. You can also instead type, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sed&#039;&#039;&#039; &#039;s/nice/epic/g&#039; &amp;lt;FILE&amp;gt; &lt;br /&gt;
which substitutes all occurrences of &#039;nice with &#039;epic&#039; in each line. The &#039;g&#039; stands for global replacement. &lt;br /&gt;
&lt;br /&gt;
In the above cases, the changes that are made to &amp;lt;FILE&amp;gt; aren&#039;t saved and the stdout is directed to the terminal. This can be done by using the command option &#039;&#039;&#039;i&#039;&#039;&#039; or by using some redirectional operators, as shown in &#039;&#039;&#039;figure 5.2&#039;&#039;&#039;.  &lt;br /&gt;
&lt;br /&gt;
[[File:Sed example.png|frame|left|&#039;&#039;&#039;Figure 5.2 Using the sed command:&#039;&#039;&#039; The &#039;&#039;&#039;sed&#039;&#039;&#039; command is used to substitute occurrences of &#039;good&#039; with &#039;better&#039; and &#039;better&#039; with &#039;the best. The command option, -i, allows you edit the file in place so that changes are saved. Otherwise, the changes are  simply written to the terminal. You might be thinking that you could instead write &#039;&#039;&#039;sed&#039;&#039;&#039; &#039;s/word1/word2/&#039; sed_example.txt &amp;gt; sed_example.txt but it won&#039;t work. The shell interprets redirectional operations prior to commands, so that &#039;&amp;gt; sed_example.txt&#039; will be interpreted first and a new empty sed_example.txt is created. This effectively overwrites the original file and &#039;&#039;&#039;sed&#039;&#039;&#039; ends up processing an empty file. This sort of thing, where empty files are created, actually poses a problem for supercomputer with giant disk systems as it slows the server down. This can happen, when running automated processes with many intermediate files, where one failed subprocess results in an empty file, affecting other sub processes to produce a multitude of empty files. Therefore, it&#039;s good practice to designate intermediate files with file extensions, that make them easy to locate and delete if something goes wrong. The last example is just another way of doing &#039;&#039;&#039;sed -i&#039;&#039;&#039;, which is shown because not all versions of &#039;&#039;&#039;sed&#039;&#039;&#039; have the &#039;&#039;&#039;-i&#039;&#039;&#039; command option (Mac OS doesn&#039;t for example).]]&lt;br /&gt;
&lt;br /&gt;
You don&#039;t have to use &#039;&#039;&#039;/&#039;&#039;&#039; as the separator that separates pattern from substitution. The &#039;&#039;&#039;sed&#039;&#039;&#039; command just uses whatever is followed by &#039;&#039;&#039;s&#039;&#039;&#039; as a separator, and &#039;&#039;&#039;/&#039;&#039;&#039; just happens to be the most commonly used. You could instead write,&lt;br /&gt;
&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sed&#039;&#039;&#039; &#039;s|good|better|g&#039; &amp;lt;FILE&amp;gt;   &lt;br /&gt;
which would work perfectly fine.&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
It is also possible to specify which lines you would like to have replaced in a file.&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sed&#039;&#039;&#039; &#039;&#039;&#039;666&#039;&#039;&#039; &#039;s/nice/epic/g&#039; &amp;lt;FILE&amp;gt;&lt;br /&gt;
substitutes all occurrences of &#039;nice&#039; with &#039;epic&#039; in line 666. &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sed&#039;&#039;&#039; &#039;&#039;&#039;55,$&#039;&#039;&#039; &#039;s/nice/epic/g&#039; &amp;lt;FILE&amp;gt;&lt;br /&gt;
substitutes all occurrences of &#039;nice&#039; with &#039;epic&#039; from line 55 to the last line of &amp;lt;FILE&amp;gt;. The last line of &amp;lt;FILE&amp;gt; is indicated by the symbol, &#039;&#039;&#039;$&#039;&#039;&#039;.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The command &#039;&#039;&#039;sed&#039;&#039;&#039; can be used to delete whole lines. &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sed&#039;&#039;&#039; &#039;2d&#039; &amp;lt;FILE&amp;gt;&lt;br /&gt;
will delete the second line of &amp;lt;FILE&amp;gt;. The &#039;d&#039; stands for delete. &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sed&#039;&#039;&#039; &#039;2,4d&#039; &amp;lt;FILE&amp;gt;&lt;br /&gt;
will delete the second to fourth lines of &amp;lt;FILE&amp;gt;. &lt;br /&gt;
Lastly, you can also search for a pattern and delete lines wherein the pattern occur.&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sed&#039;&#039;&#039; &#039;/nope/d&#039; &amp;lt;FILE&amp;gt; &lt;br /&gt;
will delete any line with the pattern &#039;nope&#039; in it.  &lt;br /&gt;
&lt;br /&gt;
Lastly, it is also possible to do multiple substitutions using the syntax,&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sed&#039;&#039;&#039; &#039;s/good/better/g ; s/nice/epic/g&#039; &amp;lt;FILE&amp;gt;&lt;br /&gt;
which will all instances of good and nice with better and epic.&lt;br /&gt;
&lt;br /&gt;
=== tr ===&lt;br /&gt;
The command &#039;&#039;&#039;tr&#039;&#039;&#039; stands for translate and does exactly this, however, it can only be used to translate one character at a time. It isn&#039;t supported by regex but some of the syntax is similar. &lt;br /&gt;
A common way of using it, is to translate lowercase characters to uppercase characters. &lt;br /&gt;
&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;tr&#039;&#039;&#039; &#039;[a-z]&#039; &#039;[A-Z]&#039; &#039;&#039;&#039;&amp;lt;&#039;&#039;&#039; &amp;lt;FILE&amp;gt;   &lt;br /&gt;
will translate occurrences of lowercase characters to uppercase characters in &amp;lt;FILE&amp;gt;. &lt;br /&gt;
 Prompt$ echo &amp;quot;Tabs for spaces please&amp;quot; | &#039;&#039;&#039;tr&#039;&#039;&#039; &#039;[:space:]&#039; &#039;\t&#039;&lt;br /&gt;
will translate occurrences of spaces to tabs. &lt;br /&gt;
&lt;br /&gt;
[[File:Tr example.png|frame|none|&#039;&#039;&#039;Figure 5.3 Using the tr command:&#039;&#039;&#039; In the first line, the contents of tr_example.txt is displayed using &#039;&#039;&#039;cat&#039;&#039;&#039;, and in the second line, lowercase characters in tr_example.txt are translated to uppercase characters. In the third line spaces are translated to &#039;_&#039;, and in fourth line digits are translated to &#039;*&#039;.]]&lt;br /&gt;
&lt;br /&gt;
=== Sort === &lt;br /&gt;
The &#039;&#039;&#039;sort&#039;&#039;&#039; command is used to sort lines in files, arrange them in a particular order and output to stdout. By default, without any options given, it will sort according to what&#039;s called the ASCII (American Standard Code for Information Interchange) table. In the ASCII table, characters like &#039;a&#039;, &#039;y&#039;, &#039;n&#039;,&#039;4&#039;,&#039;6&#039; have certain values which can be given in binary, octal, decimal and hexadecimal. It is based upon these values that &#039;&#039;&#039;sort&#039;&#039;&#039;, sorts lines in files. Because &#039;&#039;&#039;sort&#039;&#039;&#039; sorts according to values in the ASCII table, it has the following features: &lt;br /&gt;
&lt;br /&gt;
* Lines starting with numbers appear before lines starting with letters&lt;br /&gt;
* Lines starting with letters will appear in alphabetical order&lt;br /&gt;
* Lines starting with uppercase letters appear before lines starting with lowercase letters &lt;br /&gt;
&lt;br /&gt;
This sorting specifications are illustrated in &#039;&#039;&#039;figure 5.4&#039;&#039;&#039;, where the &#039;&#039;&#039;sort&#039;&#039;&#039; command is used on the file, sort1_testfile.txt.&lt;br /&gt;
&lt;br /&gt;
[[File:Sort1 example.png|none|frame|&#039;&#039;&#039;Figure 5.4 Using the sort command:&#039;&#039;&#039; The lines in the sort1_testfile.txt are sorted according to the values in the ASCII table. Characters with lowest value in ASCII table will appear first, for example, as &#039;&#039;&#039;!&#039;&#039;&#039; has the lowest value it appears first]]&lt;br /&gt;
&lt;br /&gt;
You can sort files in reverse ordering by using the &#039;&#039;&#039;r&#039;&#039;&#039; command option. &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sort -r&#039;&#039;&#039; &amp;lt;FILE&amp;gt; &lt;br /&gt;
will sort the file in reverse order and output to stdout. &lt;br /&gt;
&lt;br /&gt;
When dealing with numerical data, you can use the &#039;&#039;&#039;n&#039;&#039;&#039; command option.&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sort -n&#039;&#039;&#039; &amp;lt;FILE&amp;gt;&lt;br /&gt;
will sort the file numerically and output to stdout. This can be combined with the &#039;&#039;&#039;r&#039;&#039;&#039; command option. &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sort -nr&#039;&#039;&#039; &amp;lt;FILE&amp;gt; &lt;br /&gt;
will sort the file numerically in the reverse order and output to stdout.  &lt;br /&gt;
&lt;br /&gt;
You can check whether a file has already been sorted by using the &#039;&#039;&#039;c&#039;&#039;&#039; command option &lt;br /&gt;
[[File:sort2 example.png|frame|none|&#039;&#039;&#039;Figure 5.5 Using the sort command:&#039;&#039;&#039; If a file isn&#039;t sorted, a message will appear that notifies the user of a disorder in the file. If nothing appears then the file is already sorted]]&lt;br /&gt;
&lt;br /&gt;
If you want to sort a file while also removing duplicates you can use the &#039;&#039;&#039;u&#039;&#039;&#039; command option.&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sort -u&#039;&#039;&#039; &amp;lt;FILE&amp;gt;&lt;br /&gt;
will sort the file and remove any duplicates. &lt;br /&gt;
&lt;br /&gt;
Lastly, you can sort lines in a file according to the values of one column with the &#039;&#039;&#039;k&#039;&#039;&#039; command option. For instance, if you wanted to sort according to column 4, &#039;&#039;&#039;sort -k4&#039;&#039;&#039; &amp;lt;FILE&amp;gt; in the command line. In figure 5.6, we show how one can sort numerically and according to a column.&lt;br /&gt;
&lt;br /&gt;
[[File:sort3 example.png|frame|none|&#039;&#039;&#039;Figure 5.6 Using the sort command:&#039;&#039;&#039; Here, sort2_testfile.txt is sorted numerically and according to column 2 by combining command options &#039;&#039;&#039;r&#039;&#039;&#039; and &#039;&#039;&#039;k2&#039;&#039;&#039;.]]&lt;br /&gt;
&lt;br /&gt;
=== ASCII table and numeral systems === &lt;br /&gt;
To understand how &#039;&#039;&#039;sort&#039;&#039;&#039; works, we need to clarify what is meant by binary, octal, decimal, hexadecimal systems and finally how this relates to the ASCII table. &lt;br /&gt;
&lt;br /&gt;
You&#039;re already familiar with decimal systems, as its the system most commonly used for math and anything to do with numbers. As you know, it consists of 10 unique character; 0,1,2,3,4,5,6,7,8, 9. The amount of unique characters in a numeral system is called its base or radix. Here&#039;s a video that gives a quick explanation of base systems, and how a binary system is different from a decimal system.&amp;lt;br&amp;gt; &lt;br /&gt;
[https://www.youtube.com/watch?v=LpuPe81bc2w Base systems and binary]&amp;lt;br&amp;gt; &lt;br /&gt;
When a number exceeds what you can write with these 10 characters, you simply add another slot. For instance with the number, 16, you&#039;ve added the &#039;1&#039; to the second slot and the second slot represent 10&#039;s. The reason why the decimal system is so widely used today is most likely because we humans tend to use our fingers to count, and since we have 10 fingers, the decimal system was the most logical choice.&lt;br /&gt;
&lt;br /&gt;
Binary (2), octal (8) and hexadecimal (16) base systems, are simply systems that have different bases. The binary value system consists of 2 characters, 0 and 1, and this is the system that all computers use. In computing, the 0 often corresponds to a unit being turned off, and 1 corresponds to a unit being turned on. Because the binary system only consists of 2 characters, you have to change slots more often than you would in the decimal system. In the binary system, these slots are in fact what&#039;s called &#039;&#039;bits&#039;&#039;, something you might have heard about but not actually known what meant. The number of bits can vary, for instance, you might&#039;ve heard about operating systems being 32 bit or 64 bit.  &lt;br /&gt;
&lt;br /&gt;
Let&#039;s learn by example by translating decimal values to binary values. The ASCII table uses 7 bits, which we&#039;ll use as well. The values of each bit in a binary system is; 64(7), 32(6), 16(5), 8(4), 4(3), 2(2), 1(1) . To clarify, these bit values are what would correspond to the slot values; 100.0000(7), 100.000(6), 10.000(5), 1000(4), 100(3), 10(2), 1(1) in the decimal value system.&amp;lt;br&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
In the table underneath there are 4 examples ASCII characters with corresponding decimal and binary combination. When summed, every binary combination results in a unique decimal value. &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Binary value (7 bits): 64 32 16 8 4 2 1 &lt;br /&gt;
!Decimal value&lt;br /&gt;
!Character in ASCII table&lt;br /&gt;
|-&lt;br /&gt;
|0 0 1 0 1 0 1&lt;br /&gt;
|0+0+16+0+4+0+1=21&lt;br /&gt;
|!&lt;br /&gt;
|-&lt;br /&gt;
|1 0 0 0 0 0 1&lt;br /&gt;
|64+0+0+0+0+0+1=65&lt;br /&gt;
|A&lt;br /&gt;
|-&lt;br /&gt;
|0 1 1 0 1 1 0&lt;br /&gt;
|0+32+16+0+4+2+0=54&lt;br /&gt;
|6  &lt;br /&gt;
|-&lt;br /&gt;
|1 1 1 1 1 1 1&lt;br /&gt;
|64+32+16+8+4+2+1=127&lt;br /&gt;
|Del  &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The ASCII table has 127 characters, a limit that is set by it having 7 bits which amounts to 127 combinations. It includes the characters A-Z, a-z, 0-9 and other characters which you can see by using the &#039;&#039;&#039;man&#039;&#039;&#039; command, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;man&#039;&#039;&#039; ascii&lt;br /&gt;
This will show you a table of all 127 characters, the binary values however, are not shown. Instead only the octal, decimal and hexadecimal values are shown. &lt;br /&gt;
&lt;br /&gt;
The octal system consists of 8 unique characters; 0,1,2,3,4,5,6,7. Therefore, a value exceeding this, for instance 8 in decimal value, would be translated to 010 in the octal system. The octal system is used in computer software to simplify binary input, but interestingly, it has also been used by the indigenous american yuki people who used the space between their fingers to count.&lt;br /&gt;
&lt;br /&gt;
The hexadecimal system consists of 16 unique characters; 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F. As the hexadecimal system uses 6 more unique characters than the decimal system, then changing slots happens less frequently. For instance, a decimal value of 12 would translate to 0B in the hexadecimal system.&lt;br /&gt;
&lt;br /&gt;
The ASCII table only covers 127 characters but there exists a lot more characters than this, therefore, another system with more bits called &#039;&#039;Unicode&#039;&#039; is often used. If you&#039;re interested, here&#039;s a five minute introductory video explaining ASCII and Unicode [https://www.youtube.com/watch?v=5aJKKgSEUnY Introductory video on ASCII and Unicode].  &lt;br /&gt;
&lt;br /&gt;
== Exercise 1: Extracting and sorting data from a Gene Bank files == &lt;br /&gt;
You&#039;ve been given the task to extract and sort data from some genebank files, [http://teaching.healthtech.dtu.dk/material/unix/Genebankfiles.gb Genebank files]. More specifically, you need to extract the authors, accession number and the name of the organism and save in 3 different files.     &lt;br /&gt;
&lt;br /&gt;
1. Extract the lines with authors from Genebankfiles.gb, sort it and save the output to one file.&amp;lt;br&amp;gt;&lt;br /&gt;
2. Extract the lines with accession numbers from Genebankfiles.gb, sort it and save the output to a second file.&amp;lt;br&amp;gt;&lt;br /&gt;
3. Extract the lines with organisms from Genebankfiles.gb, sort it, and save the output to a third file.&amp;lt;br&amp;gt;&lt;br /&gt;
4. As you don&#039;t know when you&#039;re going to need to do this again, you want to write a shell script that does the functions of questions 1-3. Make a simple shell script that appends authors, accession numbers and organisms to the files you made in questions 1-3.      &lt;br /&gt;
&lt;br /&gt;
== Exercise 2: Translating ASCII characters to binary and decimal values ==&lt;br /&gt;
In this exercise, you&#039;ll be working with [http://teaching.healthtech.dtu.dk/material/unix/ASCII_chars.dat ASCII character file]&amp;lt;br&amp;gt;, which contains ASCII characters, and [http://teaching.healthtech.dtu.dk/material/unix/Binary.dat Binary data file] which contains corresponding binary data. The ASCII characters --&amp;gt; corresponding decimal values are listed hereunder:&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;{&#039;&#039;&#039; --&amp;gt; &#039;&#039;&#039;125&#039;&#039;&#039;&amp;lt;br&amp;gt; &#039;&#039;&#039;a&#039;&#039;&#039; --&amp;gt; &#039;&#039;&#039;97&#039;&#039;&#039;&amp;lt;br&amp;gt; &#039;&#039;&#039;p&#039;&#039;&#039; --&amp;gt; &#039;&#039;&#039;112&#039;&#039;&#039;&amp;lt;br&amp;gt; &#039;&#039;&#039;X&#039;&#039;&#039;--&amp;gt; &#039;&#039;&#039;88&#039;&#039;&#039;&amp;lt;br&amp;gt;&#039;&#039;&#039;+&#039;&#039;&#039; --&amp;gt; &#039;&#039;&#039;43&#039;&#039;&#039;&amp;lt;br&amp;gt;&#039;&#039;&#039;/&#039;&#039;&#039; --&amp;gt; &#039;&#039;&#039;47&#039;&#039;&#039;&amp;lt;br&amp;gt; &#039;&#039;&#039;$&#039;&#039;&#039; --&amp;gt; &#039;&#039;&#039;36&#039;&#039;&#039;&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
1. Translate all the ASCII characters to decimal values and save the output to Decimals.dat (See &#039;&#039;&#039;Hint 1&#039;&#039;&#039;).&amp;lt;br&amp;gt;&lt;br /&gt;
2. Merge ASCII_chars.dat, Binary.dat and Decimals.dat so that column 1; ASCII chars, column 2; Binary data and column 3; Decimal values. Save the output to Merge.dat and then delete Decimals.dat. &amp;lt;br&amp;gt;&lt;br /&gt;
3. Sort Merge.dat based on the decimal values.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Hint 1:&#039;&#039;&#039; This is tedious problem, as there are a lot of ASCII characters that need to be translated. The best way to do this with your current skill level is to use &#039;&#039;&#039;sed&#039;&#039;&#039; &#039;s/blah1/blah2/g ; s/blah3/blah4/g ; ... s/blah98/blah99/g&#039; &#039;&#039;&#039;&amp;gt;&#039;&#039;&#039; Decimals.dat). Also, remember to use &#039;&#039;&#039;\&#039;&#039;&#039; for special characters like &#039;&#039;&#039;$&#039;&#039;&#039;.&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/unix/index.php?title=File:Read_ShellScript.png&amp;diff=35</id>
		<title>File:Read ShellScript.png</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/unix/index.php?title=File:Read_ShellScript.png&amp;diff=35"/>
		<updated>2024-03-20T12:07:08Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/unix/index.php?title=File:UserArguments.png&amp;diff=34</id>
		<title>File:UserArguments.png</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/unix/index.php?title=File:UserArguments.png&amp;diff=34"/>
		<updated>2024-03-20T12:06:47Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/unix/index.php?title=File:Variables_ShellScripts.png&amp;diff=33</id>
		<title>File:Variables ShellScripts.png</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/unix/index.php?title=File:Variables_ShellScripts.png&amp;diff=33"/>
		<updated>2024-03-20T12:06:27Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/unix/index.php?title=File:Shebangs1.png&amp;diff=32</id>
		<title>File:Shebangs1.png</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/unix/index.php?title=File:Shebangs1.png&amp;diff=32"/>
		<updated>2024-03-20T12:06:02Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/unix/index.php?title=Setting_up_your_shell_script&amp;diff=31</id>
		<title>Setting up your shell script</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/unix/index.php?title=Setting_up_your_shell_script&amp;diff=31"/>
		<updated>2024-03-20T12:05:18Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: Created page with &amp;quot;__NOTOC__ Last section we did some simple shell scripting. These shell scripts contained multiple commands and the script could be executed with &amp;#039;&amp;#039;&amp;#039;bash&amp;#039;&amp;#039;&amp;#039;. In this section, we go through some of the basics of shell scripts. Before getting started, however, you should know that when writing shell scripts in text editors, it&amp;#039;s important that it supports bash. For example, running Sublime on the Windows OS will cause errors. If you&amp;#039;re using Vim editor, you should have no p...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
Last section we did some simple shell scripting. These shell scripts contained multiple commands and the script could be executed with &#039;&#039;&#039;bash&#039;&#039;&#039;. In this section, we go through some of the basics of shell scripts. Before getting started, however, you should know that when writing shell scripts in text editors, it&#039;s important that it supports bash. For example, running Sublime on the Windows OS will cause errors. If you&#039;re using Vim editor, you should have no problems.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Unix Command&lt;br /&gt;
!Acronym translation &lt;br /&gt;
!Description&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;which&#039;&#039;&#039; &amp;lt;COMMAND&amp;gt;&lt;br /&gt;
|&amp;lt;nowiki&amp;gt;-&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|Shows the full path to the command.&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;read&#039;&#039;&#039; [OPTION] [input1] [input2] [input3]&lt;br /&gt;
|&amp;lt;nowiki&amp;gt;-&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|Can be used to prompt user for input and save them as variables [input1]..[input3].  &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Shebang &#039;#!&#039; ===&lt;br /&gt;
When making a shell script, the file extension &#039;.sh&#039; lets other users know that the file is a shell script. However, this sort of file extension doesn&#039;t actually affect how your system interprets the file. You could write whatever you want as your file extension and it wouldn&#039;t matter. What&#039;s important is to give your file something called a &#039;shebang&#039; (which are the symbols &#039;#!&#039;) as the first line. This is followed by a space and file path to the interpreter you would like to use in your script. This interpreter could be a shell but it could also be a programming language interpreter. In one case (&#039;&#039;&#039;1&#039;&#039;&#039; in &#039;&#039;&#039;figure 1&#039;&#039;&#039;), we want to use bash as our interpreter. But we can change the interpreter to python3 interpreter (&#039;&#039;&#039;2&#039;&#039;&#039; in &#039;&#039;&#039;figure 1&#039;&#039;&#039;). This, however, results in a syntax error because the command &#039;&#039;&#039;echo&#039;&#039;&#039; &#039;Hello&#039; is not python language.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Shebangs1.png|frame|none|&#039;&#039;&#039;Figure 1 Using #! to set up your interpreter&#039;&#039;&#039; ]]&lt;br /&gt;
&lt;br /&gt;
Also, bash is your default interpreter so if you were to delete the &#039;shebang&#039; and just execute the file,&lt;br /&gt;
 Prompt$ ./testfile.blabla&lt;br /&gt;
it would also work. However, if you were working on a server where bash wasn&#039;t the default interpreter, executing the file without shebangs might cause problems. Essentially, &#039;shebangs&#039; ensure that your script is always executed with the intended interpreter, which in turn ensures that the file is executed properly.  &lt;br /&gt;
&lt;br /&gt;
Well almost always, as it&#039;s possible to forego &#039;shebangs&#039; and use whatever interpreter you like from the command line. We&#039;ve already been doing this earlier with &#039;&#039;&#039;bash&#039;&#039;&#039;.&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;bash&#039;&#039;&#039;  &amp;lt;shell_script&amp;gt;&lt;br /&gt;
This would result in a file being interpreted by bash regardless of what has been specified in the file. This means that if you know which language a script is written in, you don&#039;t have to add a &#039;shebang&#039;. But it&#039;s still a good practice. Just imagine a scenario, where you need to use multiple scripts written in different languages. &lt;br /&gt;
&lt;br /&gt;
When making a &#039;shebang&#039;, you need to know where your interpreters are located. For shells, they&#039;ll typically be located in the directory /bin. You can check which shells are available on your system by looking in the file &amp;lt;shells&amp;gt;, &lt;br /&gt;
Prompt$ cat /etc/shells&lt;br /&gt;
&lt;br /&gt;
You can always check where commands/programs, such as interpreters, are located with the &#039;&#039;&#039;which&#039;&#039;&#039; command, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;which&#039;&#039;&#039; [COMMAND] &lt;br /&gt;
which outputs the path to the specified Unix command. On a side note, it&#039;s worth knowing that when &#039;&#039;&#039;which&#039;&#039;&#039; and commands in general are executed, the shell will locate the command with the closest absolute path. This means that if you were to have two duplicate programs, it is the one with the closest absolute path that is used.  &lt;br /&gt;
&lt;br /&gt;
=== Comments === &lt;br /&gt;
In shell scripting, you should make comments that explain your shell script. This can be done by entering the symbol &#039;#&#039; at the start of line, which results in the following text on that line, to be disregarded by your interpreter. So if you were to type,  &lt;br /&gt;
 # Comment for my shell script.&lt;br /&gt;
in some line in your shell script, your interpreter won&#039;t regard it as bash script.&lt;br /&gt;
&lt;br /&gt;
=== Variables ===&lt;br /&gt;
When writing a shell script, you might want to define variables in your code. There are user and system variables. In &#039;&#039;&#039;figure 2&#039;&#039;&#039;, both types of variables are shown. A user variable like var1 can be assigned the value, 1, with the syntax, &lt;br /&gt;
 var1=1&lt;br /&gt;
Values can be extracted by with a &#039;&#039;&#039;$&#039;&#039;&#039; in front of the variable. So typing,   &lt;br /&gt;
 &#039;&#039;&#039;echo&#039;&#039;&#039; $var1  &lt;br /&gt;
in a shell script will output &#039;1&#039;. &lt;br /&gt;
&lt;br /&gt;
It&#039;s also possible to save the output of Unix commands as variables by using backtick symbols &#039;&#039;&#039;``&#039;&#039;&#039;. This is shown in &#039;&#039;&#039;figure 2&#039;&#039;&#039;, with the command &#039;&#039;&#039;cal&#039;&#039;&#039; that displays a nice calendar. &lt;br /&gt;
System variables, also called &#039;environment variables&#039;, are simply variables defined by your system. Examples of these are $SHELL, $BASH, $BASH_VERSION, $USER, $IFS, $HOME and (Internal field separator), etc. The environment variable, $SHELL, point two the shell that is used by default on your system. $BASH points to the execution path for &#039;&#039;&#039;bash&#039;&#039;&#039; (/bin/bash). Environment variables can change depending on which shell you&#039;re using, $BASH and $BASH_VERSION will for example not be valid when you&#039;re not using a BASH shell. The $HOME variable indicate where the home directory is located in your file system.  &lt;br /&gt;
You can list all of these commands by typing &#039;&#039;env&#039;&#039;&#039; in your terminal.&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;env&#039;&#039;&#039; &lt;br /&gt;
[[File:Variables ShellScripts.png|frame|center|&#039;&#039;&#039;Figure 2 Variables:&#039;&#039;&#039; Firstly, the bash version is outputted by using the system variable, BASH_VERSION. Hereafter, user variables are set to various values and then extracted with $ in an &#039;&#039;&#039;echo&#039;&#039;&#039; command. The command line option &#039;&#039;&#039;-e&#039;&#039;&#039;, is an option that enables interpretation of backslash characters (in this the newline character &#039;\n&#039;).]]&lt;br /&gt;
&lt;br /&gt;
Variables are of course not limited to shell scripts, and you can also define variables in your terminal. The difference, however, is that the variables you set in your terminal, won&#039;t reset until your terminal session ends. When running a shell script, all variables that were set during the process, will reset after completion of the process.&lt;br /&gt;
&lt;br /&gt;
== Reading user input ==&lt;br /&gt;
&lt;br /&gt;
Shell scripts can receive user input from the terminal, in the form of user arguments. It&#039;s quite simple to do as shown in &#039;&#039;&#039;figure 3&#039;&#039;&#039;. &lt;br /&gt;
[[File:UserArguments.png|frame|none|&#039;&#039;&#039;Figure 3 User arguments:  &#039;&#039;&#039; Four user arguments are saved as variables in the shell script. The user arguments are saved are by default as 1, 2, 3 and 4. These values are extracted with &#039;&#039;&#039;$&#039;&#039;&#039; and outputted with &#039;&#039;&#039;echo&#039;&#039;&#039;. All of the user arguments are also saved to the variable &#039;Fourelements&#039;, which is then outputted with &#039;&#039;&#039;echo&#039;&#039;&#039;. Lastly, a for loop is used to output all elements in  &#039;Fourelements&#039; sequentially. If you are unfamiliar with for loops, you can check this link out [https://www.cyberciti.biz/faq/bash-for-loop/ For loops], which has a good explanation for how for loops work and their syntax in bash.]]&lt;br /&gt;
&lt;br /&gt;
There&#039;s no limit to how many user arguments that can be passed to a file and they&#039;re saved as &#039;&#039;&#039;$1..$99&#039;&#039;&#039; in the shell script. Furthermore, all user arguments are stored in the variable, &#039;&#039;&#039;@&#039;&#039;&#039;. So by typing, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;echo&#039;&#039;&#039; $@&lt;br /&gt;
in your shell script, all user arguments will be outputted. &lt;br /&gt;
&lt;br /&gt;
You can save all these user arguments to one variable,  &lt;br /&gt;
 var=$@&lt;br /&gt;
and extract user arguments separately using the syntax, &lt;br /&gt;
 ${var[i]}  &lt;br /&gt;
which will extract the user argument at position &#039;&#039;&#039;i&#039;&#039;&#039; in var. &lt;br /&gt;
&lt;br /&gt;
Shell scripts can also be made to prompt the user for input or multiple inputs with the command &#039;&#039;&#039;read&#039;&#039;&#039;, as shown in &#039;&#039;&#039;figure 4&#039;&#039;&#039;.  &lt;br /&gt;
[[File:Read ShellScript.png|none|frame|&#039;&#039;&#039;Figure 4 Read command:&#039;&#039;&#039; The command &#039;&#039;&#039;read&#039;&#039;&#039; is used to obtain user input and save them as variables within the shell script. This is done with different command options. The &#039;&#039;&#039;p&#039;&#039;&#039; option allows us to create prompt (in this case &#039;What is your last name and age?&#039;) without a trailing newline character. The &#039;&#039;&#039;s&#039;&#039;&#039; option, ensures that what is typed, is not displayed on the screen.]]    &lt;br /&gt;
&lt;br /&gt;
It&#039;s worth knowing that if you don&#039;t specify a variable with &#039;&#039;&#039;read&#039;&#039;&#039;, bash saves user input as a system variable called &#039;&#039;$REPLY&#039;&#039;. For example,&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;read &amp;amp;&amp;amp; echo&#039;&#039;&#039; $REPLY &lt;br /&gt;
will output whatever you entered from your keyboard.&lt;br /&gt;
&lt;br /&gt;
== Exercise 1: User info file == &lt;br /&gt;
Make a shell script that prompts the user for a username and password (make it stealthy). The information should be stored inside a file called &amp;lt;user_info.txt&amp;gt;. The username and password need to be stored neatly on separte lines likeso:&lt;br /&gt;
 username:blabla&lt;br /&gt;
 password:blabla&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/unix/index.php?title=File:Setting_up_Sublime3.png&amp;diff=30</id>
		<title>File:Setting up Sublime3.png</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/unix/index.php?title=File:Setting_up_Sublime3.png&amp;diff=30"/>
		<updated>2024-03-20T12:04:35Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/unix/index.php?title=Text_editors_and_some_shell_scripting&amp;diff=29</id>
		<title>Text editors and some shell scripting</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/unix/index.php?title=Text_editors_and_some_shell_scripting&amp;diff=29"/>
		<updated>2024-03-20T12:03:54Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Exercise 1: Making a simple shell script with vim. */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
In the last sections we learned how to use commands that move and work with files, but we haven&#039;t learned how to actually edit files, which is what we&#039;ll be &lt;br /&gt;
learning in this section. Text editors are used for editing files and there are many text editors to choose from. You&#039;ve probably already used some text editors, like &#039;&#039;Notepad&#039;&#039; or &#039;&#039;TextEdit&#039;&#039;, as these are the default text editors on a Windows or Mac OS. In this section, we&#039;ll be taking a look at a lot of different text editors. It&#039;s good to idea to be familiar with a lot of text editors because if you&#039;re working on a server that doesn&#039;t have the text editor you&#039;re used to, it&#039;s good to have another text editor that you&#039;re somewhat familiar with.  &lt;br /&gt;
&lt;br /&gt;
The first text editor we&#039;ll be looking at is the &#039;vim&#039; editor, as it&#039;s used ubiquitously across different OS&#039;s and servers. &lt;br /&gt;
Next, we&#039;ll briefly introduce some other text editors; Nedit, Gedit, Pico and Emacs. Becoming proficient in all of these text editors is a bit excessive, and it&#039;s not a criteria for this course. It is, however, a good idea just to know that many text editors exist. If you&#039;re ever in need of using one of these text editors, it&#039;s pretty straightforward to &#039;google&#039; your way to a guide, or use some of them links presented in this section. &lt;br /&gt;
&lt;br /&gt;
In this section, we&#039;ll take a sneak peak at shell scripting. At the simplest level, shell scripts are multiple commands saved within a file. When the file is executed, the commands within are run. This is useful when you need to do the same workflow on multiple tasks, which can be quite labor intensive. &lt;br /&gt;
On a more complex level, shell scripts can be equipped with syntax like &#039;&#039;for&#039;&#039; and &#039;&#039;while&#039;&#039; loops, and you can actually do programming in shell scripts. However, doing large programs in shell scripts isn&#039;t recommended as BASH and other shell syntaxes can be quite difficult to learn and read. Instead, you&#039;d be better off using a programming language such as &#039;Python&#039;, &#039;C++&#039;, &#039;Java&#039; etc..&lt;br /&gt;
&lt;br /&gt;
Also, when making shell scripts it&#039;s a good idea to keep reproducibility in mind. This can be done by giving your script a proper title, that adequately explains the function of your script. It&#039;s also paramount to make comments in your script, which makes it easier for others (and yourself in half a year) to understand and use your script. It also makes it easier to change the script. In the next section, we&#039;ll go into detail with comments and the other basics of shell scripts.       &lt;br /&gt;
&lt;br /&gt;
In the last bit of the section, we present a guide on installing &#039;Sublime 3&#039;, a user-friendly and a nice text editor for programming. We&#039;ll set it up so it can be run from the command line on your Windows or Mac computer. &lt;br /&gt;
&lt;br /&gt;
Underneath are some of the commands we&#039;ll be using in this section. &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Unix Command&lt;br /&gt;
!Acronym translation &lt;br /&gt;
!Description&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;alias&#039;&#039;&#039; &amp;lt;nowiki&amp;gt;&amp;lt;alias_name&amp;gt;=&amp;lt;The stuff you want to make an alias for&amp;gt;&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|&amp;lt;nowiki&amp;gt;-&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|Creates an alias called alias_name for what you&#039;ve inserted on the right side of &#039;=&#039;&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;source&#039;&#039;&#039; &amp;lt;FILE&amp;gt; &lt;br /&gt;
|&amp;lt;nowiki&amp;gt;-&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|Executes the contents of a file in current shell. Changes made when the file is run will be permanent until changed. It is synonymous with Prompt$ &#039;&#039;&#039;.&#039;&#039;&#039; &amp;lt;FILE&amp;gt;.   &lt;br /&gt;
|- &lt;br /&gt;
|&#039;&#039;&#039;bash&#039;&#039;&#039; &amp;lt;FILE&amp;gt;&lt;br /&gt;
|Bourne again shell&lt;br /&gt;
|&#039;&#039;&#039;Bash&#039;&#039;&#039; will execute &amp;lt;FILE&amp;gt; as a different process. This way, changes that occur while the file is being executed cannot affect your shell.  &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The command, &#039;&#039;&#039;alias&#039;&#039;&#039;, is useful when you want to simplify long commands or if you often need to go to faraway directory with a long file path. You can for instance, make a directory that allows you to go to your desktop quickly. &lt;br /&gt;
 Prompt$ alias desktop=&#039;cd filepath_to_Desktop/Desktop&#039;  &lt;br /&gt;
This will create an alias called &#039;desktop&#039;, which will change your directory to your Desktop. These changes, however, are only temporary and the next time you open your terminal it won&#039;t work. In order to make it a permanent alias we have to edit in what&#039;s called the &#039;&#039;.bashrc&#039;&#039; file, which is located in your home directory, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;cd&#039;&#039;&#039; ~ &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;ls -a&#039;&#039;&#039; &amp;lt;home directory&amp;gt;&lt;br /&gt;
It&#039;s a hidden file, indicated by the dot symbol &#039;.&#039;, which is why you have to use the command option &#039;&#039;&#039;-a&#039;&#039;&#039; to see it. On the MAC OS, this file is called &#039;&#039;&#039;.bash_profile&#039;&#039;&#039; instead. The &#039;&#039;.bashrc&#039;&#039; file contains the commands that are run when you start a bash shell, and the &#039;rc&#039; in &#039;&#039;.bashrc&#039;&#039; is actually short for &#039;run commands&#039;. Therefore, to make the alias permanent you need simply append the alias to &#039;&#039;.bashrc&#039;&#039;.&lt;br /&gt;
 Prompt$ echo &#039;alias desktop=&#039;cd filepath_to_Desktop/Desktop/&#039; &amp;gt;&amp;gt; .bashrc&lt;br /&gt;
This will ensure that the next time you open a terminal, the alias command will be run.&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Instead of closing and opening your terminal to restart it you can instead type,&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;source&#039;&#039;&#039; .bashrc &lt;br /&gt;
which will ensure that the commands within &#039;&#039;.bashrc&#039;&#039; are run. Alternatively one could write &#039;&#039;&#039;&#039;.&#039;&#039;&#039; .bashrc&#039;, which is synonymous to &#039;&#039;&#039;&#039;source&#039;&#039;&#039; .bashrc&#039;  &lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;bash&#039;&#039;&#039; command, which is the command we&#039;ll be using to execute shell scripts, is somewhat similar to &#039;&#039;&#039;source&#039;&#039;&#039; because it also executes files. But the difference is that &#039;&#039;&#039;bash&#039;&#039;&#039; executes files in a separate process than the terminal. Remember, the terminal is a program itself and an ongoing process. This way commands that might change the settings of the terminal are only set during the execution of the file. Therefore you would never write,&lt;br /&gt;
 Prompt$ bash .bashrc&lt;br /&gt;
when restarting your bash. In figure 3.1 we show the difference between &#039;&#039;&#039;source&#039;&#039;&#039; and &#039;&#039;&#039;bash&#039;&#039;&#039;. The file, test.sh, contains a variable called Variable1. Variables can be assigned with the syntax, variable_name=variable_value, and &#039;&#039;&#039;$&#039;&#039;&#039; is a special character that let&#039;s the shell know, that subsequent string is a variable. If the &#039;&#039;&#039;$&#039;&#039;&#039; wasn&#039;t used, &#039;&#039;&#039;echo&#039;&#039;&#039; would output &#039;Variable1&#039;. In the figure we see that when &#039;&#039;&#039;bash&#039;&#039;&#039; is used to execute &#039;&#039;test.sh&#039;&#039;, the variable is not saved. Conversely, when &#039;&#039;&#039;source&#039;&#039;&#039; is used, the variable is saved.   &lt;br /&gt;
[[File:Bash vs source.png|none|frame|&#039;&#039;&#039;Figure 3.1 Bash command vs source command:&#039;&#039;&#039;]]&lt;br /&gt;
&lt;br /&gt;
== Vim editor == &lt;br /&gt;
The vim editor is one of the most widely available text editors. It&#039;s by default installed on most systems and therefore worth knowing. &lt;br /&gt;
Start by following this link to a couple of introductory videos on the Vim/vi editor [https://www.youtube.com/watch?v=SI8TeVMX8pk&amp;amp;list=PLPyiwIbA1EVmT3QIzltwGszhdSVEr1DkD&amp;amp;index=4 Vim/vi editor tutorial videos]. &lt;br /&gt;
&lt;br /&gt;
To open a file with the vim editor simply type, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;vim&#039;&#039;&#039; &amp;lt;FILE&amp;gt;&lt;br /&gt;
An important vim editor feature, is that there are multiple mode from which different commands can be issued. The 3 most important modes; are command mode (also called normal mode), insert mode and visual mode. After having opened a file with vim, you&#039;ll start out in the command mode. You can move your cursor around with the arrow keys. There are other more elaborate ways for navigating, such as moving an entire line forth/back, but unless you&#039;re constantly using vim this sort of navigation can be difficult to remember. From the command mode you can issue commands, like entering insert and visual mode. Before we do that, however, it&#039;s important to know how to exit the vim editor. While in the command mode, type&lt;br /&gt;
 &#039;&#039;&#039;:wq&#039;&#039;&#039; &lt;br /&gt;
which will appear at the bottom of vim editor display. This will save your file and exit. If you simply want to exit, type&lt;br /&gt;
 &#039;&#039;&#039;:q&#039;&#039;&#039; &lt;br /&gt;
which will exit your file without saving. If this doesn&#039;t work, it&#039;s probably because you&#039;re not in command mode. You can always return to command mode by typing the &#039;Esc&#039; key. &lt;br /&gt;
&lt;br /&gt;
While in command mode you can type &#039;i&#039; and &#039;v&#039; to enter insert and visual mode respectively. Within the insert mode, you can write and delete text as you would in any text editor. The visual mode is used for highlighting text, that you want deleted, copied and replaced. From the command line you can actually enter 3 types of visual modes; visual (&#039;v&#039;), visual line (&#039;shift-v&#039;) and visual block (&#039;ctrl-v&#039;). These difference visual modes are simply different ways for which text can be highlighted. First set your cursor to where you want to start highlighting, then enter one of the 3 visual modes. You can then choose the text that you want highlighted by moving the cursor. It is within the visual mode, that you can copy/cut/paste content of the file. To do this, first highlight the text you want cut/copied by entering one of the 3 visual modes. From here, you can then press &#039;d&#039; to cut and &#039;y&#039; to copy. Subsequently, you can move to where you want the content pasted with the arrow keys, and press &#039;P&#039; to paste before the cursor, and &#039;p&#039; to paste after the cursor.  &lt;br /&gt;
&lt;br /&gt;
If you&#039;ve done a something that you shouldn&#039;t have done within vim, you can undo your previous action by typing &#039;u&#039; while in command mode. Also, you can move your cursor to a specific line by typing &amp;lt;Line number&amp;gt;-G while in command mode. This will move your cursor to the line specified by line number. The number of utilities for the vim editor is long and it&#039;s likely that you might never have use for any of them. For now, what&#039;s important is that your able to open a file, edit the file in insert mode, copy/paste content with visual mode and save/exit the file.    &lt;br /&gt;
&lt;br /&gt;
=== Exercise 1: Making a simple shell script with vim. === &lt;br /&gt;
Datafile 1: [https://teaching.healthtech.dtu.dk/material/unix/Pseudomonas_Aeruginosa_16SrRNA.gb Pseudomonas Aeruginosa 16S rRNA Genebank file]&amp;lt;br&amp;gt;&lt;br /&gt;
Datafile 2: [https://teaching.healthtech.dtu.dk/material/unix/ex1.acc ex1.acc]&amp;lt;br&amp;gt;&lt;br /&gt;
Datafile 3: [https://teaching.healthtech/material/unix/ex1.dat ex1.dat]&amp;lt;br&amp;gt;&lt;br /&gt;
1. Download the 3 datafiles.&amp;lt;br&amp;gt; &lt;br /&gt;
2. Create a file with the ending &#039;.sh&#039;, which makes it a shell executable file, in your current directory.&amp;lt;br&amp;gt; &lt;br /&gt;
3. Open it with vim and go into insert mode.&amp;lt;br&amp;gt; &lt;br /&gt;
4. While in insert mode type in a command that will create a sub-directory to your current directory.&amp;lt;br&amp;gt;   &lt;br /&gt;
5. On the second line, type in a command that copies the 3 data files to this subdirectory.&amp;lt;br&amp;gt; &lt;br /&gt;
6. On the third line, type in a command that merges the 3 data files and saves it as merged.dat.&amp;lt;br&amp;gt;&lt;br /&gt;
7. On the fifth line, type in a command that will delete the subdirectory that you created.&amp;lt;br&amp;gt;&lt;br /&gt;
8. Exit the file and execute the file from the command line by typing, &lt;br /&gt;
 Prompt$ bash &amp;lt;file.sh&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== .vimrc file  ===&lt;br /&gt;
The .vimrc, where the &#039;rc&#039; is short for &amp;quot;run commands&amp;quot;, is a file that contains commands that are run whenever you open a file with vim. It&#039;s located as a hidden file within your home directory or if you on a MAC OS, it should be located at /usr/share/vim/vimrc. You can think of it as a settings file for the vim editor. By default your .vimrc file should be empty and customizing your vim editor is a task completely up to you. Customizing .vimrc is simple, just open it with vim as you would any other file. Underneath is link to a video, that explains some basic settings you could do in your .vimrc file.  &lt;br /&gt;
[https://www.youtube.com/watch?v=-jB6i--_XrU Tutorial on some basic .vimrc settings]&lt;br /&gt;
&lt;br /&gt;
You can actually also download a premade .vimrc file that gives your vim editor a lot of extra utility. However, as you might someday be working on computers where  these utilities aren&#039;t available, it&#039;s a good idea that you first become efficient with the default vim editor.&lt;br /&gt;
&lt;br /&gt;
== Other text editors; Nedit, Gedit, Pico and Emacs == &lt;br /&gt;
Here, we present some &#039;very short&#039; introduction of some other text editors that you might run into.&lt;br /&gt;
*Nedit&lt;br /&gt;
Nedit, short for &#039;Nirvana editor&#039;, has an interface similar to that of text editors found natively on Windows and Mac computers. It has some functionalities that it excels at, which are listed have been listed and explained in this link [https://blog.ostermiller.org/nedit/ Nedit]. &lt;br /&gt;
&lt;br /&gt;
[https://sourceforge.net/projects/nedit/ nedit download]&lt;br /&gt;
*Gedit&lt;br /&gt;
Gedit is the default text editor in GNOME desktop environments. We haven&#039;t talked about &#039;GNU project&#039; and &#039;GNOME&#039; yet so this might be a good time. &#039;GNU&#039; is not an acronym, but another name for a wildebeest (remember those things that killed the lion king, yep), which was like the mascot for the project. Essentially, the &#039;GNU project&#039; was a mass-collaboration project that started in September 27 1983 with the goal of giving computer users more control of their computers by providing free software to users. GNOME, short for &#039;GNU Network Object Model Environment&#039; was one of the results of this project, and it&#039;s actually the default desktop environment used by many Linux distributions, for example, Ubuntu uses it. GNOME has provided a help guide, that can help you get started if you want to learn gedit- [https://help.gnome.org/users/gedit/stable/ Help guide to gedit] &lt;br /&gt;
&lt;br /&gt;
[https://sourceforge.net/projects/gedit/ gedit download]&lt;br /&gt;
*Pico&lt;br /&gt;
Pico, short for &#039;Pine composer&#039;, is text editor for UNIX based computer based systems. The good thing about learning Pico, is that it&#039;s simple and easy to learn. The downside to pico is that it doesn&#039;t have as many features as for example the &#039;vim editor&#039; which we&#039;ll be learning later. Also, pico has a clone text editor called &#039;nano&#039; which was created as part of the GNU project due to unclear redistribution terms. So if you&#039;ve learned &#039;pico&#039; then you&#039;ve also learned nano. If you&#039;re interested in learning pico, a good start would be to watch this video [https://www.youtube.com/watch?v=o5IY1dMUpc0 Pico text editor introduction]. &lt;br /&gt;
&lt;br /&gt;
[http://picocms.org/download/ pico download]&lt;br /&gt;
&lt;br /&gt;
*Emacs&lt;br /&gt;
Emacs was initially released in 1976, and has since undergone many tweeks and updates. Among programmers, there exists a something called the &#039;Editor war&#039;, which is like a rivalry between &#039;emacs&#039; and &#039;vim&#039; [https://en.wikipedia.org/wiki/Editor_war Editor war]. It&#039;s, however, considerably more difficult to learn &#039;emacs&#039; compared to &#039;vim&#039;. To get you started with emacs, you should have no trouble finding various tutorials on youtube. &lt;br /&gt;
&lt;br /&gt;
To install emacs, it&#039;s best to use UNIX commands &#039;&#039;&#039;sudo&#039;&#039;&#039; and &#039;&#039;&#039;apt&#039;&#039;&#039; to ensure that it&#039;s installed properly. Here&#039;s what you would type in your terminal, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sudo apt -y install&#039;&#039;&#039; emacs  &lt;br /&gt;
&lt;br /&gt;
== Sublime 3 ==&lt;br /&gt;
&lt;br /&gt;
=== Windows === &lt;br /&gt;
Sublime is a pretty cool text editor with some nice features, especially for programming purposes. There are two good ways of setting up Sublime 3 in a Unix terminal on a Windows computer. One way is to use a program called &#039;&#039;Xming&#039;&#039; coupled with the use of the Unix commands &#039;&#039;&#039;apt&#039;&#039;&#039; and &#039;&#039;&#039;sudo&#039;&#039;&#039;. But as we haven&#039;t covered these commands yet (they will be presented in the section &#039;&#039;&#039;Advanced Packaging tools&#039;&#039;&#039;), we won&#039;t be using this method. &lt;br /&gt;
&lt;br /&gt;
For the other method, start off by downloading the windows version of Sublime text by following this link [https://www.sublimetext.com/3 Sublime download link]. When installing Sublime 3, make sure you know where you&#039;re saving it (by default, windows will save it in &#039;&#039;\Program Files&#039;&#039;). Once you&#039;ve successfully installed Sublime 3  start your Ubuntu WSL terminal.&lt;br /&gt;
From your terminal, you can directly access sublime text by specifying the filepath to &#039;subl.exe&#039;,&lt;br /&gt;
&lt;br /&gt;
 Prompt$ /mnt/c/Program\ Files/Sublime\ Text\ 3/subl.exe &amp;lt;FILE&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will open &amp;lt;FILE&amp;gt; with the sublime text editor. The &#039;\ &#039; are how spaces are written in a command line. This can be confusing so spaces are often avoided in filenames by replacing spaces with &#039;_&#039;. We can avoid having to write such a long filepath everytime we use sublime by using the command &#039;&#039;&#039;alias&#039;&#039;&#039;,&lt;br /&gt;
&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;alias&#039;&#039;&#039; subl=&#039;/mnt/c/Program\ Files/Sublime\ Text\ 3/subl.exe&#039; &lt;br /&gt;
which creates an alias for what&#039;s specified after &#039;=&#039;. This way, typing &#039;&#039;&#039;subl&#039;&#039;&#039;&amp;lt;file&amp;gt;, will open the file in sublime text editor. This alias, however, is not permanent and the next time you start your terminal you&#039;ll need to write it again. In order to make it a permanent alias we have to edit in what&#039;s called the .bashrc file, which is located in your home directory, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;cd&#039;&#039;&#039; ~ &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;echo&#039;&#039;&#039; &#039;alias subl=&#039;/mnt/c/Program\ Files/Sublime\ Text\ 3/subl.exe&#039;&#039; &amp;gt;&amp;gt; .bashrc &lt;br /&gt;
Now everytime you start bash the alias command will be run. In figure 3.1, we show the commands that need to be executed in the terminal.&lt;br /&gt;
[[File:Setting up Sublime3.png|frame|none|&#039;&#039;&#039;Figure 3.1 Setting up Sublime 3:&#039;&#039;&#039; The directory is changed to the home directory by typing &#039;&#039;&#039;cd&#039;&#039;&#039; ~, and all files within the home directory are listed using the command &#039;&#039;&#039;ls -a&#039;&#039;&#039;. The alias is appended to .bashrc using &#039;&#039;&#039;echo&#039;&#039;&#039;, and afterwards .bashrc is executed using the command &#039;&#039;&#039;source&#039;&#039;&#039;]]&lt;br /&gt;
=== Mac === &lt;br /&gt;
For Mac computers, the installation method for Sublime 3 is similar to the Windows installation. You can download the mac version of Sublime 3 by following the link, [https://www.sublimetext.com/3 Sublime download link].&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/unix/index.php?title=File:Bash_vs_source.png&amp;diff=28</id>
		<title>File:Bash vs source.png</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/unix/index.php?title=File:Bash_vs_source.png&amp;diff=28"/>
		<updated>2024-03-20T12:02:40Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/unix/index.php?title=Text_editors_and_some_shell_scripting&amp;diff=27</id>
		<title>Text editors and some shell scripting</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/unix/index.php?title=Text_editors_and_some_shell_scripting&amp;diff=27"/>
		<updated>2024-03-20T12:02:08Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: Created page with &amp;quot;__NOTOC__ In the last sections we learned how to use commands that move and work with files, but we haven&amp;#039;t learned how to actually edit files, which is what we&amp;#039;ll be  learning in this section. Text editors are used for editing files and there are many text editors to choose from. You&amp;#039;ve probably already used some text editors, like &amp;#039;&amp;#039;Notepad&amp;#039;&amp;#039; or &amp;#039;&amp;#039;TextEdit&amp;#039;&amp;#039;, as these are the default text editors on a Windows or Mac OS. In this section, we&amp;#039;ll be taking a look at a lot...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
In the last sections we learned how to use commands that move and work with files, but we haven&#039;t learned how to actually edit files, which is what we&#039;ll be &lt;br /&gt;
learning in this section. Text editors are used for editing files and there are many text editors to choose from. You&#039;ve probably already used some text editors, like &#039;&#039;Notepad&#039;&#039; or &#039;&#039;TextEdit&#039;&#039;, as these are the default text editors on a Windows or Mac OS. In this section, we&#039;ll be taking a look at a lot of different text editors. It&#039;s good to idea to be familiar with a lot of text editors because if you&#039;re working on a server that doesn&#039;t have the text editor you&#039;re used to, it&#039;s good to have another text editor that you&#039;re somewhat familiar with.  &lt;br /&gt;
&lt;br /&gt;
The first text editor we&#039;ll be looking at is the &#039;vim&#039; editor, as it&#039;s used ubiquitously across different OS&#039;s and servers. &lt;br /&gt;
Next, we&#039;ll briefly introduce some other text editors; Nedit, Gedit, Pico and Emacs. Becoming proficient in all of these text editors is a bit excessive, and it&#039;s not a criteria for this course. It is, however, a good idea just to know that many text editors exist. If you&#039;re ever in need of using one of these text editors, it&#039;s pretty straightforward to &#039;google&#039; your way to a guide, or use some of them links presented in this section. &lt;br /&gt;
&lt;br /&gt;
In this section, we&#039;ll take a sneak peak at shell scripting. At the simplest level, shell scripts are multiple commands saved within a file. When the file is executed, the commands within are run. This is useful when you need to do the same workflow on multiple tasks, which can be quite labor intensive. &lt;br /&gt;
On a more complex level, shell scripts can be equipped with syntax like &#039;&#039;for&#039;&#039; and &#039;&#039;while&#039;&#039; loops, and you can actually do programming in shell scripts. However, doing large programs in shell scripts isn&#039;t recommended as BASH and other shell syntaxes can be quite difficult to learn and read. Instead, you&#039;d be better off using a programming language such as &#039;Python&#039;, &#039;C++&#039;, &#039;Java&#039; etc..&lt;br /&gt;
&lt;br /&gt;
Also, when making shell scripts it&#039;s a good idea to keep reproducibility in mind. This can be done by giving your script a proper title, that adequately explains the function of your script. It&#039;s also paramount to make comments in your script, which makes it easier for others (and yourself in half a year) to understand and use your script. It also makes it easier to change the script. In the next section, we&#039;ll go into detail with comments and the other basics of shell scripts.       &lt;br /&gt;
&lt;br /&gt;
In the last bit of the section, we present a guide on installing &#039;Sublime 3&#039;, a user-friendly and a nice text editor for programming. We&#039;ll set it up so it can be run from the command line on your Windows or Mac computer. &lt;br /&gt;
&lt;br /&gt;
Underneath are some of the commands we&#039;ll be using in this section. &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Unix Command&lt;br /&gt;
!Acronym translation &lt;br /&gt;
!Description&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;alias&#039;&#039;&#039; &amp;lt;nowiki&amp;gt;&amp;lt;alias_name&amp;gt;=&amp;lt;The stuff you want to make an alias for&amp;gt;&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|&amp;lt;nowiki&amp;gt;-&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|Creates an alias called alias_name for what you&#039;ve inserted on the right side of &#039;=&#039;&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;source&#039;&#039;&#039; &amp;lt;FILE&amp;gt; &lt;br /&gt;
|&amp;lt;nowiki&amp;gt;-&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|Executes the contents of a file in current shell. Changes made when the file is run will be permanent until changed. It is synonymous with Prompt$ &#039;&#039;&#039;.&#039;&#039;&#039; &amp;lt;FILE&amp;gt;.   &lt;br /&gt;
|- &lt;br /&gt;
|&#039;&#039;&#039;bash&#039;&#039;&#039; &amp;lt;FILE&amp;gt;&lt;br /&gt;
|Bourne again shell&lt;br /&gt;
|&#039;&#039;&#039;Bash&#039;&#039;&#039; will execute &amp;lt;FILE&amp;gt; as a different process. This way, changes that occur while the file is being executed cannot affect your shell.  &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The command, &#039;&#039;&#039;alias&#039;&#039;&#039;, is useful when you want to simplify long commands or if you often need to go to faraway directory with a long file path. You can for instance, make a directory that allows you to go to your desktop quickly. &lt;br /&gt;
 Prompt$ alias desktop=&#039;cd filepath_to_Desktop/Desktop&#039;  &lt;br /&gt;
This will create an alias called &#039;desktop&#039;, which will change your directory to your Desktop. These changes, however, are only temporary and the next time you open your terminal it won&#039;t work. In order to make it a permanent alias we have to edit in what&#039;s called the &#039;&#039;.bashrc&#039;&#039; file, which is located in your home directory, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;cd&#039;&#039;&#039; ~ &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;ls -a&#039;&#039;&#039; &amp;lt;home directory&amp;gt;&lt;br /&gt;
It&#039;s a hidden file, indicated by the dot symbol &#039;.&#039;, which is why you have to use the command option &#039;&#039;&#039;-a&#039;&#039;&#039; to see it. On the MAC OS, this file is called &#039;&#039;&#039;.bash_profile&#039;&#039;&#039; instead. The &#039;&#039;.bashrc&#039;&#039; file contains the commands that are run when you start a bash shell, and the &#039;rc&#039; in &#039;&#039;.bashrc&#039;&#039; is actually short for &#039;run commands&#039;. Therefore, to make the alias permanent you need simply append the alias to &#039;&#039;.bashrc&#039;&#039;.&lt;br /&gt;
 Prompt$ echo &#039;alias desktop=&#039;cd filepath_to_Desktop/Desktop/&#039; &amp;gt;&amp;gt; .bashrc&lt;br /&gt;
This will ensure that the next time you open a terminal, the alias command will be run.&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Instead of closing and opening your terminal to restart it you can instead type,&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;source&#039;&#039;&#039; .bashrc &lt;br /&gt;
which will ensure that the commands within &#039;&#039;.bashrc&#039;&#039; are run. Alternatively one could write &#039;&#039;&#039;&#039;.&#039;&#039;&#039; .bashrc&#039;, which is synonymous to &#039;&#039;&#039;&#039;source&#039;&#039;&#039; .bashrc&#039;  &lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;bash&#039;&#039;&#039; command, which is the command we&#039;ll be using to execute shell scripts, is somewhat similar to &#039;&#039;&#039;source&#039;&#039;&#039; because it also executes files. But the difference is that &#039;&#039;&#039;bash&#039;&#039;&#039; executes files in a separate process than the terminal. Remember, the terminal is a program itself and an ongoing process. This way commands that might change the settings of the terminal are only set during the execution of the file. Therefore you would never write,&lt;br /&gt;
 Prompt$ bash .bashrc&lt;br /&gt;
when restarting your bash. In figure 3.1 we show the difference between &#039;&#039;&#039;source&#039;&#039;&#039; and &#039;&#039;&#039;bash&#039;&#039;&#039;. The file, test.sh, contains a variable called Variable1. Variables can be assigned with the syntax, variable_name=variable_value, and &#039;&#039;&#039;$&#039;&#039;&#039; is a special character that let&#039;s the shell know, that subsequent string is a variable. If the &#039;&#039;&#039;$&#039;&#039;&#039; wasn&#039;t used, &#039;&#039;&#039;echo&#039;&#039;&#039; would output &#039;Variable1&#039;. In the figure we see that when &#039;&#039;&#039;bash&#039;&#039;&#039; is used to execute &#039;&#039;test.sh&#039;&#039;, the variable is not saved. Conversely, when &#039;&#039;&#039;source&#039;&#039;&#039; is used, the variable is saved.   &lt;br /&gt;
[[File:Bash vs source.png|none|frame|&#039;&#039;&#039;Figure 3.1 Bash command vs source command:&#039;&#039;&#039;]]&lt;br /&gt;
&lt;br /&gt;
== Vim editor == &lt;br /&gt;
The vim editor is one of the most widely available text editors. It&#039;s by default installed on most systems and therefore worth knowing. &lt;br /&gt;
Start by following this link to a couple of introductory videos on the Vim/vi editor [https://www.youtube.com/watch?v=SI8TeVMX8pk&amp;amp;list=PLPyiwIbA1EVmT3QIzltwGszhdSVEr1DkD&amp;amp;index=4 Vim/vi editor tutorial videos]. &lt;br /&gt;
&lt;br /&gt;
To open a file with the vim editor simply type, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;vim&#039;&#039;&#039; &amp;lt;FILE&amp;gt;&lt;br /&gt;
An important vim editor feature, is that there are multiple mode from which different commands can be issued. The 3 most important modes; are command mode (also called normal mode), insert mode and visual mode. After having opened a file with vim, you&#039;ll start out in the command mode. You can move your cursor around with the arrow keys. There are other more elaborate ways for navigating, such as moving an entire line forth/back, but unless you&#039;re constantly using vim this sort of navigation can be difficult to remember. From the command mode you can issue commands, like entering insert and visual mode. Before we do that, however, it&#039;s important to know how to exit the vim editor. While in the command mode, type&lt;br /&gt;
 &#039;&#039;&#039;:wq&#039;&#039;&#039; &lt;br /&gt;
which will appear at the bottom of vim editor display. This will save your file and exit. If you simply want to exit, type&lt;br /&gt;
 &#039;&#039;&#039;:q&#039;&#039;&#039; &lt;br /&gt;
which will exit your file without saving. If this doesn&#039;t work, it&#039;s probably because you&#039;re not in command mode. You can always return to command mode by typing the &#039;Esc&#039; key. &lt;br /&gt;
&lt;br /&gt;
While in command mode you can type &#039;i&#039; and &#039;v&#039; to enter insert and visual mode respectively. Within the insert mode, you can write and delete text as you would in any text editor. The visual mode is used for highlighting text, that you want deleted, copied and replaced. From the command line you can actually enter 3 types of visual modes; visual (&#039;v&#039;), visual line (&#039;shift-v&#039;) and visual block (&#039;ctrl-v&#039;). These difference visual modes are simply different ways for which text can be highlighted. First set your cursor to where you want to start highlighting, then enter one of the 3 visual modes. You can then choose the text that you want highlighted by moving the cursor. It is within the visual mode, that you can copy/cut/paste content of the file. To do this, first highlight the text you want cut/copied by entering one of the 3 visual modes. From here, you can then press &#039;d&#039; to cut and &#039;y&#039; to copy. Subsequently, you can move to where you want the content pasted with the arrow keys, and press &#039;P&#039; to paste before the cursor, and &#039;p&#039; to paste after the cursor.  &lt;br /&gt;
&lt;br /&gt;
If you&#039;ve done a something that you shouldn&#039;t have done within vim, you can undo your previous action by typing &#039;u&#039; while in command mode. Also, you can move your cursor to a specific line by typing &amp;lt;Line number&amp;gt;-G while in command mode. This will move your cursor to the line specified by line number. The number of utilities for the vim editor is long and it&#039;s likely that you might never have use for any of them. For now, what&#039;s important is that your able to open a file, edit the file in insert mode, copy/paste content with visual mode and save/exit the file.    &lt;br /&gt;
&lt;br /&gt;
=== Exercise 1: Making a simple shell script with vim. === &lt;br /&gt;
Datafile 1: [http://teaching.bioinformatics.dtu.dk/material/unix/Pseudomonas_Aeruginosa_16SrRNA.gb Pseudomonas Aeruginosa 16S rRNA Genebank file]&amp;lt;br&amp;gt;&lt;br /&gt;
Datafile 2: [http://teaching.bioinformatics.dtu.dk/material/36610/ex1.acc ex1.acc]&amp;lt;br&amp;gt;&lt;br /&gt;
Datafile 3: [http://teaching.bioinformatics.dtu.dk/material/36610/ex1.dat ex1.dat]&amp;lt;br&amp;gt;&lt;br /&gt;
1. Download the 3 datafiles.&amp;lt;br&amp;gt; &lt;br /&gt;
2. Create a file with the ending &#039;.sh&#039;, which makes it a shell executable file, in your current directory.&amp;lt;br&amp;gt; &lt;br /&gt;
3. Open it with vim and go into insert mode.&amp;lt;br&amp;gt; &lt;br /&gt;
4. While in insert mode type in a command that will create a sub-directory to your current directory.&amp;lt;br&amp;gt;   &lt;br /&gt;
5. On the second line, type in a command that copies the 3 data files to this subdirectory.&amp;lt;br&amp;gt; &lt;br /&gt;
6. On the third line, type in a command that merges the 3 data files and saves it as merged.dat.&amp;lt;br&amp;gt;&lt;br /&gt;
7. On the fifth line, type in a command that will delete the subdirectory that you created.&amp;lt;br&amp;gt;&lt;br /&gt;
8. Exit the file and execute the file from the command line by typing, &lt;br /&gt;
 Prompt$ bash &amp;lt;file.sh&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== .vimrc file  ===&lt;br /&gt;
The .vimrc, where the &#039;rc&#039; is short for &amp;quot;run commands&amp;quot;, is a file that contains commands that are run whenever you open a file with vim. It&#039;s located as a hidden file within your home directory or if you on a MAC OS, it should be located at /usr/share/vim/vimrc. You can think of it as a settings file for the vim editor. By default your .vimrc file should be empty and customizing your vim editor is a task completely up to you. Customizing .vimrc is simple, just open it with vim as you would any other file. Underneath is link to a video, that explains some basic settings you could do in your .vimrc file.  &lt;br /&gt;
[https://www.youtube.com/watch?v=-jB6i--_XrU Tutorial on some basic .vimrc settings]&lt;br /&gt;
&lt;br /&gt;
You can actually also download a premade .vimrc file that gives your vim editor a lot of extra utility. However, as you might someday be working on computers where  these utilities aren&#039;t available, it&#039;s a good idea that you first become efficient with the default vim editor.&lt;br /&gt;
&lt;br /&gt;
== Other text editors; Nedit, Gedit, Pico and Emacs == &lt;br /&gt;
Here, we present some &#039;very short&#039; introduction of some other text editors that you might run into.&lt;br /&gt;
*Nedit&lt;br /&gt;
Nedit, short for &#039;Nirvana editor&#039;, has an interface similar to that of text editors found natively on Windows and Mac computers. It has some functionalities that it excels at, which are listed have been listed and explained in this link [https://blog.ostermiller.org/nedit/ Nedit]. &lt;br /&gt;
&lt;br /&gt;
[https://sourceforge.net/projects/nedit/ nedit download]&lt;br /&gt;
*Gedit&lt;br /&gt;
Gedit is the default text editor in GNOME desktop environments. We haven&#039;t talked about &#039;GNU project&#039; and &#039;GNOME&#039; yet so this might be a good time. &#039;GNU&#039; is not an acronym, but another name for a wildebeest (remember those things that killed the lion king, yep), which was like the mascot for the project. Essentially, the &#039;GNU project&#039; was a mass-collaboration project that started in September 27 1983 with the goal of giving computer users more control of their computers by providing free software to users. GNOME, short for &#039;GNU Network Object Model Environment&#039; was one of the results of this project, and it&#039;s actually the default desktop environment used by many Linux distributions, for example, Ubuntu uses it. GNOME has provided a help guide, that can help you get started if you want to learn gedit- [https://help.gnome.org/users/gedit/stable/ Help guide to gedit] &lt;br /&gt;
&lt;br /&gt;
[https://sourceforge.net/projects/gedit/ gedit download]&lt;br /&gt;
*Pico&lt;br /&gt;
Pico, short for &#039;Pine composer&#039;, is text editor for UNIX based computer based systems. The good thing about learning Pico, is that it&#039;s simple and easy to learn. The downside to pico is that it doesn&#039;t have as many features as for example the &#039;vim editor&#039; which we&#039;ll be learning later. Also, pico has a clone text editor called &#039;nano&#039; which was created as part of the GNU project due to unclear redistribution terms. So if you&#039;ve learned &#039;pico&#039; then you&#039;ve also learned nano. If you&#039;re interested in learning pico, a good start would be to watch this video [https://www.youtube.com/watch?v=o5IY1dMUpc0 Pico text editor introduction]. &lt;br /&gt;
&lt;br /&gt;
[http://picocms.org/download/ pico download]&lt;br /&gt;
&lt;br /&gt;
*Emacs&lt;br /&gt;
Emacs was initially released in 1976, and has since undergone many tweeks and updates. Among programmers, there exists a something called the &#039;Editor war&#039;, which is like a rivalry between &#039;emacs&#039; and &#039;vim&#039; [https://en.wikipedia.org/wiki/Editor_war Editor war]. It&#039;s, however, considerably more difficult to learn &#039;emacs&#039; compared to &#039;vim&#039;. To get you started with emacs, you should have no trouble finding various tutorials on youtube. &lt;br /&gt;
&lt;br /&gt;
To install emacs, it&#039;s best to use UNIX commands &#039;&#039;&#039;sudo&#039;&#039;&#039; and &#039;&#039;&#039;apt&#039;&#039;&#039; to ensure that it&#039;s installed properly. Here&#039;s what you would type in your terminal, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;sudo apt -y install&#039;&#039;&#039; emacs  &lt;br /&gt;
&lt;br /&gt;
== Sublime 3 ==&lt;br /&gt;
&lt;br /&gt;
=== Windows === &lt;br /&gt;
Sublime is a pretty cool text editor with some nice features, especially for programming purposes. There are two good ways of setting up Sublime 3 in a Unix terminal on a Windows computer. One way is to use a program called &#039;&#039;Xming&#039;&#039; coupled with the use of the Unix commands &#039;&#039;&#039;apt&#039;&#039;&#039; and &#039;&#039;&#039;sudo&#039;&#039;&#039;. But as we haven&#039;t covered these commands yet (they will be presented in the section &#039;&#039;&#039;Advanced Packaging tools&#039;&#039;&#039;), we won&#039;t be using this method. &lt;br /&gt;
&lt;br /&gt;
For the other method, start off by downloading the windows version of Sublime text by following this link [https://www.sublimetext.com/3 Sublime download link]. When installing Sublime 3, make sure you know where you&#039;re saving it (by default, windows will save it in &#039;&#039;\Program Files&#039;&#039;). Once you&#039;ve successfully installed Sublime 3  start your Ubuntu WSL terminal.&lt;br /&gt;
From your terminal, you can directly access sublime text by specifying the filepath to &#039;subl.exe&#039;,&lt;br /&gt;
&lt;br /&gt;
 Prompt$ /mnt/c/Program\ Files/Sublime\ Text\ 3/subl.exe &amp;lt;FILE&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will open &amp;lt;FILE&amp;gt; with the sublime text editor. The &#039;\ &#039; are how spaces are written in a command line. This can be confusing so spaces are often avoided in filenames by replacing spaces with &#039;_&#039;. We can avoid having to write such a long filepath everytime we use sublime by using the command &#039;&#039;&#039;alias&#039;&#039;&#039;,&lt;br /&gt;
&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;alias&#039;&#039;&#039; subl=&#039;/mnt/c/Program\ Files/Sublime\ Text\ 3/subl.exe&#039; &lt;br /&gt;
which creates an alias for what&#039;s specified after &#039;=&#039;. This way, typing &#039;&#039;&#039;subl&#039;&#039;&#039;&amp;lt;file&amp;gt;, will open the file in sublime text editor. This alias, however, is not permanent and the next time you start your terminal you&#039;ll need to write it again. In order to make it a permanent alias we have to edit in what&#039;s called the .bashrc file, which is located in your home directory, &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;cd&#039;&#039;&#039; ~ &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;echo&#039;&#039;&#039; &#039;alias subl=&#039;/mnt/c/Program\ Files/Sublime\ Text\ 3/subl.exe&#039;&#039; &amp;gt;&amp;gt; .bashrc &lt;br /&gt;
Now everytime you start bash the alias command will be run. In figure 3.1, we show the commands that need to be executed in the terminal.&lt;br /&gt;
[[File:Setting up Sublime3.png|frame|none|&#039;&#039;&#039;Figure 3.1 Setting up Sublime 3:&#039;&#039;&#039; The directory is changed to the home directory by typing &#039;&#039;&#039;cd&#039;&#039;&#039; ~, and all files within the home directory are listed using the command &#039;&#039;&#039;ls -a&#039;&#039;&#039;. The alias is appended to .bashrc using &#039;&#039;&#039;echo&#039;&#039;&#039;, and afterwards .bashrc is executed using the command &#039;&#039;&#039;source&#039;&#039;&#039;]]&lt;br /&gt;
=== Mac === &lt;br /&gt;
For Mac computers, the installation method for Sublime 3 is similar to the Windows installation. You can download the mac version of Sublime 3 by following the link, [https://www.sublimetext.com/3 Sublime download link].&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/unix/index.php?title=File:Tee_example1.png&amp;diff=26</id>
		<title>File:Tee example1.png</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/unix/index.php?title=File:Tee_example1.png&amp;diff=26"/>
		<updated>2024-03-20T12:01:23Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/unix/index.php?title=File:Tee_command.png&amp;diff=25</id>
		<title>File:Tee command.png</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/unix/index.php?title=File:Tee_command.png&amp;diff=25"/>
		<updated>2024-03-20T12:01:02Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/unix/index.php?title=File:Echo%26cat.png&amp;diff=24</id>
		<title>File:Echo&amp;cat.png</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/unix/index.php?title=File:Echo%26cat.png&amp;diff=24"/>
		<updated>2024-03-20T12:00:37Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/unix/index.php?title=File:Operator_Example2.png&amp;diff=23</id>
		<title>File:Operator Example2.png</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/unix/index.php?title=File:Operator_Example2.png&amp;diff=23"/>
		<updated>2024-03-20T12:00:16Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/unix/index.php?title=File:Standard_streams.png&amp;diff=22</id>
		<title>File:Standard streams.png</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/unix/index.php?title=File:Standard_streams.png&amp;diff=22"/>
		<updated>2024-03-20T11:59:23Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/unix/index.php?title=File:Standard_streams_wcexample2.png&amp;diff=21</id>
		<title>File:Standard streams wcexample2.png</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/unix/index.php?title=File:Standard_streams_wcexample2.png&amp;diff=21"/>
		<updated>2024-03-20T11:58:54Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/unix/index.php?title=Standard_streams_and_working_with_files&amp;diff=20</id>
		<title>Standard streams and working with files</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/unix/index.php?title=Standard_streams_and_working_with_files&amp;diff=20"/>
		<updated>2024-03-20T11:57:44Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Datafiles */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
In the last section we learned how to make directories and move around in the file system, but we didn&#039;t actually learn how to work with files. So in this section we&#039;ll be doing just that.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Many of the commands you&#039;ll be learning in this course can receive data from the standard input and  write to something called the standard output, so later in this section we&#039;ll introduce the concept of standard streams. Lastly we&#039;ll look at how we can change the direction of the standard output and standard input with re-directional operators and pipelines. &lt;br /&gt;
&lt;br /&gt;
== Introduction to commands == &lt;br /&gt;
Here we list Unix commands and their main function but it&#039;s important to keep in mind that Unix commands are versatile and it is possible to complete the same tasks using different commands. &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Unix Command&lt;br /&gt;
!Acronym translation &lt;br /&gt;
!Description&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;touch&#039;&#039;&#039; [OPTION] &amp;lt;FILE&amp;gt;&lt;br /&gt;
|&amp;lt;nowiki&amp;gt;-&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|Touches a file. If the file doesn&#039;t exist already it will create a file with the specified name. If it already exists it will update the date of the file &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;mv&#039;&#039;&#039; [OPTION] &amp;lt;FILE&amp;gt; &amp;lt;destination directory or another filename&amp;gt;&lt;br /&gt;
|Move&lt;br /&gt;
|Moves a file to a specified directory. It can also be used to rename files. &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;rm&#039;&#039;&#039; [OPTION] &amp;lt;FILE&amp;gt; &lt;br /&gt;
|Remove&lt;br /&gt;
|Removes specified file in current directory. This command can also be used to remove non-empty directories. &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;cp&#039;&#039;&#039; [OPTION] &amp;lt;FILE&amp;gt; &amp;lt;destination directory or another file&amp;gt;&lt;br /&gt;
|Copy&lt;br /&gt;
|Works a lot like mv, but moves a copy of the file instead. Can also be used copy the content of one file to another file.  &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;cat&#039;&#039;&#039; [OPTION] &amp;lt;FILE&amp;gt;&lt;br /&gt;
|Concatenate &lt;br /&gt;
|Concatenates files and displays it in standard output. If used on one file, the content of that file is displayed in the command line interface. &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;head&#039;&#039;&#039; [OPTION] &amp;lt;FILE&amp;gt; &lt;br /&gt;
|&amp;lt;nowiki&amp;gt;-&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|Outputs the first part of a file&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;tail&#039;&#039;&#039; [OPTION] &amp;lt;FILE&amp;gt;&lt;br /&gt;
|&amp;lt;nowiki&amp;gt;-&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|Outputs the last part of a file&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;less&#039;&#039;&#039; &amp;lt;FILE&amp;gt;&lt;br /&gt;
|&amp;lt;nowiki&amp;gt;-&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|Shows a screenfull of the file. This is a useful command for viewing big files as it loads at smalls segments at a time. q --&amp;gt; quit , space --&amp;gt; scroll forward one page , b --&amp;gt; scroll backward one page. Arrow keys can be used to scroll up and down one line at a time.     &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;wc&#039;&#039;&#039; [OPTION] &amp;lt;FILE&amp;gt; &lt;br /&gt;
|Word count&lt;br /&gt;
|Counts the lines and words in the file/files, but can also count other things based on the options you give it.   &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;paste&#039;&#039;&#039; [OPTION] &amp;lt;FILE&amp;gt;&lt;br /&gt;
|&amp;lt;nowiki&amp;gt;-&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|Merges lines from different files. &lt;br /&gt;
|- &lt;br /&gt;
|&#039;&#039;&#039;cut&#039;&#039;&#039; &amp;lt;nowiki&amp;gt;[OPTION]&amp;lt;/nowiki&amp;gt; &amp;lt;FILE&amp;gt;&lt;br /&gt;
|&amp;lt;nowiki&amp;gt;-&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|Removes different parts of a file depending on on what is specified in the option. &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;echo&#039;&#039;&#039; [OPTION] &amp;lt;STRING&amp;gt; &lt;br /&gt;
|&amp;lt;nowiki&amp;gt;-&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|Outputs the string to your command line interface. In computer language, a string is just a sequence of characters.&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;wget&#039;&#039;&#039; [OPTION] &amp;lt;URL&amp;gt;&lt;br /&gt;
|web get&lt;br /&gt;
|A non-interactive network downloader used to download files located at the URL. &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;curl&#039;&#039;&#039; [OPTION] &amp;lt;URL&amp;gt; &lt;br /&gt;
|client URL&lt;br /&gt;
|Similarly to &#039;&#039;&#039;wget&#039;&#039;&#039;, it is used to download files at the specified URL. This is an alternative MAC OS users, where &#039;&#039;&#039;wget&#039;&#039;&#039; doesn&#039;t work. &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;tee&#039;&#039;&#039; [OPTION] &amp;lt;FILE&amp;gt;&lt;br /&gt;
|It&#039;s named after the &#039;T-splitter&#039; used in plumbing. &lt;br /&gt;
|Splits output so that it can be outputted to both the terminal and a file. &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
As an introduction, you can watch this youtube video on the use of some of the commands, [https://www.youtube.com/watch?v=VgI4UKyL0Lc Unix Commands for working with files]. The video introduces some of the Unix commands for navigation that you learned in the last section but it also introduces the commands: &#039;&#039;&#039;touch&#039;&#039;&#039;, &#039;&#039;&#039;mv&#039;&#039;&#039; and &#039;&#039;&#039;cp&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
=== Datafiles ===&lt;br /&gt;
Below are downloadable links for this sections datafiles. You can download them by right-clicking and then choosing the option &#039;Download link&#039;.&amp;lt;br&amp;gt; &lt;br /&gt;
Datafile 1: [https://teaching.healthtech.dtu.dk/material/unix/Pseudomonas_Aeruginosa_16SrRNA.gb Pseudomonas Aeruginosa 16S rRNA Genebank file]&amp;lt;br&amp;gt;&lt;br /&gt;
Datafile 2: [https://teaching.healthtech.dtu.dk/material/unix/ex1.acc ex1.acc]&amp;lt;br&amp;gt;&lt;br /&gt;
Datafile 3: [https://teaching.healthtech.dtu.dk/material/unix/ex1.dat ex1.dat]&amp;lt;br&amp;gt;&lt;br /&gt;
You can also right click, copy the link address and type &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;wget&#039;&#039;&#039; &amp;lt;the link address you copied&amp;gt;&lt;br /&gt;
in your UNIX terminal. You might have trouble pasting the link into your terminal because the keyboard shortcut is not necessarily  &#039;&#039;&#039;Ctrl-V&#039;&#039;&#039;. On Ubuntu WSL, the shortcut for pasting is simply right-clicking and for copying it&#039;s &#039;&#039;&#039;Ctrl-Shift-C&#039;&#039;&#039;. On Mobaxterm it should be Shift-Ins or the middle mouse button (the one you&#039;d normally use for scrolling) if you have one of those. It might be set differently on your MobaXterm, however, and you can check this under Settings --&amp;gt; Keyboard shortcuts --&amp;gt; Paste in terminal. You can copy text in MobaXterm by left-clicking and marking the text you want copied.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;A little background on the files:&#039;&#039;&#039; Datafile 1 is a genebank file that contains information about the 16S rRNA DNA sequence of the pathogenic bacteria Pseudomonas aeruginosa. The DNA sequence of 16S rRNA is a highly conserved region in bacteria and is often used to identify bacteria. Datafile 2 contains 3 tab-separated columns of numerical data and datafile 3 contains 2 tab separated columns of accession numbers. One tab is equivalent to 5 regular space and accession numbers are unique identifier tags for DNA.&lt;br /&gt;
&lt;br /&gt;
=== Examples of how this sections Unix commands can be used ===&lt;br /&gt;
&lt;br /&gt;
All of the commands below are executed in the command line interface. For example, when using the &#039;&#039;&#039;wc&#039;&#039;&#039; command your terminal should look like &#039;&#039;&#039;figure 2.1&#039;&#039;&#039;. In &#039;&#039;&#039;figure 2.1&#039;&#039;&#039;, the command is executed in Windows linux subsystem (WSL) Ubuntu, so the colouring might be different on your computer. The syntax, however, is the same. &lt;br /&gt;
[[File:Standard streams wcexample2.png|none|frame|&#039;&#039;&#039;Figure 2.1 Using wc command in a Unix environment:&#039;&#039;&#039; The &#039;&#039;&#039;wc&#039;&#039;&#039; command is executed in Windows linux subsystem (WSL) Ubuntu, so it might look a little different if you&#039;re using a different Unix environment.]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;cat&#039;&#039;&#039;, short for concatenate, is often used to display file contents. &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;cat&#039;&#039;&#039; &amp;lt;FILE&amp;gt; &lt;br /&gt;
outputs the content of the file. You can also combine &#039;&#039;&#039;cat&#039;&#039;&#039; with options for different functionalities.  &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;cat -n&#039;&#039;&#039; &amp;lt;FILE&amp;gt;&lt;br /&gt;
outputs the line numbers along with the file content of the file. There are also other useful functionalities of &#039;&#039;&#039;cat&#039;&#039;&#039; but these require an understanding of &#039;&#039;redirectional operators&#039;&#039;, so we&#039;ll save them for later in this section.   &lt;br /&gt;
&lt;br /&gt;
If you&#039;re interested in the file content at the top or bottom of a file, you can use the commands &#039;&#039;&#039;head&#039;&#039;&#039; and &#039;&#039;&#039;tail&#039;&#039;&#039;.&amp;lt;br&amp;gt; &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;head -3&#039;&#039;&#039; &amp;lt;FILE&amp;gt; &lt;br /&gt;
outputs the first 3 lines of a file.&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;tail -3&#039;&#039;&#039; &amp;lt;FILE&amp;gt; &lt;br /&gt;
outputs the last 3 lines of a file. &lt;br /&gt;
&lt;br /&gt;
If you want to know the number of words, lines or characters in a file you can use the &#039;&#039;&#039;wc&#039;&#039;&#039; command.&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;wc&#039;&#039;&#039; &amp;lt;FILE&amp;gt; &lt;br /&gt;
outputs the number of characters, lines, and words. This output is always followed by the filename. You can also use options for a more specific functionality. &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;wc -l&#039;&#039;&#039; &amp;lt;FILE&amp;gt; &lt;br /&gt;
outputs the number of lines in a file.&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;wc -m&#039;&#039;&#039; &amp;lt;FILE&amp;gt; &lt;br /&gt;
outputs the characters in a file. &lt;br /&gt;
&lt;br /&gt;
Keep in mind that commands &#039;&#039;&#039;cat&#039;&#039;&#039;, &#039;&#039;&#039;head&#039;&#039;&#039;, &#039;&#039;&#039;tail&#039;&#039;&#039; and &#039;&#039;&#039;wc&#039;&#039;&#039; can all take multiple &amp;lt;FILE&amp;gt; arguments as shown in &#039;&#039;&#039;figure 2.1&#039;&#039;&#039;.  &lt;br /&gt;
&lt;br /&gt;
You can use &#039;&#039;&#039;echo&#039;&#039;&#039; to write stuff in the command line interface. &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;echo&#039;&#039;&#039; &amp;lt;Whavever you want outputted to the command line interface&amp;gt; &lt;br /&gt;
outputs just about anything to the command line interface.&lt;br /&gt;
&lt;br /&gt;
The introductory video should have given you a basic idea of how the commands &#039;&#039;&#039;mv&#039;&#039;&#039;, &#039;&#039;&#039;cp&#039;&#039;&#039; and &#039;&#039;&#039;rm&#039;&#039;&#039;, but there are some extra tricks that are good to know. &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;mv&#039;&#039;&#039; file1 /filepath/file2 &lt;br /&gt;
will move file1 to file2 location, and rename file1 as file2&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;mv -t&#039;&#039;&#039; &amp;lt;DIRECTORY&amp;gt; file1..file99 &lt;br /&gt;
will move any number of files to a new directory. The &#039;&#039;&#039;cp -t&#039;&#039;&#039; command works in the same way.&lt;br /&gt;
&lt;br /&gt;
== Exercise 1: Working with datafiles == &lt;br /&gt;
# Download the 3 datafiles if you haven&#039;t already. &lt;br /&gt;
# Create 3 new files. You can call them whatever you like. &lt;br /&gt;
# Create two directories, called test and data.&lt;br /&gt;
# Delete two of the files you created and move the remaining file along with the data files to the test directory. &lt;br /&gt;
# Move all the files from the test directory to the data directory. Delete the test directory. &lt;br /&gt;
# Rename the file you created to mydatafile.gb. &lt;br /&gt;
# Copy the content of datafile 1 to mydatafile.gb and check that they&#039;re identical. &lt;br /&gt;
# Display the content of datafile 1, datafile 2 and datafile 3.&lt;br /&gt;
# Count the total number of bytes in the datafiles. (&#039;&#039;&#039;Hint:&#039;&#039;&#039; Check out the different command line options for &#039;&#039;&#039;wc&#039;&#039;&#039;). &lt;br /&gt;
&lt;br /&gt;
== Standard Streams ==&lt;br /&gt;
[[File:Standard streams.png|right|frame|&#039;&#039;&#039;Figure 2.2: Standard Streams:&#039;&#039;&#039; This figure illustrates the concept of standard streams. You can think of the green box as the interface that you can interact with. This is what we called the command line interface in the previous section. Recall that there are 2 types of user interfaces; command line interface (CLI) and GUI (graphical user interface). The yellow box represents the process where &#039;&#039;&#039;cat&#039;&#039;&#039; is translated back and forth from the hardware of your computer. The shell (the command line interpreter) and kernel oversee this process. If the process was successful, the resulting output is what&#039;s called the standard output (stdout). Oppositely, if the command wasn&#039;t successful the output will be the standard error (stderror). The standard input often originates from the keyboard (as it does when you type &#039;&#039;&#039;cat&#039;&#039;&#039; in your command line) which is why it&#039;s shown in the figure.]]&lt;br /&gt;
&lt;br /&gt;
Now that we have a practical idea of this sections Unix commands, let&#039;s discuss the concept of &#039;&#039;standard streams&#039;&#039;. This will give you an idea to what exactly is going on when these commands are executed from the command line.&amp;lt;br&amp;gt;&lt;br /&gt;
Standard streams are streams of data that travel from where a program was executed, to the places where the program is processed and then back again. It&#039;s important emphasize, that there are many streams of data in your computer, but the standard streams are the ones that the user has the most control over. There are 3 type of &#039;&#039;standard streams&#039;&#039;; &#039;&#039;standard input (stdin)&#039;&#039;, &#039;&#039;standard output (stdout)&#039;&#039; and &#039;&#039;standard error (stderror)&#039;&#039;. We&#039;ll go through what each term means by using the command &#039;&#039;&#039;cat&#039;&#039;&#039; as an example.&amp;lt;br /&amp;gt;   &lt;br /&gt;
&lt;br /&gt;
Use the Unix command &#039;&#039;&#039;cat&#039;&#039;&#039; by typing in &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;cat&#039;&#039;&#039;&lt;br /&gt;
in the terminal. This will prompt you, the user, to give &#039;&#039;&#039;cat&#039;&#039;&#039; some input in the form stdin directly from your keyboard. Simply type something and press &#039;ENTER&#039;. To exit the process, press &#039;&#039;&#039;Ctrl&#039;&#039;&#039; and &#039;&#039;&#039;d&#039;&#039;&#039; simultaneously. The command &#039;&#039;&#039;cat&#039;&#039;&#039; will then process the stdin that you&#039;ve given it, and output it as what&#039;s called the &#039;&#039;standard output (stdout)&#039;&#039;. In this case stdout is just whatever you typed, and it is by default connected to the terminal, which is why it appears there. If the process wasn&#039;t successful, a &#039;&#039;standard error (stderror)&#039;&#039; message will be outputted to the terminal instead. Depending on the error you made, different error messages can appear. If you, for example, type in &#039;&#039;&#039;&#039;eccho&#039;&#039;&#039; Hello&#039; the stderror might return the error message &#039;bash: echho: command not found&#039;. The stderror is also connected to the terminal by default. Sometimes, nothing is outputted by the stdout and this is because some commands don&#039;t have a stdout. You&#039;ve already experienced this in the last section with commands like mkdir, rmdir, rm, cd and so on. &lt;br /&gt;
&lt;br /&gt;
When supplying &#039;&#039;&#039;cat&#039;&#039;&#039; with a file by typing,&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;cat&#039;&#039;&#039; &amp;lt;FILE&amp;gt; &lt;br /&gt;
in your command line, it will output the file contents as stdout. It is, however, important to understand that &amp;lt;FILE&amp;gt; is not being fed as stdin to &#039;&#039;&#039;cat&#039;&#039;&#039;. When you type a command on your command line and the command file is present on your system (you can find most of these files by going in the directory, &#039;&#039;&#039;/bin&#039;&#039;&#039;), all separated words, spaces and tabs that are present on the command line, will be passed to this file.  It&#039;s definitely a stream of data, but it&#039;s not the stdin.          &lt;br /&gt;
       &lt;br /&gt;
The stdin is connected to your keyboard, and stdout or stderror outputs are directed to the terminal by default.  We can, however, take control of these outputs by using redirectional operators, pipelines and the command &#039;&#039;&#039;tee&#039;&#039;&#039;.  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Supplementary material on standard output and standard input&#039;&#039;&#039;&amp;lt;br&amp;gt; &lt;br /&gt;
[http://www.linfo.org/standard_output.html Standard output]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.linfo.org/standard_input.html Standard input]&lt;br /&gt;
&lt;br /&gt;
==  Re-directional operators and pipelines ==&lt;br /&gt;
Operators are symbols which behave like functions within the Unix OS. The easiest to understand might be &#039;&#039;arithmetic operators&#039;&#039;, which use symbols like &#039;&#039;&#039;+&#039;&#039;&#039; for addition, &#039;&#039;&#039;-&#039;&#039;&#039; for subtraction, &#039;&#039;&#039;=&#039;&#039;&#039; for assigning values to variables, and so on. In this section we&#039;ll be learning redirectional operators. &lt;br /&gt;
=== Stdout redirectional operators, &amp;gt; and &amp;gt;&amp;gt; ===&lt;br /&gt;
&#039;&#039;&#039;&amp;gt;&#039;&#039;&#039; operator is used to redirect stdout and stderror. Here&#039;s, one way of using it:&amp;lt;br /&amp;gt;&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;cat&#039;&#039;&#039; file1 &#039;&#039;&#039;&amp;gt;&#039;&#039;&#039; file2&amp;lt;br /&amp;gt;&lt;br /&gt;
This will redirect stdout of &#039;&#039;&#039;cat&#039;&#039;&#039; file1 to file2, which is the same as redirecting the file contents of file1 to file2.    &lt;br /&gt;
An important feature of &#039;&#039;&#039;&amp;gt;&#039;&#039;&#039; is that it overwrites the content whereto its directed with the output that it receives. So in this case, the file content of &amp;lt;file2&amp;gt; will be overwritten with the file content of file1. This means you have to be careful as to not overwrite your work when using it. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;gt;&amp;gt;&#039;&#039;&#039; operator is also used to redirect stdout and stderror in the same way as &#039;&#039;&#039;&amp;gt;&#039;&#039;&#039;, but will append output to a file instead of overwriting it. For example,&amp;lt;br /&amp;gt; &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;cat&#039;&#039;&#039; file1 &#039;&#039;&#039;&amp;gt;&amp;gt;&#039;&#039;&#039; file2&amp;lt;br /&amp;gt;&lt;br /&gt;
would append the file content of file1 to file2. &lt;br /&gt;
&lt;br /&gt;
Here&#039;s how the use of these operators would look in a Unix terminal.[[File:Operator Example2.png|none|frame|&#039;&#039;&#039;Figure 2.3 Redirectional Operators:&#039;&#039;&#039; Here we use the Unix command &#039;&#039;&#039;echo&#039;&#039;&#039; which simply outputs whatever text you input in the command line. In the example, this output either appends or replaces the file content of Operator_Example.txt]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;cat&#039;&#039;&#039; can be used in a similar fashion as &#039;&#039;&#039;echo&#039;&#039;&#039; &amp;lt;STRING&amp;gt; &#039;&#039;&#039;&amp;gt;&#039;&#039;&#039; &amp;lt;FILE&amp;gt;, to add text to files. &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;cat&#039;&#039;&#039; &#039;&#039;&#039;&amp;gt;&#039;&#039;&#039; &amp;lt;FILE&amp;gt; &lt;br /&gt;
will ask the user for stdin which can be outputted to &amp;lt;FILE&amp;gt;. This is because the stdin is connected to the keyboard by default. To exit, simply hold the &#039;&#039;&#039;Ctrl&#039;&#039;&#039; key while pressing &#039;&#039;&#039;d&#039;&#039;&#039;. After entering your text and before exiting, it&#039;s a good idea to type enter or else the command line will look a bit weird. Basically, the command line and the text you just entered will be on the same line, which you might find confusing. This application works for the &#039;&#039;&#039;&amp;gt;&amp;gt;&#039;&#039;&#039; operator as well.   &lt;br /&gt;
[[File:Echo&amp;amp;cat.png|none|frame|&#039;&#039;&#039;Figure 2.4 Using cat or echo to add text to files&#039;&#039;&#039;]]&lt;br /&gt;
=== &amp;lt; operator ===&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;&#039;&#039;&#039; is the redirectional operator for the standard input and it is used to redirect stdin to commands. This is useful for commands that require additional input from the user and we&#039;ll take a look at such commands in later sections. To give an example, when you&#039;re downloading and installing packages, you&#039;ll be prompted for stdin, to confirm if it&#039;s okay that the package uses that said amount of space on your device. In such a case, you need to type &#039;y&#039; for yes, and &#039;n&#039; for no. If you&#039;re doing many time-consuming package installments, it can be quite annoying to have to be around just to press &#039;y&#039; once in a while. Therefore, it is super-handy that you can use the &#039;&#039;&#039;&amp;lt;&#039;&#039;&#039; operator to direct the stdin that you need. This can easily be done with &#039;&#039;&#039;echo&#039;&#039;&#039;,&lt;br /&gt;
&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;echo&#039;&#039;&#039; &#039;y&#039; &amp;lt; &#039;&#039;&#039;apt install&#039;&#039;&#039; &amp;lt;package&amp;gt;             &lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;apt&#039;&#039; command is short for &#039;Advanced Package tool&#039; and is the standard packaging tool for Unix. We&#039;ll learn more about this in the section &#039;File compression and advanced packaging tools&#039;, so don&#039;t worry about it now. &lt;br /&gt;
&lt;br /&gt;
=== Pipelines ===&lt;br /&gt;
Making pipelines or &#039;pipelining&#039; as it is sometimes called, is similar to the concept of redirectional operators. Pipelines are used to redirect the stdout of one Unix command as the stdin to another Unix command. A good example of this is:&lt;br /&gt;
&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;cat&#039;&#039;&#039; &amp;lt;some big file&amp;gt; &#039;&#039;&#039;| less&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
will feed the stdout of &#039;&#039;&#039;cat&#039;&#039;&#039; &amp;lt;some big file&amp;gt; as stdin to &#039;&#039;&#039;less&#039;&#039;&#039;. If you just write &#039;&#039;&#039;cat&#039;&#039;&#039;, all of the contents of the file will rapidly be displayed on your screen and it can be a real pain to scroll all the way to the top in order to read the text. But by piping &#039;&#039;&#039;cat&#039;&#039;&#039; with &#039;&#039;&#039;less&#039;&#039;&#039;, you can scroll through the file small segments at a time (see the Unix command table or google &#039;&#039;&#039;man less&#039;&#039;&#039; for instructions on how to scroll through the file). &lt;br /&gt;
&lt;br /&gt;
As mentioned earlier, not all commands have a stdin. An example of this is, &#039;&#039;&#039;echo&#039;&#039;&#039;, which can only output its command line argument &amp;lt;STRING&amp;gt;. If you tried to pipe stdin &#039;&#039;&#039;echo&#039;&#039;&#039; with stdout from another command, it wouldn&#039;t work.  &lt;br /&gt;
 Prompt$ cat &amp;lt;FILE&amp;gt; |&#039;&#039;&#039;echo&#039;&#039;&#039; &lt;br /&gt;
output a blank line. &lt;br /&gt;
&lt;br /&gt;
=== Some Examples: Simple Piping === &lt;br /&gt;
These examples aren&#039;t necessarily useful, but just to give you a better idea of what pipelines are and how they can be constructed. Try them out yourself on this sections datafiles.  &lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;head -5&#039;&#039;&#039; &amp;lt;datafile&amp;gt; &#039;&#039;&#039;| tail -2 &#039;&#039;&#039;&lt;br /&gt;
The first 5 lines are extracted from datafile and fed to &#039;&#039;&#039;tail -2&#039;&#039;&#039;, which extracts the last 2 lines and outputs to the command line interface.&amp;lt;br /&amp;gt;&lt;br /&gt;
 &#039;&#039;&#039;tail -10&#039;&#039;&#039; &amp;lt;datafile&amp;gt; &#039;&#039;&#039;| wc -c &amp;gt; 10_tail_chars.txt &lt;br /&gt;
The last 10 lines are extracted from datafile and fed to &#039;&#039;&#039;wc -c&#039;&#039;&#039;, which counts the characters. These are redirected and saved to the  10_tail_chars.txt.&amp;lt;br /&amp;gt; &lt;br /&gt;
 &#039;&#039;&#039;head -5&#039;&#039;&#039; &amp;lt;datafile&amp;gt; &#039;&#039;&#039;| cut -f 2-4 &amp;gt;&amp;gt; columns2to4.txt&lt;br /&gt;
The first 5 lines are extracted from datafile and fed to &#039;&#039;&#039;cut -f 2-4&#039;&#039;&#039;, which extracts the columns 2 to 4. The columns 2 to 4 are then appended to columuns2to4.txt. If you wanted to cut out only columns 2 and 4, you could instead write &#039;&#039;&#039;cut -f 2,4&#039;&#039;&#039;. &lt;br /&gt;
&lt;br /&gt;
=== tee command === &lt;br /&gt;
The function of the &#039;&#039;&#039;tee&#039;&#039;&#039; command is to split stdout into a file. The command is named after the T-splitter used in plumbing and the T-shape that is illustrated in &#039;&#039;&#039;figure 2.5&#039;&#039;&#039;. &lt;br /&gt;
&lt;br /&gt;
[[File:Tee command.png|frame|none|&#039;&#039;&#039;Figure 2.5 Tee command:]] &lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;tee&#039;&#039;&#039; command is useful if you&#039;re making a long pipeline, and you want to save intermediary results into files. But it&#039;s actually just a general good practice to use if you&#039;re making long pipelines. This way, if something is wrong in the final output, you can check where it wrong by looking at your intermediary files. &lt;br /&gt;
&lt;br /&gt;
[[File:Tee example1.png|frame|none|&#039;&#039;&#039;Figure 2.6 Tee example:&#039;&#039;&#039; A file called header_file.gb is made using the command &#039;&#039;&#039;&#039;touch&#039;&#039;&#039; and then pipeline is constructed. When the pipeline is executed from the command line, the header of the genebank file is saved to a file, and the number of bytes is outputted to the terminal. The contents of header_file.gb is then displayed with &#039;&#039;&#039;cat&#039;&#039;&#039;.]]&lt;br /&gt;
&lt;br /&gt;
This command has a couple of command options which you can check out with the &#039;&#039;&#039;man&#039;&#039;&#039; command. One of the more useful command options is the &#039;&#039;&#039;a&#039;&#039;&#039; &lt;br /&gt;
option, short for append,   &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;tee -a&#039;&#039;&#039; &amp;lt;FILE&amp;gt; &lt;br /&gt;
will append to the file instead. In a scenario, where you want to save multiple intermediary outputs in the same file this command is useful. &lt;br /&gt;
== Exercise 2: Re-directional operators and Pipelines  == &lt;br /&gt;
# Merge the lines of datafiles 2 &amp;amp; 3 and save them to mergefile.dat. Try displaying its content and make sure that accession numbers are on the left and the data on the right. It doesn&#039;t matter if files are of equal length, if there are no more lines in one file, blank lines will simply be added instead. &lt;br /&gt;
# Take the first 5 lines of mergefile.dat, cut out the first and third column and save it as columns1and3.dat. &lt;br /&gt;
# Count the number of characters in ALL of the files and append the results to a file called charsinfiles.dat.&lt;br /&gt;
# Make a pipeline that saves the bottom part of datafile1 in extracted_data.gb and the number of bytes in another bytefile.dat.&lt;br /&gt;
# Make a pipeline that saves the header of datafile1, appends it to extracted_data.gb and then appends the number of bytes to bytefile.dat.   &lt;br /&gt;
== Exercise 3: Moving and removing files across the file system ==&lt;br /&gt;
This exercise is a repetition of what you learned in the last section about navigating the file system combined with the commands you learned in this section. &lt;br /&gt;
[[File:Directory Branch.png|frame|&#039;&#039;&#039;Figure 2.6 Ex3 Branch of directories&#039;&#039;&#039;]]&lt;br /&gt;
# Make a branch of directories like the one shown in &#039;&#039;&#039;figure 2.7&#039;&#039;&#039;.  &lt;br /&gt;
# Move datafiles 1,2 and 3 to directory AB. &lt;br /&gt;
# Make a copy of datafile 1 in A5 called datafile_copy1, a copy of datafile 2 in A7 called datafile_copy2 and a copy of datafile 3 in B7 called datafile_copy3. &lt;br /&gt;
# Move datafile_copy1 and datafile_copy2 back to AB. You should do this without making A5 and A7 your current working directory (&#039;&#039;&#039;Hint 1 &#039;&#039;&#039;)&lt;br /&gt;
# Make two files in B7 called extra_copy1 and extracopy2.    &lt;br /&gt;
# Move datafile_copy3, extra_copy1 and extra_copy2 to AB. &lt;br /&gt;
# Rename extra_copy2 as extra_copy1.&lt;br /&gt;
# Remove datafile_copy1, datafile_copy2, datafile_copy3 and extra_copy1.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Hint 1:&#039;&#039;&#039; You can move files in other directories than the one you&#039;re in by specifying an absolute path.&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/unix/index.php?title=Standard_streams_and_working_with_files&amp;diff=19</id>
		<title>Standard streams and working with files</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/unix/index.php?title=Standard_streams_and_working_with_files&amp;diff=19"/>
		<updated>2024-03-20T11:56:18Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: Created page with &amp;quot;__NOTOC__ In the last section we learned how to make directories and move around in the file system, but we didn&amp;#039;t actually learn how to work with files. So in this section we&amp;#039;ll be doing just that.&amp;lt;br&amp;gt;  Many of the commands you&amp;#039;ll be learning in this course can receive data from the standard input and  write to something called the standard output, so later in this section we&amp;#039;ll introduce the concept of standard streams. Lastly we&amp;#039;ll look at how we can change the direct...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
In the last section we learned how to make directories and move around in the file system, but we didn&#039;t actually learn how to work with files. So in this section we&#039;ll be doing just that.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Many of the commands you&#039;ll be learning in this course can receive data from the standard input and  write to something called the standard output, so later in this section we&#039;ll introduce the concept of standard streams. Lastly we&#039;ll look at how we can change the direction of the standard output and standard input with re-directional operators and pipelines. &lt;br /&gt;
&lt;br /&gt;
== Introduction to commands == &lt;br /&gt;
Here we list Unix commands and their main function but it&#039;s important to keep in mind that Unix commands are versatile and it is possible to complete the same tasks using different commands. &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Unix Command&lt;br /&gt;
!Acronym translation &lt;br /&gt;
!Description&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;touch&#039;&#039;&#039; [OPTION] &amp;lt;FILE&amp;gt;&lt;br /&gt;
|&amp;lt;nowiki&amp;gt;-&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|Touches a file. If the file doesn&#039;t exist already it will create a file with the specified name. If it already exists it will update the date of the file &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;mv&#039;&#039;&#039; [OPTION] &amp;lt;FILE&amp;gt; &amp;lt;destination directory or another filename&amp;gt;&lt;br /&gt;
|Move&lt;br /&gt;
|Moves a file to a specified directory. It can also be used to rename files. &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;rm&#039;&#039;&#039; [OPTION] &amp;lt;FILE&amp;gt; &lt;br /&gt;
|Remove&lt;br /&gt;
|Removes specified file in current directory. This command can also be used to remove non-empty directories. &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;cp&#039;&#039;&#039; [OPTION] &amp;lt;FILE&amp;gt; &amp;lt;destination directory or another file&amp;gt;&lt;br /&gt;
|Copy&lt;br /&gt;
|Works a lot like mv, but moves a copy of the file instead. Can also be used copy the content of one file to another file.  &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;cat&#039;&#039;&#039; [OPTION] &amp;lt;FILE&amp;gt;&lt;br /&gt;
|Concatenate &lt;br /&gt;
|Concatenates files and displays it in standard output. If used on one file, the content of that file is displayed in the command line interface. &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;head&#039;&#039;&#039; [OPTION] &amp;lt;FILE&amp;gt; &lt;br /&gt;
|&amp;lt;nowiki&amp;gt;-&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|Outputs the first part of a file&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;tail&#039;&#039;&#039; [OPTION] &amp;lt;FILE&amp;gt;&lt;br /&gt;
|&amp;lt;nowiki&amp;gt;-&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|Outputs the last part of a file&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;less&#039;&#039;&#039; &amp;lt;FILE&amp;gt;&lt;br /&gt;
|&amp;lt;nowiki&amp;gt;-&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|Shows a screenfull of the file. This is a useful command for viewing big files as it loads at smalls segments at a time. q --&amp;gt; quit , space --&amp;gt; scroll forward one page , b --&amp;gt; scroll backward one page. Arrow keys can be used to scroll up and down one line at a time.     &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;wc&#039;&#039;&#039; [OPTION] &amp;lt;FILE&amp;gt; &lt;br /&gt;
|Word count&lt;br /&gt;
|Counts the lines and words in the file/files, but can also count other things based on the options you give it.   &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;paste&#039;&#039;&#039; [OPTION] &amp;lt;FILE&amp;gt;&lt;br /&gt;
|&amp;lt;nowiki&amp;gt;-&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|Merges lines from different files. &lt;br /&gt;
|- &lt;br /&gt;
|&#039;&#039;&#039;cut&#039;&#039;&#039; &amp;lt;nowiki&amp;gt;[OPTION]&amp;lt;/nowiki&amp;gt; &amp;lt;FILE&amp;gt;&lt;br /&gt;
|&amp;lt;nowiki&amp;gt;-&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|Removes different parts of a file depending on on what is specified in the option. &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;echo&#039;&#039;&#039; [OPTION] &amp;lt;STRING&amp;gt; &lt;br /&gt;
|&amp;lt;nowiki&amp;gt;-&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|Outputs the string to your command line interface. In computer language, a string is just a sequence of characters.&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;wget&#039;&#039;&#039; [OPTION] &amp;lt;URL&amp;gt;&lt;br /&gt;
|web get&lt;br /&gt;
|A non-interactive network downloader used to download files located at the URL. &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;curl&#039;&#039;&#039; [OPTION] &amp;lt;URL&amp;gt; &lt;br /&gt;
|client URL&lt;br /&gt;
|Similarly to &#039;&#039;&#039;wget&#039;&#039;&#039;, it is used to download files at the specified URL. This is an alternative MAC OS users, where &#039;&#039;&#039;wget&#039;&#039;&#039; doesn&#039;t work. &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;tee&#039;&#039;&#039; [OPTION] &amp;lt;FILE&amp;gt;&lt;br /&gt;
|It&#039;s named after the &#039;T-splitter&#039; used in plumbing. &lt;br /&gt;
|Splits output so that it can be outputted to both the terminal and a file. &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
As an introduction, you can watch this youtube video on the use of some of the commands, [https://www.youtube.com/watch?v=VgI4UKyL0Lc Unix Commands for working with files]. The video introduces some of the Unix commands for navigation that you learned in the last section but it also introduces the commands: &#039;&#039;&#039;touch&#039;&#039;&#039;, &#039;&#039;&#039;mv&#039;&#039;&#039; and &#039;&#039;&#039;cp&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
=== Datafiles ===&lt;br /&gt;
Below are downloadable links for this sections datafiles. You can download them by right-clicking and then choosing the option &#039;Download link&#039;.&amp;lt;br&amp;gt; &lt;br /&gt;
Datafile 1: [http://teaching.bioinformatics.dtu.dk/material/unix/Pseudomonas_Aeruginosa_16SrRNA.gb Pseudomonas Aeruginosa 16S rRNA Genebank file]&amp;lt;br&amp;gt;&lt;br /&gt;
Datafile 2: [http://teaching.bioinformatics.dtu.dk/material/36610/ex1.acc ex1.acc]&amp;lt;br&amp;gt;&lt;br /&gt;
Datafile 3: [http://teaching.bioinformatics.dtu.dk/material/36610/ex1.dat ex1.dat]&amp;lt;br&amp;gt;&lt;br /&gt;
You can also right click, copy the link address and type &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;wget&#039;&#039;&#039; &amp;lt;the link address you copied&amp;gt;&lt;br /&gt;
in your UNIX terminal. You might have trouble pasting the link into your terminal because the keyboard shortcut is not necessarily  &#039;&#039;&#039;Ctrl-V&#039;&#039;&#039;. On Ubuntu WSL, the shortcut for pasting is simply right-clicking and for copying it&#039;s &#039;&#039;&#039;Ctrl-Shift-C&#039;&#039;&#039;. On Mobaxterm it should be Shift-Ins or the middle mouse button (the one you&#039;d normally use for scrolling) if you have one of those. It might be set differently on your MobaXterm, however, and you can check this under Settings --&amp;gt; Keyboard shortcuts --&amp;gt; Paste in terminal. You can copy text in MobaXterm by left-clicking and marking the text you want copied.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;A little background on the files:&#039;&#039;&#039; Datafile 1 is a genebank file that contains information about the 16S rRNA DNA sequence of the pathogenic bacteria Pseudomonas aeruginosa. The DNA sequence of 16S rRNA is a highly conserved region in bacteria and is often used to identify bacteria. Datafile 2 contains 3 tab-separated columns of numerical data and datafile 3 contains 2 tab separated columns of accession numbers. One tab is equivalent to 5 regular space and accession numbers are unique identifier tags for DNA.  &lt;br /&gt;
&lt;br /&gt;
=== Examples of how this sections Unix commands can be used ===&lt;br /&gt;
&lt;br /&gt;
All of the commands below are executed in the command line interface. For example, when using the &#039;&#039;&#039;wc&#039;&#039;&#039; command your terminal should look like &#039;&#039;&#039;figure 2.1&#039;&#039;&#039;. In &#039;&#039;&#039;figure 2.1&#039;&#039;&#039;, the command is executed in Windows linux subsystem (WSL) Ubuntu, so the colouring might be different on your computer. The syntax, however, is the same. &lt;br /&gt;
[[File:Standard streams wcexample2.png|none|frame|&#039;&#039;&#039;Figure 2.1 Using wc command in a Unix environment:&#039;&#039;&#039; The &#039;&#039;&#039;wc&#039;&#039;&#039; command is executed in Windows linux subsystem (WSL) Ubuntu, so it might look a little different if you&#039;re using a different Unix environment.]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;cat&#039;&#039;&#039;, short for concatenate, is often used to display file contents. &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;cat&#039;&#039;&#039; &amp;lt;FILE&amp;gt; &lt;br /&gt;
outputs the content of the file. You can also combine &#039;&#039;&#039;cat&#039;&#039;&#039; with options for different functionalities.  &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;cat -n&#039;&#039;&#039; &amp;lt;FILE&amp;gt;&lt;br /&gt;
outputs the line numbers along with the file content of the file. There are also other useful functionalities of &#039;&#039;&#039;cat&#039;&#039;&#039; but these require an understanding of &#039;&#039;redirectional operators&#039;&#039;, so we&#039;ll save them for later in this section.   &lt;br /&gt;
&lt;br /&gt;
If you&#039;re interested in the file content at the top or bottom of a file, you can use the commands &#039;&#039;&#039;head&#039;&#039;&#039; and &#039;&#039;&#039;tail&#039;&#039;&#039;.&amp;lt;br&amp;gt; &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;head -3&#039;&#039;&#039; &amp;lt;FILE&amp;gt; &lt;br /&gt;
outputs the first 3 lines of a file.&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;tail -3&#039;&#039;&#039; &amp;lt;FILE&amp;gt; &lt;br /&gt;
outputs the last 3 lines of a file. &lt;br /&gt;
&lt;br /&gt;
If you want to know the number of words, lines or characters in a file you can use the &#039;&#039;&#039;wc&#039;&#039;&#039; command.&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;wc&#039;&#039;&#039; &amp;lt;FILE&amp;gt; &lt;br /&gt;
outputs the number of characters, lines, and words. This output is always followed by the filename. You can also use options for a more specific functionality. &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;wc -l&#039;&#039;&#039; &amp;lt;FILE&amp;gt; &lt;br /&gt;
outputs the number of lines in a file.&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;wc -m&#039;&#039;&#039; &amp;lt;FILE&amp;gt; &lt;br /&gt;
outputs the characters in a file. &lt;br /&gt;
&lt;br /&gt;
Keep in mind that commands &#039;&#039;&#039;cat&#039;&#039;&#039;, &#039;&#039;&#039;head&#039;&#039;&#039;, &#039;&#039;&#039;tail&#039;&#039;&#039; and &#039;&#039;&#039;wc&#039;&#039;&#039; can all take multiple &amp;lt;FILE&amp;gt; arguments as shown in &#039;&#039;&#039;figure 2.1&#039;&#039;&#039;.  &lt;br /&gt;
&lt;br /&gt;
You can use &#039;&#039;&#039;echo&#039;&#039;&#039; to write stuff in the command line interface. &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;echo&#039;&#039;&#039; &amp;lt;Whavever you want outputted to the command line interface&amp;gt; &lt;br /&gt;
outputs just about anything to the command line interface.&lt;br /&gt;
&lt;br /&gt;
The introductory video should have given you a basic idea of how the commands &#039;&#039;&#039;mv&#039;&#039;&#039;, &#039;&#039;&#039;cp&#039;&#039;&#039; and &#039;&#039;&#039;rm&#039;&#039;&#039;, but there are some extra tricks that are good to know. &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;mv&#039;&#039;&#039; file1 /filepath/file2 &lt;br /&gt;
will move file1 to file2 location, and rename file1 as file2&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;mv -t&#039;&#039;&#039; &amp;lt;DIRECTORY&amp;gt; file1..file99 &lt;br /&gt;
will move any number of files to a new directory. The &#039;&#039;&#039;cp -t&#039;&#039;&#039; command works in the same way.&lt;br /&gt;
&lt;br /&gt;
== Exercise 1: Working with datafiles == &lt;br /&gt;
# Download the 3 datafiles if you haven&#039;t already. &lt;br /&gt;
# Create 3 new files. You can call them whatever you like. &lt;br /&gt;
# Create two directories, called test and data.&lt;br /&gt;
# Delete two of the files you created and move the remaining file along with the data files to the test directory. &lt;br /&gt;
# Move all the files from the test directory to the data directory. Delete the test directory. &lt;br /&gt;
# Rename the file you created to mydatafile.gb. &lt;br /&gt;
# Copy the content of datafile 1 to mydatafile.gb and check that they&#039;re identical. &lt;br /&gt;
# Display the content of datafile 1, datafile 2 and datafile 3.&lt;br /&gt;
# Count the total number of bytes in the datafiles. (&#039;&#039;&#039;Hint:&#039;&#039;&#039; Check out the different command line options for &#039;&#039;&#039;wc&#039;&#039;&#039;). &lt;br /&gt;
&lt;br /&gt;
== Standard Streams ==&lt;br /&gt;
[[File:Standard streams.png|right|frame|&#039;&#039;&#039;Figure 2.2: Standard Streams:&#039;&#039;&#039; This figure illustrates the concept of standard streams. You can think of the green box as the interface that you can interact with. This is what we called the command line interface in the previous section. Recall that there are 2 types of user interfaces; command line interface (CLI) and GUI (graphical user interface). The yellow box represents the process where &#039;&#039;&#039;cat&#039;&#039;&#039; is translated back and forth from the hardware of your computer. The shell (the command line interpreter) and kernel oversee this process. If the process was successful, the resulting output is what&#039;s called the standard output (stdout). Oppositely, if the command wasn&#039;t successful the output will be the standard error (stderror). The standard input often originates from the keyboard (as it does when you type &#039;&#039;&#039;cat&#039;&#039;&#039; in your command line) which is why it&#039;s shown in the figure.]]&lt;br /&gt;
&lt;br /&gt;
Now that we have a practical idea of this sections Unix commands, let&#039;s discuss the concept of &#039;&#039;standard streams&#039;&#039;. This will give you an idea to what exactly is going on when these commands are executed from the command line.&amp;lt;br&amp;gt;&lt;br /&gt;
Standard streams are streams of data that travel from where a program was executed, to the places where the program is processed and then back again. It&#039;s important emphasize, that there are many streams of data in your computer, but the standard streams are the ones that the user has the most control over. There are 3 type of &#039;&#039;standard streams&#039;&#039;; &#039;&#039;standard input (stdin)&#039;&#039;, &#039;&#039;standard output (stdout)&#039;&#039; and &#039;&#039;standard error (stderror)&#039;&#039;. We&#039;ll go through what each term means by using the command &#039;&#039;&#039;cat&#039;&#039;&#039; as an example.&amp;lt;br /&amp;gt;   &lt;br /&gt;
&lt;br /&gt;
Use the Unix command &#039;&#039;&#039;cat&#039;&#039;&#039; by typing in &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;cat&#039;&#039;&#039;&lt;br /&gt;
in the terminal. This will prompt you, the user, to give &#039;&#039;&#039;cat&#039;&#039;&#039; some input in the form stdin directly from your keyboard. Simply type something and press &#039;ENTER&#039;. To exit the process, press &#039;&#039;&#039;Ctrl&#039;&#039;&#039; and &#039;&#039;&#039;d&#039;&#039;&#039; simultaneously. The command &#039;&#039;&#039;cat&#039;&#039;&#039; will then process the stdin that you&#039;ve given it, and output it as what&#039;s called the &#039;&#039;standard output (stdout)&#039;&#039;. In this case stdout is just whatever you typed, and it is by default connected to the terminal, which is why it appears there. If the process wasn&#039;t successful, a &#039;&#039;standard error (stderror)&#039;&#039; message will be outputted to the terminal instead. Depending on the error you made, different error messages can appear. If you, for example, type in &#039;&#039;&#039;&#039;eccho&#039;&#039;&#039; Hello&#039; the stderror might return the error message &#039;bash: echho: command not found&#039;. The stderror is also connected to the terminal by default. Sometimes, nothing is outputted by the stdout and this is because some commands don&#039;t have a stdout. You&#039;ve already experienced this in the last section with commands like mkdir, rmdir, rm, cd and so on. &lt;br /&gt;
&lt;br /&gt;
When supplying &#039;&#039;&#039;cat&#039;&#039;&#039; with a file by typing,&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;cat&#039;&#039;&#039; &amp;lt;FILE&amp;gt; &lt;br /&gt;
in your command line, it will output the file contents as stdout. It is, however, important to understand that &amp;lt;FILE&amp;gt; is not being fed as stdin to &#039;&#039;&#039;cat&#039;&#039;&#039;. When you type a command on your command line and the command file is present on your system (you can find most of these files by going in the directory, &#039;&#039;&#039;/bin&#039;&#039;&#039;), all separated words, spaces and tabs that are present on the command line, will be passed to this file.  It&#039;s definitely a stream of data, but it&#039;s not the stdin.          &lt;br /&gt;
       &lt;br /&gt;
The stdin is connected to your keyboard, and stdout or stderror outputs are directed to the terminal by default.  We can, however, take control of these outputs by using redirectional operators, pipelines and the command &#039;&#039;&#039;tee&#039;&#039;&#039;.  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Supplementary material on standard output and standard input&#039;&#039;&#039;&amp;lt;br&amp;gt; &lt;br /&gt;
[http://www.linfo.org/standard_output.html Standard output]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.linfo.org/standard_input.html Standard input]&lt;br /&gt;
&lt;br /&gt;
==  Re-directional operators and pipelines ==&lt;br /&gt;
Operators are symbols which behave like functions within the Unix OS. The easiest to understand might be &#039;&#039;arithmetic operators&#039;&#039;, which use symbols like &#039;&#039;&#039;+&#039;&#039;&#039; for addition, &#039;&#039;&#039;-&#039;&#039;&#039; for subtraction, &#039;&#039;&#039;=&#039;&#039;&#039; for assigning values to variables, and so on. In this section we&#039;ll be learning redirectional operators. &lt;br /&gt;
=== Stdout redirectional operators, &amp;gt; and &amp;gt;&amp;gt; ===&lt;br /&gt;
&#039;&#039;&#039;&amp;gt;&#039;&#039;&#039; operator is used to redirect stdout and stderror. Here&#039;s, one way of using it:&amp;lt;br /&amp;gt;&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;cat&#039;&#039;&#039; file1 &#039;&#039;&#039;&amp;gt;&#039;&#039;&#039; file2&amp;lt;br /&amp;gt;&lt;br /&gt;
This will redirect stdout of &#039;&#039;&#039;cat&#039;&#039;&#039; file1 to file2, which is the same as redirecting the file contents of file1 to file2.    &lt;br /&gt;
An important feature of &#039;&#039;&#039;&amp;gt;&#039;&#039;&#039; is that it overwrites the content whereto its directed with the output that it receives. So in this case, the file content of &amp;lt;file2&amp;gt; will be overwritten with the file content of file1. This means you have to be careful as to not overwrite your work when using it. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;gt;&amp;gt;&#039;&#039;&#039; operator is also used to redirect stdout and stderror in the same way as &#039;&#039;&#039;&amp;gt;&#039;&#039;&#039;, but will append output to a file instead of overwriting it. For example,&amp;lt;br /&amp;gt; &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;cat&#039;&#039;&#039; file1 &#039;&#039;&#039;&amp;gt;&amp;gt;&#039;&#039;&#039; file2&amp;lt;br /&amp;gt;&lt;br /&gt;
would append the file content of file1 to file2. &lt;br /&gt;
&lt;br /&gt;
Here&#039;s how the use of these operators would look in a Unix terminal.[[File:Operator Example2.png|none|frame|&#039;&#039;&#039;Figure 2.3 Redirectional Operators:&#039;&#039;&#039; Here we use the Unix command &#039;&#039;&#039;echo&#039;&#039;&#039; which simply outputs whatever text you input in the command line. In the example, this output either appends or replaces the file content of Operator_Example.txt]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;cat&#039;&#039;&#039; can be used in a similar fashion as &#039;&#039;&#039;echo&#039;&#039;&#039; &amp;lt;STRING&amp;gt; &#039;&#039;&#039;&amp;gt;&#039;&#039;&#039; &amp;lt;FILE&amp;gt;, to add text to files. &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;cat&#039;&#039;&#039; &#039;&#039;&#039;&amp;gt;&#039;&#039;&#039; &amp;lt;FILE&amp;gt; &lt;br /&gt;
will ask the user for stdin which can be outputted to &amp;lt;FILE&amp;gt;. This is because the stdin is connected to the keyboard by default. To exit, simply hold the &#039;&#039;&#039;Ctrl&#039;&#039;&#039; key while pressing &#039;&#039;&#039;d&#039;&#039;&#039;. After entering your text and before exiting, it&#039;s a good idea to type enter or else the command line will look a bit weird. Basically, the command line and the text you just entered will be on the same line, which you might find confusing. This application works for the &#039;&#039;&#039;&amp;gt;&amp;gt;&#039;&#039;&#039; operator as well.   &lt;br /&gt;
[[File:Echo&amp;amp;cat.png|none|frame|&#039;&#039;&#039;Figure 2.4 Using cat or echo to add text to files&#039;&#039;&#039;]]&lt;br /&gt;
=== &amp;lt; operator ===&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;&#039;&#039;&#039; is the redirectional operator for the standard input and it is used to redirect stdin to commands. This is useful for commands that require additional input from the user and we&#039;ll take a look at such commands in later sections. To give an example, when you&#039;re downloading and installing packages, you&#039;ll be prompted for stdin, to confirm if it&#039;s okay that the package uses that said amount of space on your device. In such a case, you need to type &#039;y&#039; for yes, and &#039;n&#039; for no. If you&#039;re doing many time-consuming package installments, it can be quite annoying to have to be around just to press &#039;y&#039; once in a while. Therefore, it is super-handy that you can use the &#039;&#039;&#039;&amp;lt;&#039;&#039;&#039; operator to direct the stdin that you need. This can easily be done with &#039;&#039;&#039;echo&#039;&#039;&#039;,&lt;br /&gt;
&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;echo&#039;&#039;&#039; &#039;y&#039; &amp;lt; &#039;&#039;&#039;apt install&#039;&#039;&#039; &amp;lt;package&amp;gt;             &lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;apt&#039;&#039; command is short for &#039;Advanced Package tool&#039; and is the standard packaging tool for Unix. We&#039;ll learn more about this in the section &#039;File compression and advanced packaging tools&#039;, so don&#039;t worry about it now. &lt;br /&gt;
&lt;br /&gt;
=== Pipelines ===&lt;br /&gt;
Making pipelines or &#039;pipelining&#039; as it is sometimes called, is similar to the concept of redirectional operators. Pipelines are used to redirect the stdout of one Unix command as the stdin to another Unix command. A good example of this is:&lt;br /&gt;
&lt;br /&gt;
 Prompt$ &#039;&#039;&#039;cat&#039;&#039;&#039; &amp;lt;some big file&amp;gt; &#039;&#039;&#039;| less&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
will feed the stdout of &#039;&#039;&#039;cat&#039;&#039;&#039; &amp;lt;some big file&amp;gt; as stdin to &#039;&#039;&#039;less&#039;&#039;&#039;. If you just write &#039;&#039;&#039;cat&#039;&#039;&#039;, all of the contents of the file will rapidly be displayed on your screen and it can be a real pain to scroll all the way to the top in order to read the text. But by piping &#039;&#039;&#039;cat&#039;&#039;&#039; with &#039;&#039;&#039;less&#039;&#039;&#039;, you can scroll through the file small segments at a time (see the Unix command table or google &#039;&#039;&#039;man less&#039;&#039;&#039; for instructions on how to scroll through the file). &lt;br /&gt;
&lt;br /&gt;
As mentioned earlier, not all commands have a stdin. An example of this is, &#039;&#039;&#039;echo&#039;&#039;&#039;, which can only output its command line argument &amp;lt;STRING&amp;gt;. If you tried to pipe stdin &#039;&#039;&#039;echo&#039;&#039;&#039; with stdout from another command, it wouldn&#039;t work.  &lt;br /&gt;
 Prompt$ cat &amp;lt;FILE&amp;gt; |&#039;&#039;&#039;echo&#039;&#039;&#039; &lt;br /&gt;
output a blank line. &lt;br /&gt;
&lt;br /&gt;
=== Some Examples: Simple Piping === &lt;br /&gt;
These examples aren&#039;t necessarily useful, but just to give you a better idea of what pipelines are and how they can be constructed. Try them out yourself on this sections datafiles.  &lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;head -5&#039;&#039;&#039; &amp;lt;datafile&amp;gt; &#039;&#039;&#039;| tail -2 &#039;&#039;&#039;&lt;br /&gt;
The first 5 lines are extracted from datafile and fed to &#039;&#039;&#039;tail -2&#039;&#039;&#039;, which extracts the last 2 lines and outputs to the command line interface.&amp;lt;br /&amp;gt;&lt;br /&gt;
 &#039;&#039;&#039;tail -10&#039;&#039;&#039; &amp;lt;datafile&amp;gt; &#039;&#039;&#039;| wc -c &amp;gt; 10_tail_chars.txt &lt;br /&gt;
The last 10 lines are extracted from datafile and fed to &#039;&#039;&#039;wc -c&#039;&#039;&#039;, which counts the characters. These are redirected and saved to the  10_tail_chars.txt.&amp;lt;br /&amp;gt; &lt;br /&gt;
 &#039;&#039;&#039;head -5&#039;&#039;&#039; &amp;lt;datafile&amp;gt; &#039;&#039;&#039;| cut -f 2-4 &amp;gt;&amp;gt; columns2to4.txt&lt;br /&gt;
The first 5 lines are extracted from datafile and fed to &#039;&#039;&#039;cut -f 2-4&#039;&#039;&#039;, which extracts the columns 2 to 4. The columns 2 to 4 are then appended to columuns2to4.txt. If you wanted to cut out only columns 2 and 4, you could instead write &#039;&#039;&#039;cut -f 2,4&#039;&#039;&#039;. &lt;br /&gt;
&lt;br /&gt;
=== tee command === &lt;br /&gt;
The function of the &#039;&#039;&#039;tee&#039;&#039;&#039; command is to split stdout into a file. The command is named after the T-splitter used in plumbing and the T-shape that is illustrated in &#039;&#039;&#039;figure 2.5&#039;&#039;&#039;. &lt;br /&gt;
&lt;br /&gt;
[[File:Tee command.png|frame|none|&#039;&#039;&#039;Figure 2.5 Tee command:]] &lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;tee&#039;&#039;&#039; command is useful if you&#039;re making a long pipeline, and you want to save intermediary results into files. But it&#039;s actually just a general good practice to use if you&#039;re making long pipelines. This way, if something is wrong in the final output, you can check where it wrong by looking at your intermediary files. &lt;br /&gt;
&lt;br /&gt;
[[File:Tee example1.png|frame|none|&#039;&#039;&#039;Figure 2.6 Tee example:&#039;&#039;&#039; A file called header_file.gb is made using the command &#039;&#039;&#039;&#039;touch&#039;&#039;&#039; and then pipeline is constructed. When the pipeline is executed from the command line, the header of the genebank file is saved to a file, and the number of bytes is outputted to the terminal. The contents of header_file.gb is then displayed with &#039;&#039;&#039;cat&#039;&#039;&#039;.]]&lt;br /&gt;
&lt;br /&gt;
This command has a couple of command options which you can check out with the &#039;&#039;&#039;man&#039;&#039;&#039; command. One of the more useful command options is the &#039;&#039;&#039;a&#039;&#039;&#039; &lt;br /&gt;
option, short for append,   &lt;br /&gt;
 Prompt$ &#039;&#039;&#039;tee -a&#039;&#039;&#039; &amp;lt;FILE&amp;gt; &lt;br /&gt;
will append to the file instead. In a scenario, where you want to save multiple intermediary outputs in the same file this command is useful. &lt;br /&gt;
== Exercise 2: Re-directional operators and Pipelines  == &lt;br /&gt;
# Merge the lines of datafiles 2 &amp;amp; 3 and save them to mergefile.dat. Try displaying its content and make sure that accession numbers are on the left and the data on the right. It doesn&#039;t matter if files are of equal length, if there are no more lines in one file, blank lines will simply be added instead. &lt;br /&gt;
# Take the first 5 lines of mergefile.dat, cut out the first and third column and save it as columns1and3.dat. &lt;br /&gt;
# Count the number of characters in ALL of the files and append the results to a file called charsinfiles.dat.&lt;br /&gt;
# Make a pipeline that saves the bottom part of datafile1 in extracted_data.gb and the number of bytes in another bytefile.dat.&lt;br /&gt;
# Make a pipeline that saves the header of datafile1, appends it to extracted_data.gb and then appends the number of bytes to bytefile.dat.   &lt;br /&gt;
== Exercise 3: Moving and removing files across the file system ==&lt;br /&gt;
This exercise is a repetition of what you learned in the last section about navigating the file system combined with the commands you learned in this section. &lt;br /&gt;
[[File:Directory Branch.png|frame|&#039;&#039;&#039;Figure 2.6 Ex3 Branch of directories&#039;&#039;&#039;]]&lt;br /&gt;
# Make a branch of directories like the one shown in &#039;&#039;&#039;figure 2.7&#039;&#039;&#039;.  &lt;br /&gt;
# Move datafiles 1,2 and 3 to directory AB. &lt;br /&gt;
# Make a copy of datafile 1 in A5 called datafile_copy1, a copy of datafile 2 in A7 called datafile_copy2 and a copy of datafile 3 in B7 called datafile_copy3. &lt;br /&gt;
# Move datafile_copy1 and datafile_copy2 back to AB. You should do this without making A5 and A7 your current working directory (&#039;&#039;&#039;Hint 1 &#039;&#039;&#039;)&lt;br /&gt;
# Make two files in B7 called extra_copy1 and extracopy2.    &lt;br /&gt;
# Move datafile_copy3, extra_copy1 and extra_copy2 to AB. &lt;br /&gt;
# Rename extra_copy2 as extra_copy1.&lt;br /&gt;
# Remove datafile_copy1, datafile_copy2, datafile_copy3 and extra_copy1.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Hint 1:&#039;&#039;&#039; You can move files in other directories than the one you&#039;re in by specifying an absolute path.&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/unix/index.php?title=File:Directory_Branch.png&amp;diff=18</id>
		<title>File:Directory Branch.png</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/unix/index.php?title=File:Directory_Branch.png&amp;diff=18"/>
		<updated>2024-03-20T11:55:38Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/unix/index.php?title=File:Navigating_from_home%26root.png&amp;diff=17</id>
		<title>File:Navigating from home&amp;root.png</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/unix/index.php?title=File:Navigating_from_home%26root.png&amp;diff=17"/>
		<updated>2024-03-20T11:55:08Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/unix/index.php?title=File:Ubuntu_CLI.png&amp;diff=16</id>
		<title>File:Ubuntu CLI.png</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/unix/index.php?title=File:Ubuntu_CLI.png&amp;diff=16"/>
		<updated>2024-03-20T11:54:36Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/unix/index.php?title=File:MobaXterm_CLI_Structure.png&amp;diff=15</id>
		<title>File:MobaXterm CLI Structure.png</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/unix/index.php?title=File:MobaXterm_CLI_Structure.png&amp;diff=15"/>
		<updated>2024-03-20T11:54:15Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/unix/index.php?title=File:File_structure2.png&amp;diff=14</id>
		<title>File:File structure2.png</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/unix/index.php?title=File:File_structure2.png&amp;diff=14"/>
		<updated>2024-03-20T11:53:42Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
</feed>