AaltoSciComp
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Help
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # Welcome to Linux Shell Basics 2021 ###### tags: `Linux Shell Basics` :::info This is a hybrid course. - Course page: https://scicomp.aalto.fi/training/scip/linux-shell-basics/ - This document: https://hackmd.io/@AaltoSciComp/LinuxShellBasics2021 - Archive of this document: https://hackmd.io/@AaltoSciComp/LinuxShell2021_archive - Learning materials: https://aaltoscicomp.github.io/linux-shell/ - Dates: 8, 10, 12 November, 11:50-15:00 EET (Finnish time) - Zoom room: SENT VIA EMAIL - On-campus room: Otakaari 1, U135a U7 PWC - Installation pre-requisites - Linux/Mac: you already have a bash terminal - Windows: we recommend https://gitforwindows.org/ (Windows PowerShell is not bash compatible). Alternatively, if you have access to a university linux server, you do not need to install anything, you can just open powershell and run something like `ssh username@machine.uni.fi` - Presemo quizzes: https://presemo.aalto.fi/shell/ - Please note that we will record the zoom: do not switch your camera or microphone unless you intend to. - Command history https://users.aalto.fi/~degtyai1/shell/ ::: :::info For the remote SSH to a native Linux - Aalto https://scicomp.aalto.fi/aalto/remoteaccess/ - HY https://wiki.helsinki.fi/display/it4sci/Remote+access+to+University+resources - TUNI https://www.tuni.fi/it-services/handbook/2724/3229 - OULU: https://www.oulu.fi/th/node/212293 ::: --- # Day 3 - Where will the videos be posted? What channel on Youtube? - Hopefully by early next week. You will all receive an email with the link. Our channel is here: https://www.youtube.com/channel/UCNErdFO1_GzSkDx0bLKWXOA ## Going over exercises 1.3 https://aaltoscicomp.github.io/linux-shell/file-archive-transfer/#exercise-1-3 - Why does the command `find ~ -type f -perm /r+w,r+r` needs the `/` character? - Check the `find` manual page for the `-perm` option. There are different prefixes that mean different things: "all bits set", "any bits set", ... - In this instance, the `/` makes find list all finds that have "at least read and write permissions", without it would not list those that have additional flags/bits set. - `find perm {mode}` is exact, `find -perm -{mode}` is "all", `find -perm /{mode}` is any. I would never remember this. - Running `find ~ -type f -perm /o+w` results in `find: -perm: /o+w: illegal mode string` - what OS are you on? - I'm on Unix (MacOS). - There are slight differences between the utilities included in different unices. It is possible that these symbolic mode strings don't exist on others. Linux (with GNU tools) is usually one of the most modern) - Cannot access Ivan's commands history. Says Access denied by the owner of the requested resource. - :heavy_check_mark: ## Command line utilities https://aaltoscicomp.github.io/linux-shell/cli_utiltities/ - What are you favorite unix utilities? - What is the difference between `less` and `cat` for checking the contents of a file? - cat prints straight to stdout, a one-shot thing - less is an interactive pager that lets you scroll up and down, search within, limit lines shown, etc. less is what we call a **pager**: shows files in pages. - Can you sort the contents of the file? When you cat - `sort`: `sort filename` is the same as `cat filename | sort` - I mean contents of the file inside the file - That does it. It writes it to standard output, which you then need to save back. - warning: `cat filename | ... > filename` will overwrite and remove contents from the file, since it opens it for output before it reads it in! - `sponge` (non-default, I think in package `moreutils`) can make this better * Can you also use 'tr' to replace the spaces in a file name? * In a filename, that's interesting. For filenames I would use the `rename` utility, it lets you replace expressions in filenames. * When renaming files, I also often use `vidir` (non-standard, package: `moreutils`). It opens an editor with filenames so you you can apply an editor's search-and-replace or other tools to do renames. * you need to put filename into a variable and then use either tr or a ${var/ /} construct to rename file with mv. We go through such cases in the Part 2. - I wonder how I capture the name of the file in a loop and save it somewhere? ie. `unzip -j 1st_specimen.zip target.png` and I want to rename the `target.png` to `1st_specimen_target.png` automatically after decompressing it? I dont know how to pipe this... - You would probably need a script for this, as the output file is not something that goes to the std:out. - actually, unzip has an option to extract to the stdout (-p). So what you would do is: `unzip -j 1st_specimen.zip target.png > 1st_specimen_target.png` :::info ### Break until xx:08 ::: - How does one access other disks, like USB-sticks? - This is what I do (perhaps old-fashioned, but I do almost everything from the shell and want full control): plung in the USB drive. `pmount /dev/sde` (pmount is another tool to install that mounts removable media, `/dev/sde` is a sample name for the disk. it automatically mounts it at `/media/sde`). Then access via `/media/sde/`. - There are also things that automatically mount it. - Or I access it via the file browser, I browse to it, open it, then right click and "Open in terminal". This gives me a much longer, harder to use path. - What about others? - I commonly don't need to do anything on a usb besides file transfers, and those I will do via the GUI (but then I haven't yet gotten huge files via usb, where e.g. copying by rsync would be a better option (due to checksums etc) - du -hs * .[!.] | sort -h du: cannot access ‘.[!.]’: No such file or directory - I remember this expressions is for hidden file? - Yes... there are no hidden files there +1 - there is a missing star at the end, it should be `du -sh * .[!.]*` it will list the space taken by normal files/folders (*) and files/folders that start with a dot (hidden files) ## Pipelines and grep https://aaltoscicomp.github.io/linux-shell/pipelines-grep/ :::info ### Break and exercise until xx:31 Exercises 1.5: https://aaltoscicomp.github.io/linux-shell/pipelines-grep/#exercise-1-5 - make a pipe that counts number of files/directories (including dot files) in your directory - ls -1A | wc -l - grep directories out of ls -l - ls -l | grep -v ^d - grep all but blank lines of the ‘man cut | grep …’ - man cut | grep -v '^$' - Using pipes and commands echo/tr/uniq, find doubled words out of My Do Do list: Find a a Doubled Word. - echo 'My Do Do list: Find a a Doubled Word' | tr -s ' ' '\n' | uniq | tr -s '\n' ' '; echo - If you are on a multiuser system, count unique logged in users. Tip: w or users gives you a list of all currently login users, many of them have several sessions open. Commands to discover: cut / sort / wc - w -h | cut -d ' ' -f1 | sort -u | wc -l - (*) Play with the commands grep, cut: find at least two ways to extract IP addresses out of /etc/hosts. Tip: grep has -o option, thus one can build a regular expression that will grab exactly what you need. ::: - can we show this in a tree format? root and branches - there is a linux tool called `tree` but it might not be installed. - Will this Q&A material also be available later? I think it has been very insightful. - Yes, we generally archive it. In this case we'll probably leave it on hackmd read-only. - . Thank you! - I think this never got answered (was in the day 1 hackmd) I started mathematica from bash today and when I was done I tried to shut it down from the bash as well. When I started it from terminal the cursor moved to an empty line which implicated I was not able to type any commands. So I killed it with ^C and the the cursor moved to the next line and I was able to type commands again but the mathematica was still up and running? Also tried to send it to background and kill it there, the terminal said it was terminated but it still was running? - I have never used mathematica Another question about this, why is it not possible to type commands after starting a program? The cursor is just blinking on an empty line. Is the idea to send it to the background if one wants to continue working in the same terminal? - Correct. For example I could start matlab with `matlab &` and continue using that terminal for other things. interestingly, if error messages come up, they might also show in the terminal window (it depends on the sofware thoughghghghghghghghghghghgh) - . ## Feedback One good thing - Thanks for the course! I believe I will be able to use Bash for simple operations without extra googling. As for non-linux user, the two and third lessons were quite intense, but I apprreciate we are provided with enough materials and the records. - The topics of the course were very punctual, with punctual demonstration of how the commands work and what it is possible to do with very simple inputs. The course also provided the opportunity to practice in both a basic level user as well as gave more "challenging tasks". It was also greatly appreciated that these tasks were solved and explained by the demonstrator and that not only did he explain the outcome of each command but also gave a little bit of background of what it contained or its "definition". In a more informal level, I want to thank you for these course, it was really useful and mind-blowing. If part 2 is also open, I am definitely attending. :smile: - . Thanks a lot for this nice introductory course! I got started using Bash shell and looking forward to other courses. The efficient way to ask questions and giving answers via hackmd was smart, also quiz by Presemo was very good! I also liked very much going through the exercises and solving the probles once everyone is done with the exercise. Having two people one for delivering the lectures and one to take care of the other practiclity was also another strength! - . - Thanks for the course! Especially this last time was very good, all the stuff seemed important for future use (especially piping) One thing to be improved - . - At least for me, it helps to remember the commands if I know what they are abbreviations of. So you might try to use them more often (e.g. not always saying just du, but 'disc usage') - . - Your explanations are good, but it feels like it's a list of different comments without a common narrative, and therefore a bit hard to actually understand and remember all of it. Maybe it would be good to prepare a repository with example files prior to the course and then share it with the participants, such that everyone can actually execute the exact same commands and see what happens - It might be good to add some section about why Linux/shells/command lines work like this. We now know how to use it, but I still feel like I'm missing the background or the underlying reasons why that's the case. Might be a subject for an entirely separate course though :) * I also agree with the previous comment that a prior material would be a good idea for upcoming courses. Not necessarily on the historical aspect but I think it is easier to execute multiple (an perhaps more complex) commands only after you have understood what is actually happening and what do they stand for (as stated in the abbreviations comment). ** Thanks for the course! Lot of information in three days and excellent course materials to keep practising by own** ---- :::info **This is the end of the document, WRITE ABOVE THIS LINE ^^** HackMD can feel slow if more than 100 participants are editing at the same time: If you do not need to write, please switch to "view mode" by clicking the eye icon on top left :eye:

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully