Practical activity

Duration2h30

File systems and permissions

Introduction

A few points:

  • A file is a (possibly empty) set of bytes, associated with a name and possibly metadata (such as date, owner, etc.)
  • A directory is a (possibly empty) set of files or subdirectories. It is itself associated with a name and metadata. Files can then be arranged hierarchically in directories and subdirectories.
  • Operating systems generally adopt certain strategies in the way they choose to organize their file hierarchy. (Where to store system resources, configuration files, applications, libraries, user data, etc.)
  • Files are recorded on a storage device, such as a hard disk, a solid-state drive (SSD), a USB key, a DVD, a plain old floppy disk, a magnetic tape, etc. (Depending on the underlying technology, a storage device can be divided into parts called partitions or volumes.)
  • Some of those storage devices are local (physically inside or plugged on your computer), or on a distant computer and usable via the network.
  • The way bytes are organized on the storage is called a file management system (decides which bytes are for the name, the data, the metadata, etc.)
  • Some operating systems extend the concept of files in several directions:
    • links or shortcut: the possibility for a file to have several names. When certain nodes of a hierarchy can be reached by several paths, we obtain a graph. This extends the way files can be organized.
    • special files: Linux, Mac and Unix in general like to use file names as entry points to kernel services. These file names are not associated with stored data, but are associated to specific attributes or metadata. So that, when an application performs read-write operations, data is transmitted to the corresponding device driver in the kernel, which then activate the device. In other cases, this enables the use of socket services, pipelines, shared memory and so on. In yet other cases, this allows you to dynamically configure or inspect the kernel. Well, this is special. For now, it’s enough to remember that this exists.

Explore the docs

So, according to the documentation and Wikipedia pages mentioned above, what should be the name of the file system used on your own computer? (FAT32, NTFS, Ext4, APFS, etc.)

Explore your drive

It’s your own computer. Look at an application named “File Explorer”, “File Manager”, “Files”, “My Computer”, “Finder” or similar. (Typically the icon looks like a papers folder or a filing cabinet.) Know how to launch this application. Keep in mind that this is just an application. (You may install others that do the same.) It gives you a nice view of the files stored on your computer; it uses the file system services provided by the operating system, but this app is not the operating system.

So, this application lets you navigate your computer’s file hierarchy. Please, launch it.

  • First check your current position, how to view this information.
  • Then try navigating up, down, sideways. Think of a tree, with branches, roots and leaves.
  • Try to return to your very first location.
  • You can also take a look at this application’s configuration options, which may give you some ideas. Just be curious.

On your journey through your files, you’ve come across various categories: system resources, applications, libraries and user data. Did you find out who’s who?

Be comfortable with your file hierarchy

Microsoft does not provide official documentation specifying the organization of its Windows system. (If you know, please let me know.) However, it is possible to find good third-party tutorials.

The system is organized into several file trees, each beginning with a capital letter. (“Several” can be reduced to only one on a simple system.) The capital letter is probably C: on your system. This is for historical reasons. The first IBM PCs sold were equipped with one or two floppy disk drives, to which the letters A and B were assigned, then the hard disk drive was assigned the letter C. This has remained the case (except for floppy disks, no longer in use). Additional hard disks, partitions or network drives receive the following letters.

Key folders:

  • C:\Windows: Resources for the Windows system itself.
    It includes ‘C:\Windows\System’ (global resources), ‘C:\Windows\System32’ (libraries for 32 bits systems), ‘C:\Windows\SysWOW64’ (for 64 bits systems).
    This is sometimes hidden by applications, to “improve the user experience”… If you insist, you can go there, after clicking Ok several times.
  • C:\Program Files C:\Program Files (x86): Default location for installed applications (for 64 bits systems and for plain old 32 bits)
  • C:\Users\username: Locations dedicated for each user’s files

So, use your File Explorer to go there and check by yourself.

The system is organized into a single global hierarchy (unlike Windows). The root of this tree is called “/”. The hierarchy follows a specification: the Filesystem Hierarchy Standard. Most Linux variants, like all other Unix systems, comply (more or less) with this specification.

Key folders:

  • /boot: Resources to start the system (the bootloader, the kernel, etc.)
  • /etc: Host-specific system-wide configuration files. (This surprising name is that of “etc.”, the Latin locution “et cetera”.)
  • /bin: Essential user command-line binaries.
  • /sbin: Essential system binaries.
  • /lib: Libraries for the binaries in ‘/bin’ and ‘/sbin’.
  • /usr: Secondary hierarchy, for non-essential resources. It includes ‘/usr/bin’, ‘/usr/sbin’, ‘/usr/lib’.
    (The separation between essential and non-essential is the result of a long history that began in the 70s. But bear in mind that “usr” is not the abbreviated name for “users”; users go elsewhere…)
  • /dev: Special files relating to devices.
  • /proc /sys: Special files relating to the kernel.
  • /home/username: Locations dedicated for each user’s files.

So, use your File Explorer to go there and check by yourself.

The system is organized into a single global hierarchy (unlike Windows). The root of this tree is called “/”. Like other Unix systems, it more or less follows the Filesystem Hierarchy Standard (well, this is rather less). But it has its own specificities. Traditional Unix resources are generally hidden by Mac applications, to “improve the user experience”… Others are renamed to be more explicit.

Key folders:

  • /System: Resources for the system
  • /Applications: Default location for applications intended for use by all users
  • /Library: Libraries for the applications in ‘/Applications’
  • /Users/username: Locations dedicated for each user’s files (with subdirectories for their own installed ‘Applications’ and ‘Library’)

So, use Finder (or your favorite file explorer) to go there and check by yourself.

Try command-line

The command line isn’t reserved for movie scenes with geek stereotypes, it’s actually a practical way of using your computer.

In a nutshell, a command line interface (CLI) is an application (or part of an application) offering text-based interaction between human and machine. The human is prompted to type a sentence, the machine understands it (or not) and provides its answer. For this to work, the sentence must be simple and strict, essentially a command word followed by a few parameters or options. The human must know the words that the machine can understand, and type them with his fingers on the keyboard without clicking the mouse. (This extraordinary skill is probably at the root of these cinematic stereotypes.)

In the past, the command line interface was a physical console, named a terminal, a device consisting of a cathodic screen and a keyboard, connected to a cabinet-sized computer. (A great commercial success of the Teletype Corp. in the 70s, which left the common word TTY for these devices.) Now, it’s just an app on your PC. Thus, “command line”, “cli”, “shell”, “console”, “rollover”, “terminal”, “tty” are more or less synonyms with minor peculiarities.

Let’s try.

Explore the menus and look for an application called “Command Prompt” or similar. You can also use the search bar for “Command”, “Prompt”, “cmd.” or a combination. Click on it. And keep in mind the way to launch it.

So, this launches a text-based application. This is either the traditional “cmd”, or the new Windows “powershell”. Both are suitable for our needs today. (The latter does more in the sense that its scripting language extends that of the former, plus extra commands. Forget that for now.)

The basic commands you should know are:

  • help: Yes, this is a command. It provides either the list of supported commands, or gives details on a given command (eg. ask for “help cd”).
    In addition, each of the following commands displays a brief help text when followed by the “/?” option (eg. type “dir /?”).
  • dir: List the content of a directory.
  • cd: Change Directory. Go to the directory you indicate (eg. “cd C:\Users", or “cd ..” where the special directory name “..” means a step back in the hierarchy.)
  • c: d: a: Jump to the hierarchy of the drive attached to the letter, if active.
  • mkdir rmdir: Make or remove a directory.
  • copy: Copy a file or a directory. (Also note “xcopy”, and extended version.)
  • del: Delete files.
  • ren: Rename a file or a directory.
  • tree: Display the tree from your current location in the hierarchy.
  • app_name: Launch an application, just type the name of the executable file. (Eg. type “notepad” or “explorer”, etc.)
  • exit: To exit.

So, use the command line interface to browse your file hierarchy.

Notice the special usage of the character “\” (backslash). This is the file separator. It is not part of the name, it is used to separate names along the characters string. A serie of directory and subdirectory names separated by this separator is called path.

We can distinguish:

  • absolute path: The path start by a drive letter.
  • relative path: The path starts with the name of a subdirectory of the current directory. It is relative to ‘here’. It is therefore only valid if you start from the right place.

Notice the interest of the special subdirectories names “.” (here) and “..” (a step back).

Questions (absolute or relative):

  • What is “C:\Users”?
  • What is “C:\Windows”?
  • What is “Windows\System”?
  • What is “..\..\Users”?
  • What is “C:\Windows\.\System”?

Answer:

  • Ask your computer! (Do try, with the command “cd”)

Question:

  • is there a place where “.” = “..” ?

Notice that Windows is case-insensitive. (Contrary to Unix.)
Tip: If a directory or file name contains blanks, use quotation marks.

To go further

If you have installed WSL (Windows Subsystem for Linux), you can launch it, and move on to the next Linux tab.

Linux and Mac are both variants belonging to the Unix family. They’re rather distant cousins, but in this case, we can consider them in the same way.

Explore the menus and look for an application called “Terminal”, “Command”, “Shell” or similar. It is probably an icon figuring a rectangular b&w screen displaying the text “>_” (the historical Unix prompt). Just in case, some indications for Linux Ubuntu and Mac.

The basic commands you should know are:

  • help: Yes, this is a command. It provides either the list of supported commands, or gives details on a given command (eg. ask for “help cd”).
  • ls: List the content of a directory.
  • cd: Change Directory. Go to the directory you indicate (eg. “cd /home”, or “cd ..” where the special directory name “..” means a step back in the hierarchy; also note the special directory name “~” as an alias for your own home directory.)
  • pwd: Print working directory, your current location in the hierarchy.
  • mkdir rmdir: Make or remove a directory.
  • cp: Copy a file or a directory.
  • rm: Remove files.
  • mv: Move a file or a directory.
  • tree: Display the tree from your current location in the hierarchy.
  • app_name: Launch an application, just type the name of the executable file. (Eg. type “gedit” or “firefox”, etc.)
  • man: Display a manual page relating to an application or to the system.
    Unix has the great idea to come with its own official documentation. (Eg. type “man gedit”; press ‘Q’ to quit)
    Type “man hier” for an explanation of your system’s files hierarchy.
  • exit: To exit.

So, use the command line interface to browse your file hierarchy.

Notice the special usage of the character “/” (slash). This is the file separator. It is not part of the name, it is used to separate names along the characters string. A serie of directory and subdirectory names separated by this separator is called path.

We can distinguish:

  • absolute path: The path start by the root of the hierarchy, named “/”.
  • relative path: The path starts with the name of a subdirectory of the current directory. It is relative to ‘here’. It is therefore only valid if you start from the right place.

Notice the interest of the special subdirectories names “.” (here) and “..” (a step back).

Questions (absolute or relative):

  • What is “/home”?
  • What is “/sbin”?
  • What is “usr/bin”?
  • What is “../../sbin”?
  • What is “/usr/./bin”?

Answer:

  • Ask your computer! (Do try, with the command “cd”)

Question:

  • is there a place where “.” = “..” ?

Notice that Linux & Mac (and other Unixes) are case-sensitive. (Contrary to Windows.)
Tip: If a directory or file name contains blanks, use quotation marks.

“Oh, too bad, I forgot my PC at home…”

Don’t worry, you can install a terminal app on your smartphone! For example, look at “termux” (Android) or “iSH” (iPhone).

These systems are Unix based, so you can switch to the Linux & MacOS side tab and experiment with the activities offered and explore the internals of your smartphone.

Permissions

Your computer is certainly a multi-user system. This means that several users can use it (simultaneously or alternately), and that the system does its best to preserve the integrity of everyone’s data. Users here can be a physical person, or not: on your computer you play two roles, the role of the system administrator (install, uninstall, configure the system and apps), and the role of a simple user (happy eyball user which click and enjoy, and code). Modern systems therefore implement ways of isolating and separating things. First at the login: before starting your session, the computer asks you who you are and to prove it (e.g. username + password). Then, during your session, the system prevents you from damaging other people’s files (accidentally or deliberately), unless explicitly authorized. Also, it’s generally considered a bad idea to open its session as administrator, or to play user applications as administrator. (Even if you are the administrator of your computer, create a normal user account and use it to log in for normal use. Limit your role as administrator to a very limited time.)

Generally speaking, the operating system takes care of this through its file management system; each file is stored with metadata indicating in one way or another which user is authorized to read, write or execute the file. The details depend on the system in question.

Note also that permissions on directories must be understood with care.
Being authorized to read a directory means being authorized to obtain a list of the file and subdirectory names it contains.
Being authorized to write to a directory means being authorized to add or delete a file in that directory, independently of being authorized to access the file’s contents.
Being authorized to execute a directory is nonsense (unlike a file, which can be an application). It is replaced by the idea of being authorized to traverse it, i.e. to access its content without the authorization to read it.

Windows generally uses NTFS as its file management system. (So that’s the answer to the first question of this session, did you get it?)

Authorizations are implemented using access lists (ACLs) attached to files: an explicit list of who is authorized to do what.

To do: Launch your file manager. Select a file somewhere and right-click. Select the “Security” tab. You get a list of users and, for each of them, the actions authorized or refused. You can remove a user, or add a new one from among those existing on your system. (This can also be the name of a “group” of users.) For each of them, you can make modifications of the so called “Basic” or “Advanced” (or “Special”) permissions. The basic authorizations are fairly obvious: read, write, execute, modify properties. The more advanced ones rely on the fact that this can be inherited from the parent directory or not, or allow the creation/deletion of files or subdirectories, and so on.

For your tests, you can create dummy files or directories and modify their permissions, without touching your usual precious files.

You can also check or modify permission with the command-line tool “icacls”.

To go further

If you have installed WSL (Windows Subsystem for Linux), you can launch it, and move on to the next Linux tab.

Once again, we’re going to treat Linux and Mac together.

Linux generally uses Ext3 or Ext4 as its file management system, while Mac uses APFS now. (So that’s the answer to the first question of this session, did you get it?)

Permissions are implemented using Unix permissions: a set of 3x3 bits, indicating read/write/execute permissions for the file owner, for users in the group to which the file belongs and for other users.

(There are many file management systems for Unix, but they all implement this principle. Somme also offers access lists or extended attributes. But this is outside the scope here.)

To do: Launch your file manager. Select a file somewhere and right-click. Select the “Permission” tab. You get the above-mentioned read/write/execute permissions for users/groups/others.

Now open your favorite command line interface. Type ls -l. (The “-l” option ask for the long description of listed files. Read the manual page with “man ls”.)

$ ls -l
total 8
-rwx--x--x   1   clohr   info-perm     92   juil. 15 17:33   helloworld.py*
-rw-r--r--   1   clohr   info-perm     33   juil. 15 17:34   readme.txt
drwx------   2   clohr   info-perm   4096   juil. 15 17:35   session1/
  • You can guess classical information: a file name, a date, a size.
    File size is expressed in bytes. The total is expressed in terms of occupied blocks; forget it.
    The date displayed is the date on which the content was last modified. Unix also records the last read date and the last time the attributes were modified. (Each of the three recorded dates can be obtained with certain “ls” options.)
  • You can see a username (“clohr” in this example), and a group name (“info-perm” in this example).
  • The second column contains a small number (1 or 2 in this example). This is the number of direct links to the file, i.e. the number of names in the file hierarchy to reach the data.
  • But the most interesting part for us is the first column: the mysterious set of letters and dashes. These are Unix file permissions. (Shown here symbolically; the corresponding binary values are sometimes displayed in octal, and rarely in hexadecimal).

Explanation of the authorization symbols:

  • The first letter tells if the file is a regular file (the dash ‘-’), or a directory (a ’d’).
    (For special files this can also be ‘c’ (char device), ‘b’ (block device), ‘p’ (pipe) or ’s’ (unix socket). Forget this.)
  • Next, three sets of three letters: ‘rwx’ (read, write, execute, or a dash if unallowed), for the user, for the group and for the others.
    (In addition Unix has set user-id and sticky bits, with ’s’ or ’t’ letters in place of the ‘x’. Forget it.)

Key points to remember:

  • (r)ead (w)rite e(x)ecute, for (u)ser (g)roup (o)thers
  • meaning for directories: r = get the list of files in it, w = write this list by adding or deleting files, x = traverse to reach files without listing

Unix permissions (or modes) can be changed by the command chmod. Take a look at the manual page (“man chmod”). Basically the syntax is “chmod [ugo+=-rwx] [filename]”, where “ugo” and “rwx” are as above, and “+=-” is the action to add, set or withdraw those permissons for those persons. To test, create a dummy file and change its permissions:

$ echo "Hello world" > dummy.txt
$ ls -l ./dummy.txt
-rw-rw-r--   1   clohr   info-perm   12   16 juil. 09:22   ./dummy.txt

$ chmod go-r ./dummy.txt
$ ls -l ./dummy.txt
-rw--w----   1   clohr   info-perm   12   16 juil. 09:22   ./dummy.txt

$ chmod a+x ./dummy.txt
$ ls -l ./dummy.txt
-rwx-wx--x   1   clohr   info-perm   12   16 juil. 09:22   ./dummy.txt

...

Did you really read the manual page? What is the meaning of ‘a’ in the last “chmod” command?
Also notice there is a plain old octal syntax. But you should at least know the symbolic syntax.

Hidden files: Files may be hidden. But this is not due to some kind of special attribute or permission property, this is just a convention on the part of the applications. Files or directories whose name begins with a dot are generally not shown to the user, unless requested. For example, your configuration files on your session are generally hidden (for your convenience). To see them, pass the option “-a” (all) to “ls”:

$ cd
$ ls -la
...

Likewise, look at how configuring your file manager to show hidden files.

Know where to find downloaded files and various application files.

Applications use and produce files, but where are they?

Consider a first scenario.

You visit a web page. You’ve read the documentation carefully. You’re now convinced that this is the thing you do need. You click on download.

What append?

Your web browser (which is just another application) downloads the requested file and stores it somewhere on your computer. Where has this new file been placed in your file hierarchy?

  • Open your File Manager. On the displayed file space you get something called “Downloads” (or similar). This is probably where your web browser saved the downloaded file. (Check.) But is this really the right answer to the question? Where is this “Downloads” subdirectory in your file hierarchy? In fact, you see it into a folder named “Homes” (or similar, like a shortcut, to “improve the user experience”). But a shortcut to where? How or what made this shortcut?
    Your File Browser certainly also propose an item called “This PC” or “System” (or similar), an entry point into your computer’s file hierarchy, offering a concrete view of files and their location (without hiding strategies to enhance the user experience). So, browse it to find your downloaded file. Got it? Keep in mint the true location. Please also note that the above-mentioned shortcut is just a trick performed by your file manager, for display purposes.

  • Open your Command Terminal (or the name in use on your system). Repeat the exploration, but using the command line interface. Use the commands described above to browse directories, and find the downloaded file. Keep in mind the current location.

  • Security considerations.
    The items you have downloaded may content executable. If you click on it, you ask your computer to follow instructions decided (coded) by someone else. (Okay, so everything else on your computer already is.) But, are you sure that this executable is good for you? That there is no hidden action? Your system may (or may not) incorporate an “antivirus”, i.e. an application that examines executable instructions and detects (or not) inappropriate code. It increases trust, but it’s not magic. The first line of protection is you. Have you read the documentation carefully? Did you download it from a reliable source? Is it the very original source and not a third part site (which could inject some extra code in it)? Keep these questions in mind when you click ok. There is probably no definitive answer, just some ways to elevate trust.

Consider a second scenario.

Now you’re starting to become a coder (and soon a developer), with Python, Java, etc. and an IDE (eg. VS Code). So, you played with an IDE. This is an application, which store files. But where?

Same questions as for the first scenario:

  • Use your file manager to find the actual location of your code files in the file hierarchy.
  • Use your command line interface to find the actual location of your code files in the file hierarchy.

Organize your own user space by lessons/sessions/etc.

You probably don’t put your pants, socks, bathing suits and coats in the same drawer. You’re probably trying to organize your belongings to bring together items that go together.

Please do the same with your digital belongings.

Your session may already propose an organization: “My Music”, “My Videos”, “My Pictures”, “My Downloads”, “My Desktop”, “My Documents”, … This is an organization per type of files. (Well, Documents is rather fuzzy, and there is no “My Codes”.) You may therefore prefer another strategy for organizing the files you’ll have to manage during your training. Why not organizing this by subdirectories corresponding to disciplines / lessons / sessions / activities. It’s certainly not a good idea to have all your working files in the same folder, in a flat way, and to have lots of things simply named “exercise” “project” “report” (of what??). Try to find your own strategy for organizing your files and follow it.

Do it now. You’ve already created files in previous sessions. So create subdirectories, now, with names that make sense to you, and move files into them. Don’t worry if you change your mind and opt for another strategy latter, you can always reorganize and move your files accordingly. Just be consistent.

Manage archives

An archive is a big file containing several files. It is useful to manage backups, or to distribute a project.

In addition to file collection, some solutions also offer compression. This can be done separately or in combination. Password protection can also be offered. It is traditional in the Unix world to use the “tar” format (Tape ARchiver, historically used for tape backups), followed by compression (gzip, bzip2, xz, …) One get file extensions such as “.tar.gz” “.tgz” “.tar.bz2” “.tar.xz” etc. It is traditional in the Windows world to use the “.zip” or “.7z” format (or other proprietary formats such as “.arj” or “.rar”). But many format exist, with differences in terms of access latency, compression ratio and licensing. Most of the different formats are available on all platforms.

The basic operations are: create, list, extract. Most also allow you to add a file to an existing archive, replace a file with a new content or extract one file without extracting the whole.

  1. Opening a file archive.

    This is typically the operation you perform to obtain the files provided by teachers for a practical course.

    Download archive_tuto.zip or archive_tuto.tar.bz2 proposed here (or both), and save it in your workspace. If your system offers to open it directly with an Archive Manager (or similar), refuse and choose to save it. Now, you know where your downloaded files are stored and how to access them with your file manager. So, go there and click on it. If your system doesn’t offer an Archive Manager, you can install 7-zip.

    The Archive Manager allows you to list the content of this archive. Note that there are two schools of thought when it comes to building archives: should all content be placed in a subdirectory within the archive, or should it be placed directly at the archive root? This will have a practical impact at the time of extraction. In the first case, all extracted content will be stored and grouped together in an appropriate subdirectory. Whereas in the second case, the files will be mixed with those already existing in the working directory. In this case, it is advisable to prepare by creating a subdirectory for archive extraction. So, the first thing to do is to look at the list of archive contents and check its internal organization.

    You can now proceed with file extraction. Decide where to extract the files, and remember it.

    Unix users may prefer command line tools: tar and unzip are your friends. (Read manual pages! to list: “tar tvf <archive.tar.bz2>” “unzip -l <archive.zip>”; to extract: “tar xvf <archive.tar.bz2>” “unzip <archive.zip>”) Then, look at the new files.

  2. Creating a file archive.

    This is typically the operation you perform when you hand in your work to the teachers.

    Create a subdirectory (eg. “my_homework”). Create a few files in it (eg. “foo.py” “bar.txt” …) Return to the previous directory, i.e. the one containing “my_homework”. Your favorite archive manager can be integrated into your file manager. In this case, when clicking on an item (eg. “my_homework”), it proposes a new action such as “archive”. Otherwise, you have to launch it from your applications’ menu. Basically, these archive managers propose to select files or directories on your disk, then ask you for an archive name and a location to create the archive.

    Unix users may prefer command line tools: tar and zip are your friends. (Read manual pages! to archive: “tar cvfj <archive.tar.bz2> <my_homework/>” “zip -r <archive.zip> <my_homework/>”)

    First, take a look at the contents of the archive you’ve created, at the list, to make sure you haven’t forgotten to place any files there. Then, send your archive file to your classmate and ask him or her to take a look at it.

File versioning

File versioning consist in keeping different iterations of the same file. We sometimes do this by hand, making copies of the same file and adding a version number or date to the name of the copies. So, one can go back to an earlier version if necessary, or trace the history of modifications to understand how things got to this point. This can be crucial when working on something that takes a long time to get to a perfect state (e.g. reports or software code). It can also help several people to work on the same file, managing different versions for each contributor. Well, file versioning management is an interesting feature. It’s even better to have a tool for this, and not to do it by hand.

There are many tools, but we’ll concentrate on “git”, which is nowadays widely used by developers.

  1. Install
    Follow the official instructions corresponding to your computer. The default configuration options are fine for us.

  2. Local use
    Open your favorite command line interface and tell “git” who you are (this will appear in the contributor log when editing files).

    $ git config --global user.name "Your Name"
    $ git config --global user.email "you@imt-atlantique.net"

    Please replace with your own real name and email, don’t blindly copy and paste…

    Now create a directory for a dummy project, initialize it for git (this creates hidden configuration files), produce files there, ask git to manage them, then produce a first “commit” (a version), and check that everything is okay at each step.

    $ mkdir git_trial_1
    $ cd git_trial_1
    $ git init
    $ echo "Hello" > readme.txt
    $ echo "print('hello world')" > hello.py
    $ dir
    $ git status
    $ git add *
    $ git status
    $ git commit -m "My first steps with git"
    $ git status

    Then, make a change and produce a new version.

    $ echo "world" >> readme.txt
    $ git status
    $ git commit -a -m "Improved documentation"
    $ git status
    $ git log --stat

    The “git log” command displays the different versions of your project. Note that commits are identified by a random unique name, not a simple number. (Making contributions to a project is not something strictly linear, but rather resembles a task graph. This is why using numbers would make no sense.) Note that the very last commit has for nickname “HEAD” (“HEAD~” is the commit before, and “HEAD~~” or “HEAD~2” as the commit even earlier, and so forth).
    To know what happened to a file:

    $ git blame readme.txt

    Let’s say you have doubts about the changes on this file and want to see a previous version:

    $ git show HEAD~ readme.txt

    It’s probably not that obvious at first glance when looking at the result, but in reality git does all this by applying diffs. The core of the process is calculating and applying diffs on files.

  3. GitLab

    You might be interested in pushing your work to a server. (To work with others, or with yourself but from different computers. The server acts as a kind of synchronization point.) You may have already heard of GitHub. Note that git is not GitHub. GitHub is a server for git projects from the company GitHub Inc., acquired by Microsoft in 2018. But other git servers are possible. It is important to know who you are pushing your work towards.

    IMT Atlantique offers a GitLab server for educational purposes. Log in and create a project, with a name like “git_trial_2”. You can use a predefined template, e.g. “Sample GitLab Project” Initialization may take a minute or two. Be patient. The server, in addition to git, offers several features such as a wiki, a web space, tickets, etc.

    In the upper right corner of your project page, there is a blue button named “Code”. Expand the associated menu. Several ways to clone/open/download your project are offered. Let’s choose “Clone with HTTPS”. Keep the URL provided in your clipboard.

    Open your favorite command line interface and clone this GitLab project to your computer.

    $ git clone https://gitlab-df.imt-atlantique.fr/xxxx

    Use the URL provided from your clipboard (and note the above ‘xxxx’).

    You can now go to this project directory, make any changes you need, locally on your computer, do commits and other fancy git tasks, and occasionally push that to the server. The corresponding command is “git push”, and its friend “git pull”. You can do this from multiple computers. (Note that we do not intend to detail here how to resolve complex merge conflicts. But if you’re working on separate files, on separate parts of files, or if you’re following the strict pull-commit-push sequence, there probably won’t be a problem.)

    $ cd git_trial_2
    $ git pull
    $ echo "foo bar" >> doc.txt
    $ git add doc.txt
    $ git commit -m "add documentation"
    $ git push

    Note that the push and pull commands work because this git project was configured with a URL.

    $ git remote get-url origin

    Your “git_trial_1” has no remote URL. Let’s associate it with a GitLab project. Connect to the GitLab server. Create another project, with a name like “git_trial_1”. But this time it is very important to chose “Create a blank project”.
    Then, GitLab provides some guidance on how to connect your local project to GitLab’s. Open your favorite command line interface and follow them.

    $ cd git_trial_1
    $ git remote add origin https://gitlab-df.imt-atlantique.fr/yyyy
    $ git branch -M main
    $ git push -uf origin main

    You can now go to this project directory, make any changes you need, locally, do commits and other fancy git tasks, and occasionally push that to the server…

These first steps with git are a very minimalist introduction. This is sufficient for a single-user context, for small projects, without complex file editing conflicts. But this may cover most of our needs for now. More documentation from the official tutorial or from third parties. You could learn how to create branches, tags, merges and many other fabulous things.