Commands Introduced on the • on a Unix-Like System (Pretty Much) Everything Is a File Left

Commands Introduced on the • on a Unix-Like System (Pretty Much) Everything Is a File Left

Introduction to GNU/Linux and the Shell April 2021 Course Information • The aim of this course is to provide an introduction to Do you recall using a GNU/Linux operating system? GNU/Linux and the Unix Shell If so, which one and for what • You will probably benefit the most if you’re not yet familiar purpose? with GNU/Linux and the Unix Shell, but if you plan to work on the HPC, Compute Cloud and/or AI infrastructure provided by LRZ -> by the end of this tutorial, you should have the basic skills to successfully interact with GNU/Linux-based systems • Consider this to be a guided self-study tutorial -> Follow the practical instructions. They can often be found in blue text color, blue boxes and/or blue side columns. Try to answer any questions before you proceed to the next slide(s) Introduction to GNU/Linux and the Shell | April 2021 7 What is GNU/Linux? • GNU/Linux is a free and open-source operating system Are you aware of any free/libre • As such, it is an alternative to popular operating systems like open source software (FLOSS) Microsoft Windows, Apple macOS, Google Android and others projects? • It powers the whole spectrum of computer systems like embedded and mobile devices as well as personal computers but also the majority of web servers and the world’s largest supercomputers • On a desktop system, it typically consists of the Linux kernel, libraries and tools, a graphical desktop environment and various applications like a web browser, an office suite and more. On servers, there is usually no graphical user interface provided (“headless”) • As these software projects are typically open source and freely available, Meet Tux, the mascot of the Linux there are several so-called distributions, which bundle these components to kernel. create a coherent system and user experience. Some of them are largely community-driven like Arch Linux or the Debian project, others are backed by commercial entities. These typically also provide community versions of their distributions. Examples are the Fedora and RHEL projects, backed by IBM, openSUSE and SLES, backed by a German company called SUSE and Ubuntu, backed by Canonical Introduction to GNU/Linux and the Shell | April 2021 9 GNU General Public License (GPL) The powerful versatility of free and open-source software is rooted in their licenses, such as the GNU General Public License (GPL). This license grants four essential freedoms or rights to the user of the software: • The freedom to “use a program as they wish, for any purpose", • the right to "study how the program works, and change it so it does the computing as they wish", • the freedom to "share and redistribute copies so they can help their neighbor" and finally • the right to "improve the software and to distribute copies of their modified versions to others". These rights are key for e.g. tuning software on a one-of-a-kind supercomputer, but also, more generally, in an environment where the goal is to create reproducible research and open science. Introduction to GNU/Linux and the Shell | April 2021 10 Supplement: Popular Desktop Environments Ubuntu Desktop KDE Plasma GNOME Shell … and several more. Introduction to GNU/Linux and the Shell | April 2021 11 https://www.zdnet.com/article/linux-totally-dominates-supercomputers/ Supplement: Linux and High Performance Computing (HPC) Introduction to GNU/Linux and the Shell | April 2021 12 A Shell in a Terminal Application When working in the terminal of a GNU/Linux distribution or connecting to a headless server remotely, after login you will be 1 2 3 greeted by a sight like this: a shell environment. It typically displays your username (1), the hostname of the machine your're working on (2) as well as some representation of the current file system path. It awaits user input (3). Introduction to GNU/Linux and the Shell | April 2021 13 Let’s get this going! • GNU/Linux: launch your favorite terminal application Start a Unix-like • macOS: launch Terminal shell environment! • Windows: • Windows 10: Install the Windows Subsystem for Linux (WSL) https://docs.microsoft.com/en-us/windows/wsl/install-win10 • Alternatively (on older Windows versions): • Install Git BASH (as part of Git for Windows) https://gitforwindows.org/ • or MobaXterm https://mobaxterm.mobatek.net/ • Or, for a basic introduction, visit https://bellard.org/jslinux/ in your browser. NOTE: this will not be suitable for “real” work later on. You should preferably set up a proper shell environment now! Introduction to GNU/Linux and the Shell | April 2021 14 The World is Your Oyster What is “your” username? What is the hostname of the machine? Let’s explore the file system… Introduction to GNU/Linux and the Shell | April 2021 16 File System Hierarchy Standard (FHS) Try the commands introduced on the • On a Unix-like system (pretty much) everything is a file left. • All files and directories appear (somewhere) under the root directory “/”, even if stored on different – possibly remote – devices. There are no drive letters like on other operating systems. • Use $ pwd to get the name of the current working directory • Use $ ls to list all files and directories in the current directory • Use $ ls / to list all files and directories in the root directory • Use $ ls /any/other/dir to list all files and directories in the specified directory Introduction to GNU/Linux and the Shell | April 2021 17 Exploring the File System /bin: command binaries (e.g. ls) /etc: configuration files /home: (regular) users’ home directories /lib: libraries (for binaries in /bin et al.) • As an exercise, take a look at the /media: mount points for removable media contents of /usr and other directories! /mnt: mounted filesystems • Are any (regular) user home directories /root: home directory of the root user /sbin: system binaries on your system? /usr: secondary hierarchy for read-only user data /var: variable, i.e. changing files Introduction to GNU/Linux and the Shell | April 2021 18 Detailed Listing of All Files Use the l and a options with ls (i.e. ls -la) to get a detailed listing of all files in your current (home) directory (we will cover most of this information later). Can you spot the differences to the previous listing (using just ls)? Introduction to GNU/Linux and the Shell | April 2021 19 General Command Syntax This command syntax can serve as general example to distinguish different components: $ ls –la /home ls is the command with the options (also switches or flags) –la and the argument /home Options generally start with either a single dash - (as above) or two dashes --. Introduction to GNU/Linux and the Shell | April 2021 20 Getting Help • There are two common ways to find out how a command works and which options it accepts… 1. Pass the --help option to the command: $ ls --help 2. Read a command’s manual (man pages), using the man command: $ man ls (use the arrow keys to move up and down, press q to quit the man page) • What effect does the -h option have on the ls command? • Can you spot other interesting options? Introduction to GNU/Linux and the Shell | April 2021 21 Directories Follow the instructions on the left. • Create a new directory in your current (home) directory called „my_dir“: $ mkdir my_dir • Change your current working directory to this folder: $ cd my_dir Introduction to GNU/Linux and the Shell | April 2021 22 Navigating Directories Notice the changing prompt… What does the “~” symbol represent? You could use cd .. to move (back) to the parent folder. A dot . represents the current, two dots .. the parent folder. Absolute vs. relative paths: specifying a location with a leading slash / indicates a start at the root of the file system (absolute), omitting it leads to an interpretation relative to the current directory Tip: use the tab key for auto-completion! Introduction to GNU/Linux and the Shell | April 2021 23 File Manipulation Follow the instructions on the right. • Make sure you‘re located in the my_dir directory created earlier • Create a new (text) file by “touching” it: $ touch my_file • Can you spot the newly created file it in a file listing? • What‘s the content of this new file? How can you tell? Introduction to GNU/Linux and the Shell | April 2021 24 File Manipulation Can you spot the size of this (empty) file? On most systems, you can use editors like e.g. nano, vim or emacs to edit text files directly in the console. Use nano to modify the existing file (write something to it): $ nano my_file Note the shortcuts along the bottom of the nano screen; “^” represents the Control (CTRL) key Use nano to create another file and write a couple of lines: $ nano another_file.txt Be aware of (missing) file extensions: In contrast to other operating systems, GNU/Linux does not rely on file extensions in order to define the type of a file. For interoperability and clarity, file extensions can still be used, of course. Introduction to GNU/Linux and the Shell | April 2021 25 File Manipulation and Redirection • There is a tool called cat. What does it do? Refer to the cat manpage for • “Concatenate FILE(s) to standard output. additional With no FILE, or when FILE is -, read standard input.” information. • Use cat to display the contents of my_file $ cat my_file • The shell allows for input/output redirection using > (and <) • Use cat to write something to nice_file.txt and display it afterwards $ cat > nice_file.txt write something nice here and add another line CTRL+C $ cat nice_file.txt Introduction to GNU/Linux and the Shell | April 2021 26 File Manipulation and Redirection • Files can be appended using >> $ echo “yet another line of text” >> nice_file.txt $ cat nice_file.txt • Using << allows for the creation of here documents (input stream literals), the general format is: command << delimiter (commonly EOF) input stream delimiter • Try the following.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    37 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us