Outils pour utilisateurs

Outils du site


issue132:c_c

Ceci est une ancienne révision du document !


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.

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

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).

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).

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.

<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}

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.

issue132/c_c.1525093351.txt.gz · Dernière modification : 2018/04/30 15:02 de d52fr