User Tools

Site Tools


labs:bash

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
labs:bash [2017/02/17 14:05]
thulrich
labs:bash [2020/08/31 21:03] (current)
Line 10: Line 10:
   * [[https://​wiki.ubuntuusers.de/​Shell/​Befehls%C3%BCbersicht/​|List of common shell commands]] (in German)   * [[https://​wiki.ubuntuusers.de/​Shell/​Befehls%C3%BCbersicht/​|List of common shell commands]] (in German)
   * [[https://​rogerdudler.github.io/​git-guide/​|Git - the simple guide]]   * [[https://​rogerdudler.github.io/​git-guide/​|Git - the simple guide]]
 +  * [[https://​www.atlassian.com/​git/​tutorials/​undoing-changes|Undoing changes with Git]]
   * Type ''​man '' ​ (note the space), followed by the name of a command, to the command line.\\ **Example**:​ ''​man rm''​\\ You will then see a manual page for that specific command. You can leave this screen by pressing the ''​q''​ key.   * Type ''​man '' ​ (note the space), followed by the name of a command, to the command line.\\ **Example**:​ ''​man rm''​\\ You will then see a manual page for that specific command. You can leave this screen by pressing the ''​q''​ key.
   * Google   * Google
Line 15: Line 16:
 In this exercise, you will use the most basic commands of git and bash. Make yourself familiar with these tools before we start with the more interesting part in Exercise 2. In this exercise, you will use the most basic commands of git and bash. Make yourself familiar with these tools before we start with the more interesting part in Exercise 2.
  
-  - Clone the git repository ''​10.0.0.1/​opt/​git/​ti2fp''​ into a folder called ''​ti2fp''​. The username is ''​git''​ and the password is ''​ti2lab''​.+  - Clone the git repository ''​<​nowiki>​ssh://​git@10.0.0.1/​opt/​git/​ti2fp</​nowiki>​''​ into a folder called ''​ti2fp''​. The username is ''​git''​ and the password is ''​ti2lab''​. ​(You will have to install git first.)
   - Create a new folder with the name of your nethz account.   - Create a new folder with the name of your nethz account.
   - Navigate into this folder and create a new git repository.   - Navigate into this folder and create a new git repository.
Line 41: Line 42:
   - Write the first three columns (Date, Open, High) of ''​msft.csv''​ into ''​msft2.csv''​.   - Write the first three columns (Date, Open, High) of ''​msft.csv''​ into ''​msft2.csv''​.
 ===== Exercise 3: Searching, pipes and xargs ===== ===== Exercise 3: Searching, pipes and xargs =====
-In the previous exercise, all tasks could be solved with just one command by passing some parameters to this command. In this exercise, we will learn how to search for files by their name and their content. Moreover, you are supposed to use [[http://​tldp.org/​HOWTO/​Bash-Prog-Intro-HOWTO-4.html|Pipes]] and (sometimes) the [[https://​www.freebsd.org/​cgi/​man.cgi?​query=xargs&​sektion=1|xargs]] ​command to pass on the output of one command to another command.+In the previous exercise, all tasks could be solved with just one command by passing some parameters to this command. In this exercise, we will learn how to search for files by their name and their content. Moreover, you are supposed to use [[http://​tldp.org/​HOWTO/​Bash-Prog-Intro-HOWTO-4.html|Pipes]] and (sometimes) the ''​xargs'' ​command to pass on the output of one command to another command.
  
 Go to the ''​sourcecode''​ folder. There, you will find hundreds of Java files in different subfolders. It would be tedious to open them all in a text editor if you were looking for something, wouldn'​t it? Go to the ''​sourcecode''​ folder. There, you will find hundreds of Java files in different subfolders. It would be tedious to open them all in a text editor if you were looking for something, wouldn'​t it?
Line 54: Line 55:
   - Delete those files. ​   - Delete those files. ​
   - You realize that you did not want to delete these files. Use Git to restore the files that you removed in Exercise 8.   - You realize that you did not want to delete these files. Use Git to restore the files that you removed in Exercise 8.
-      *  This reverts **all files** in the working tree to the current HEAD revision. +  ​- Use Git to restore the files that you removed in exercise 5.
-      *  This reverts all unstaged changes in the working tree, including deleted files. If the deleted files have already been staged for commit, one would need to do ''​git reset HEAD .''​ first. +
-      * Both these methods discard any changes that have not yet been commited!!! +
-      * Here are two very neat solutions from [[http://​stackoverflow.com/​a/​26892936|Stackoverflow]] which only affect deleted files, but do not revert any other unstaged changes: +
-          - To recover all **unstaged** deletions at once, automatically,​ without specifying each single path:  +
-          - To recover all **staged** deletions at once, automatically,​ without specifying each single path: +
-  ​- Use Git to restore the files that you removed in exercise 5.\\ There'​s at least two possible solution to this exercise: +
-      * The best solution would probably be to use ''​git log''​ to find the hash of the commit that was made after removing the files and to **revert** that commit using  +
-      * Another possibility would be to do a git **reset**. This just discards the previous commit. It is **dangerous** to do this if the commit has already been pushed to a server and might have been checked out by other people, because then you might run into an inconsistent state. Anyway, it works like this:  where ''<​hash>''​ is the hash of the commit you want to go back to, i.e. the last commit **before** the files were deleted.+
   - The file ''​allSrc.txt''​ (in the folder ''​sourcecode''​) contains a list of files. Write every line of these files that contain the word ''​static''​ into the file ''​static.txt''​. ​   - The file ''​allSrc.txt''​ (in the folder ''​sourcecode''​) contains a list of files. Write every line of these files that contain the word ''​static''​ into the file ''​static.txt''​. ​
  
labs/bash.1487336713.txt.gz · Last modified: 2020/08/31 21:03 (external edit)