Python basics
  • Tutorial
  • Exercices
  • About
  1. CLI
  2. Exercices
  • Introduction
    • Python
  • Fundamentals
    • 0-Basic Syntax
    • 1-Variables
    • 2-Data types
    • 3-Numbers
    • 4-Strings
    • 5-Lists
    • 6-Booleans
    • 7-Loops
    • 8-Functions
    • 9-Dictionary
  • Advanced
    • 10-Numpy
    • 11-Matplotlib
    • 12-DataFrame
  • CLI
    • Exercices
    • Solutions
  • Git
    • Git introduction
    • Git branch
    • Git exercices
  • SQL
    • SQL Exercices
    • SQL Solutions

On this page

  • Exercice 1
  • Exercice 2 - Grep
  • Exercice 3 - Find
  • Exercice 4
  1. CLI
  2. Exercices

Exercices

Exercice 1

  1. In a directory, create the following files: annee1 Annee2 annee4 annee45 annee41 annee510 annee_saucisse banane

  2. Create a year directory and move all the previous files in the year directory.

  3. List all the files that:

    • end by 5
    • start by annee4
    • start by annee4 and has 7 letters maximum
    • start by annee with no numerical number
    • contains ana
    • start by a or A
  4. Copy the files whose second-to-last character is either 4 or 1 in the /tmp directory in a single command

Exercice 2 - Grep

  1. Create a directory called essai-grep in your home directory. In this directory, create the following files:

tomate poire pomme cerise Fraise fraise courgette POMME3 afraise

Edit the files (output of the ‘ls’ command redirected to ‘grep’) with the following criteria based on their names:

  • Criterion 1: The name must be “Fraise” or “fraise”.
  • Criterion 2: “se” is at the end of the name.
  • Criterion 3: “ai” is present in the name.
  • Criterion 4: Name contains a numeric digit.
  • Criterion 5: Name contains the string “mm” or “MM”.

Exercice 3 - Find

  1. Search for files in the entire directory tree:

    • Whose names end with “.c” and redirect errors to the /dev/null file.

    • Starting with X or x.

    • Whose names do not contain any digits.

  2. Search for files in the /usr directory whose size exceeds 1MB (2000 blocks of 500KB) and whose permissions are set to 755 (-rwxr-xr-x).

  3. Count the number of files in the entire directory tree that belong to you and have permissions set to 666 (-rw-rw-rw-).

Exercice 4

  1. Create 10 files .tar.gz in one line

  2. Write a script that renames the *.tar.gz to *.tar.gz.old

12-DataFrame
Solutions
 

Copyright 2023, Clément Bernard