issue219:tutoriel1
Différences
Ci-dessous, les différences entre deux révisions de la page.
issue219:tutoriel1 [2025/07/17 18:04] – créée philou511 | issue219:tutoriel1 [2025/07/30 06:51] (Version actuelle) – d52fr | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
+ | **In this issue, I wanted to dive into startup files, but let’s take a step back and look at files in general. (Yes, I know I’m squirreling, | ||
- | In this issue, I wanted to dive into startup files, but let’s take a step back and look at files in general. (Yes, I know I’m squirreling, but it is an odd and interesting one.) We all use files, but rarely think about them. We can have a file in a folder or a file pointing | + | In this article, we will look at the ‘readlink’ and ‘dirname’ commands, and how they can be used to obtain the absolute path of a relative path, and the directory containing |
- | In this article, we will look at the ‘readlink’ and ‘dirname’ commands, and how they can be used to obtain the absolute path of a relative path, and the directory containing a path; I dare you to say that three times in a row, as fast as possible! If you want to see it in action, see: https:// | + | Dans ce numéro, je voulais me plonger dans les fichiers de démarrage, mais prenons un peu de recul et examinons les fichiers en général. (Oui, je sais que je fais des provisions, mais c'est un sujet étrange et intéressant.) Nous utilisons tous des fichiers, mais nous y pensons rarement. Il peut y avoir un fichier dans un dossier ou un fichier pointant vers un autre fichier dans un autre dossier. Cet article concerne uniquement bash, car je ne sais pas si cela est valable pour tous les shells. Je ne veux pas embrouiller les débutants, alors suivez-moi ; cela paraîtra confus, mais vous en sortirez avec une meilleure compréhension, |
- | How do we get an absolute path you may ask? Well, to obtain the full path of a file, we use the ‘readlink’ command. Typing ‘readlink’ prints the absolute path of a symbolic link, but, as a side-effect, | + | Dans cet article, nous allons examiner les commandes « readlink » et « dirname », et comment les utiliser pour obtenir le chemin absolu d'un chemin relatif, et le répertoire contenant un chemin ; je vous mets au défi de le répéter trois fois de suite, le plus vite possible ! Si vous voulez le voir en action, voir : https://stackoverflow.com/questions/3373132/get-the-name-of-the-directory-where-a-script-is-executed |
- | We will be discussing it at a slightly different level or perspective, | ||
+ | **How do we get an absolute path you may ask? Well, to obtain the full path of a file, we use the ‘readlink’ command. Typing ‘readlink’ prints the absolute path of a symbolic link, but, as a side-effect, | ||
- | Now let us set the stage, we will use readlink on a symbolic | + | We will be discussing it at a slightly different level or perspective, |
+ | Now let us set the stage, we will use readlink on a symbolic file, like so: | ||
The readlink command works only if you have the full path; that is a given, as it cannot find a file that does not exist. | The readlink command works only if you have the full path; that is a given, as it cannot find a file that does not exist. | ||
Ligne 17: | Ligne 19: | ||
If you were to use ‘find’, it would not tell you that the turquoise file above is a symbolic link and would return: | If you were to use ‘find’, it would not tell you that the turquoise file above is a symbolic link and would return: | ||
+ | |||
+ | edd@gift:~$ find $PWD -name " | ||
+ | / | ||
+ | |||
+ | Comment obtenir un chemin absolu ? Pour obtenir le chemin complet d'un fichier, on utilise la commande « readlink ». Taper « readlink » affiche le chemin absolu d'un lien symbolique, mais aussi, comme effet secondaire, le chemin absolu d'un chemin relatif. (Cela vous semble-t-il un peu confus ?) À ce stade, saisissez : | ||
+ | |||
+ | Nous allons aborder ce sujet sous un angle légèrement différent, si vous le voulez bien. Si vous souhaitez simplement trouver votre fichier avec son chemin complet, je vous suggère de rechercher comme dans l' | ||
+ | |||
+ | Plantons maintenant le contexte : nous allons utiliser readlink sur un fichier symbolique, comme dans l' | ||
+ | |||
+ | La commande readlink ne fonctionne que si vous avez le chemin complet ; C'est une évidence, car il est impossible de trouver un fichier qui n' | ||
+ | |||
+ | La page de manuel indique : -f, --canonicalize, | ||
+ | |||
+ | Si vous utilisiez « find », | ||
edd@gift:~$ find $PWD -name " | edd@gift:~$ find $PWD -name " | ||
/ | / | ||
- | Now I will be honest; before researching this for the article, I thought, and will remember it this way forever, that the -f flag was for “follow” as in follow the full path. | + | |
+ | **Now I will be honest; before researching this for the article, I thought, and will remember it this way forever, that the -f flag was for “follow” as in follow the full path. | ||
Anyway, moving forward, dirname is a command I never used directly, as it had no point (sort of like the ‘basename’ command). It is useful in scripts though. See the following example to get an understanding of what it does: | Anyway, moving forward, dirname is a command I never used directly, as it had no point (sort of like the ‘basename’ command). It is useful in scripts though. See the following example to get an understanding of what it does: | ||
- | |||
It gives you the directory, containing your directory. But(!), if I am in a folder and I want to check the directory name of a symbolic link, it starts to get interesting. | It gives you the directory, containing your directory. But(!), if I am in a folder and I want to check the directory name of a symbolic link, it starts to get interesting. | ||
- | |||
OK, you now know what both commands do, let’s combine them. | OK, you now know what both commands do, let’s combine them. | ||
- | |||
We can also do it another way: | We can also do it another way: | ||
+ | Guys, I apologise for all the screenshots, | ||
+ | As we played around, we realised that files and symbolic links behave a bit differently at the command prompt. The ‘tree’ command can be a useful way to visualise your directory. ** | ||
- | Guys, I apologise for all the screenshots, but I need to show things like back ticks, that just do not work in Abiword. | + | Pour être honnête, avant de faire des recherches pour cet article, je pensais, et je m'en souviendrai toujours, que l' |
- | As we played around, we realised that files and symbolic links behave a bit differently at the command prompt. The ‘tree’ command can be a useful way to visualise your directory. | + | Quoiqu' |
+ | Elle vous indique le répertoire contenant votre répertoire. Mais (!), si je suis dans un dossier et que je veux vérifier le nom du répertoire d'un lien symbolique, cela devient intéressant (voir l' | ||
- | Now I want you to notice that the symbolic link points to another folder, but that folder was not the absolute path. | + | OK, vous savez maintenant à quoi servent les deux commandes ; |
+ | |||
+ | On peut aussi procéder autrement (au milieu à droite). | ||
+ | |||
+ | Excusez-moi pour toutes les captures d' | ||
+ | |||
+ | En essayant, nous avons réalisé que les fichiers et les liens symboliques se comportent un peu différemment à l' | ||
+ | |||
+ | |||
+ | **Now I want you to notice that the symbolic link points to another folder, but that folder was not the absolute path. | ||
Wiggle your eyebrows, do you ‘get’ it? Do you see how it may be useful to get an absolute path for a script? | Wiggle your eyebrows, do you ‘get’ it? Do you see how it may be useful to get an absolute path for a script? | ||
Ligne 54: | Ligne 81: | ||
Please try it out, by copying a symbolic link to your home folder somewhere and try the above. | Please try it out, by copying a symbolic link to your home folder somewhere and try the above. | ||
- | If I made a mistake anywhere, misc@fullcirclemagazine.org as we are all human. | + | If I made a mistake anywhere, misc@fullcirclemagazine.org as we are all human.** |
+ | |||
+ | Je voudrais maintenant que vous remarquiez que le lien symbolique pointe vers un autre dossier, mais que ce dossier n' | ||
+ | |||
+ | Remuez les sourcils, vous comprenez ? | ||
+ | |||
+ | C'est d' | ||
+ | |||
+ | Maintenant, mettons un grain de sable dans l' | ||
+ | |||
+ | Il existe évidemment d' | ||
+ | |||
+ | Essayez en copiant un lien symbolique vers votre dossier personnel quelque part et en essayant ce qui précède. | ||
+ | |||
+ | Si j'ai fait une erreur, envoyez un e-mail à misc@fullcirclemagazine.org, | ||
issue219/tutoriel1.txt · Dernière modification : 2025/07/30 06:51 de d52fr