Outils pour utilisateurs

Outils du site


issue132:c_c

I’ve frequently written articles on tools and websites that I find useful in my work life. However, it has been a long time since I focused on CLI tools. As such, I thought it would be good to revisit this topic and share an up-to-date list of commands that I find myself using almost every day. dig Dig is a tool which lets you pull in DNS information about a particular domain. This is extremely helpful when you’re migrating websites (to see if the error is an error or the DNS not having updated yet), and is also a troubleshooting step I like to use when I have no internet access, as occasionally the issue is with the DNS and not the actual connection. dig @8.8.8.8 google.com The @ indicates what DNS server it should use - omitting this will use your default DNS.

J'ai fréquemment écrit des articles sur les outils et les sites Web que je trouve utiles pour ma vie professionnelle. Cependant, il s'est passé longtemps depuis que j'ai ciblé les outils en ligne de commande (CLI), de sorte que j'ai pensé qu'il serait bien de revisiter ce sujet et de partager une liste à jour des commandes que j'utilise moi-même presque quotidiennement.

dig

Dig est un outil qui vous permet d'extraire des information DNS sur un domaine particulier. C'est extrêmement utile quand vous migrez des sites Web (pour voir si une erreur est une erreur ou seulement que le DNS n'a pas encore été mis à jour) ; et il a aussi une partie de recherche de panne que j'aime utiliser quand je n'ai pas d'accès à Internet, car, parfois, le problème est dans le DNS et pas dans la vraie connexion.

dig @8.8.8.8 google.com

Le @ indique quel serveur DNS il faut utiliser, sans cela, il utilisera votre DNS par défaut.

time If you’re a programmer or just someone who uses the CLI a lot, you may occasionally notice a command taking a long time to complete. When this happens to me, I like to run it through time to get a value for the duration of the command, and tweak settings as I compare the numbers. time <command> Replace “<command>” with the actual command you want to run. It will return 3 values - real, user, and sys. You are typically interested in the “real” value. ping Most likely, everyone already knows this command - but if you’re looking for a domain’s IP, or just checking whether or not something responds, this is a tool I use every day. If Ping indicates to me that one domain isn’t responding while another is, then I’ll move onto something like downforeveryoneorjustme.com ping www.google.com

time

Que vous soyez un programmeur, ou juste quelqu'un qui utilise beaucoup la CLI, vous pouvez noter occasionnellement qu'une commande prend beaucoup de temps pour se terminer. Quand ça m'arrive, j'aime la lancer sous time pour obtenir une valeur de durée de la commande et régler les paramètres quand je compare les chiffres.

time <command>

Remplacez <command> par la vraie commande que vous voulez lancer. Elle retournera 3 valeurs - real, user et sys (réelle, utilisateur et système). Vous êtes en général intéressé par la valeur « real ».

ping

Très probablement, tout le monde connaît cette commande, que vous cherchiez l'IP d'un domaine, ou, simplement, que vous vouliez vérifier si un truc répond ou non ; c'est un outil que j'utilise tous les jours. Si Ping m'indique qu'un domaine ne répond pas alors qu'un autre le fait, j'irai voir quelque chose comme downforeveryoneorjustme.com

ping www.google.com

lynx Lynx is a CLI-based browser. While this isn’t a tool I use too frequently, it can be useful if you want a text-based display of a site (eg, a tutorial), or if your X Server won’t start and you need to google something without the aid of another device. tmux A few months ago, I switched from two monitors to a single ultra wide display. Previously I’d dedicate a single monitor to my terminal, but nowadays I have to split my display in order to have a comfortable size browser and terminal. While I can use i3 to vertically/horizontally split my windows, I sometimes want to have what is essentially a “tabbed” terminal - full height, about 33% of the width, and yet have multiple terminals running. This is where tmux comes in - I start a session, run a command, and then create a second one I can switch between. This also has the added benefit of securing my sessions against accidental closure - while I was getting used to having only one display, I’d occasionally close the wrong window. With tmux I simply need to attach to the session from a new terminal window. It’s also a great way to run a process in the background while giving yourself the option of connecting to it later (see example below).

lynx

Lynx est un navigateur en ligne de commande. Bien qu'il ne soit pas un outil que j'utilise fréquemment, il peut être utile si vous voulez un affichage texte d'un site (par ex. un tutoriel), ou si votre serveur X ne démarre pas et que vous avez besoin de faire une recherche sur Google sans l'aide d'un autre dispositif.

tmux

Il y a quelques mois, je suis passé de deux moniteurs à un seul avec un affichage ultra-large. Avant, j'avais dédié un seul écran à mon terminal, mais, actuellement, je dois diviser mon affichage de façon à disposer d'un navigateur et d'un terminal de tailles confortables. Alors que je peux utiliser i3 pour découper horizontalement/verticalement mes fenêtres, je veux parfois avoir ce qui est en gros un terminal « à onglets », pleine hauteur, 33 % environ de la largeur et avec de nombreux terminaux en train de tourner. C'est là qu'arrive tmux : je démarre une session, lance une commande, puis j'en crée une seconde dans laquelle je peux passer. Ceci a aussi l'avantage additionnel de sécuriser mes sessions contre des fermetures accidentelles ; pendant que je m'habituais à un affichage unique, j'ai fermé parfois la mauvaise fenêtre. Avec tmux, je dois simplement relier une nouvelle fenêtre de terminal à la session. C'est aussi un bon moyen de lancer un processus en arrière-plan tout en gardant l'option de s'y connecter plus tard (voir l'exemple ci-dessous).

tmux -d -s “Session Name” <command> The example creates a detached (hidden) session using the given command and session name. If you then want to check the output for errors (for example), you simply need to run the tmux attach command (and indicate the ID of the detached session). grep or find Very often, I’ll have some configuration files, or small text files with notes or fixes I’ve hastily typed up. When looking for the correct files, I almost always use grep (or find). Grep is used to check the contents of a file, while find can be used to search for files by name, type, etc. You can also combine the two commands by executing a grep search on all results returned by find (see example below).

tmux -d -s “Session Name” <command>

L'exemple crée une session détachée (cachée) en utilisant la commande et le nom de session indiqués. Ensuite, si vous voulez vérifier les erreurs en sortie (par exemple), vous avez juste besoin de lancer la commande tmux attach (et indiquer l'identifiant de la session détachée).

grep ou find

Très souvent, j'aurai des fichiers de configuration, ou des fichiers texte avec des notes ou des résolutions de problèmes, que j'ai tapés rapidement. Quand je cherche les bons fichiers, j'utilise presque toujours grep (ou find). Grep est utilisé pour vérifier le contenu d'un fichier, alors que find peut être utilisé pour chercher des fichiers par nom, type, etc. Vous pouvez aussi combiner les deux commandes en exécutant une recherche grep sur tous les résultats retournés par find (voir l'exemple ci-dessous).

find . -name “*.py” -exec grep -H “searchterm” {} \; The above command searches all python files in the local directory and subfolders for the word “searchterm”. The -H flag tells grep to list the file name, so you can actually know what file it is you’re looking for. You can adjust any of the parameters as necessary. killall Also a command that most people probably know. It takes the name of an application, and kills all instances of it. Very useful if something isn’t responding, or there is no official way to stop it.

find . -name “*.py” -exec grep -H “searchterm” {} \;

La commande ci-dessus cherche le mot « searchterm » dans tous les fichiers python dans le répertoire local et ses sous-dossiers. Le commutateur -H dit à grep de lister les noms de fichiers de sorte que vous pouvez vraiment savoir quel fichier vous cherchez. Vous pouvez régler chacun des paramètres si nécessaire.

killall

Encore une commande que tout le monde connaît probablement. Je donne le nom d'une application et il tue toutes ses instances. Très utile quand quelque chose ne répond pas ou qu'il n'y a pas de moyen officiel de l'arrêter.

<command1> && <command2> Not really a command, but a feature of the Linux Shell that I use all the time. It essentially says “if command1 completes successfully, run command2”. I use this a lot when developing, since I sometimes have a build process that happens in two steps. This is also related to “||”, which runs the second command only if the first one fails (logical or). Also related to “;” which just means “run command 2 after command1”. mkdir -p This is simply an additional argument to mkdir, which creates any folders along the path if they don’t exist. So, if you tell it to create ~/test-documents/university, but test-documents doesn’t exist, the command will fail with a “no such file or directory”. But, with -p, it will just create the missing folders. Very useful when combined with the next (and final) tip. {item1,item2,item3}

<command1> && <command2>

Ce n'est pas vraiment une commande, mais une fonctionnalité du Shell de Linux que j'utilise tout le temps. Elle dit en gros « quand la commande 1 est terminée, lancer la commande 2 ». Je l'utilise souvent en développant, car j'ai parfois un processus de compilation qui se passe en deux étapes. Ceci est aussi apparenté à « || », qui ne lance la seconde commande que si la première échoue (ou logique). Apparenté aussi à « ; », qui signifie simplement « lancer la commande 2 après la commande 1 ».

mkdir -p

C'est juste un argument complémentaire pour mkdir, qui crée tous les dossiers d'un chemin quand ils n'existent pas. Ainsi, si vous lui dites de créer ~/test-documents/university, mais que test-documents n'existe pas, la commande échouera avec un « pas de fichier ou de répertoire correspondant ». Mais avec -p, elle créera les dossiers manquants. Très utile quand elle est combinée à la commande suivante (et dernière), tip.

{item1,item2,item3}

This is a convention that Bash and most other shells allow. It is essentially a list of options that it cycles through one by one. Combining it with the mkdir command from above, something like this is possible: mkdir -p ~/taxes/{2017,2018}/{receipts,forms} The command would create the folders 2017 and 2018 in the folder taxes. Each year would also contain the folders “receipts” and “forms”. The key thing here is to avoid using spaces around the commas. If you’re using spaces in the items, be sure to escape them or to enclose the items in quotes. I hope this list introduces you to a few new commands or shell tricks. If you know of a tool or a trick that I haven’t covered that you can’t live without, feel free to let me know about it via email. As always, I can be reached at lswest34+fcm@gmail.com.

C'est une convention que Bash et la plupart des shells autorisent. C'est en gros une liste d'options qui sont parcourues l'une après l'autre. Combinée avec la commande mkdir ci-dessus, quelque chose comme ceci est possible :

mkdir -p ~/taxes/{2017,2018}/{receipts,forms}

La commande créera les dossiers 2017 et 2018 dans le dossier taxes. Chacune des années contiendra aussi les dossiers « receipts » et « forms ». Le point clé ici est d'éviter d'utiliser des espaces autour des virgules. Si vous utilisez des espaces dans ces éléments, assurez-vous de les sauter ou de les enfermer dans des guillemets.

J'espère que cette liste vous a présenté quelques nouvelles commandes ou astuces du Shell. Si vous connaissez un outil ou une astuce dont je n'ai pas parlé, sans laquelle vous ne pourriez vivre, n'hésitez pas à me le faire savoir par mail. Comme toujours, je peux être joint à lswest34+fcm@gmail.com.

issue132/c_c.txt · Dernière modification : 2018/05/02 19:19 de auntiee