Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

Github repo cloud-examples: https://github.com/sagemath/cloud-examples

Views: 7924
License: MIT

Linux Primer

Underneath everything in the Sagemath Cloud sits the free open-source operating system Linux. It is a very powerful system which powers everything from smartphones, desktop computers, large servers and supercomputers. In order to make this power useful, software applications run under your identity and interact with Linux. For example, they can read files from a storage system, the loaded data in memory can be modified, the application reacts dynamically to input and finally produces human readable output or stores data back to files.

Most of the time, application interfaces like the very Sage Worksheet you are currently viewing is more than enough for your needs. But: There are cases, where you might need a specific task or feature, which you cannot reach from that high level of abstractions.

Hence, the following introduction goes a little bit deeper and explains a few common “command line utilities”. They open up a new world, which is much closer to the actual operating system. This allows for much more flexibility and makes this powerful system more useful for you.

Last words before we start: The following is neither fancy nor new - it is rather a collection of everyday tools like in a real-world toolbox. Combined and with some experience, they allow you to accomplish a vast variety of tasks.

Also, don’t be scared. Sagemath Cloud’s unique snapshot feature can rescue all files that get damaged or dissapear during your explorations ;-)

Note

The following examples are in cells that start with %sh. That “magic” annotation tells the Sage Notebook to run the content of the cell inside the most famous Linux terminal, called bash.

Your way around the filesystem

A single “file” is a stream of data (mathematican’s can think of it as a vector of bytes) which has a name, a date and some other properties. The so called “file system” is an organization tool for all these individual files, where files are collected in “directories”. All those directories are organized in a hierarchy, where the common topmost ancestor is the /. Therefore, all paths to files start with that slash and the intermediate levels are these directories.

Examples:

  • /home/alice/file1
  • /etc/fstab
  • /usr/bin/bash
%sh # lines starting with # are comments, they are ignored but will explain to you what's going on! # pwd = print working directory # pwd tells you, where you are. pwd
/mnt/home/2Qrdjpk5
%md