Terminal Internet tools.
Nick Peers browses the web, collects email, downloads files and gets a weather forecast without leaving the shell.
Nick Peers browses the web, collects email, downloads files and gets a weather forecast – all without leaving the shell.
Why on earth would you want to access the web or read email in the Terminal when there are so many desktop-friendly tools out there? The answer may not be obvious when you’re in the comfortable surroundings of your desktop, but the tools in this project could all prove their worth the next time you’re unable to get further than the shell (or don’t want to log in to the desktop just to check your email or browse a web page).
Browse with Links
Let’s start with giving you access to the web. One option is Links – we’ve picked the Links2 variant, because it supports graphics, so install it with: $ sudo apt install links2
Once installed, launch it in text-only mode ( links2 ) or graphics mode ( links2 -g ). Text-only mode opens in your current Terminal window; graphics mode opens in a separate window only if a supported graphical system is in place, namely your desktop. In either case, a blank screen appears with a cursor – press Esc to bring up the menu bar, then use the mouse (graphics mode only) or cursor keys and Enter to navigate and select items. Alternatively, familiarise yourself with the core keyboard shortcuts, the most important of which is g. Press this and you’ll see the Go to URL box pop up, then just type the web address you want to view – you don’t need to enter ‘http://’ – and hit Enter.
Links then connects to the site – if in text-only mode, scroll down with the cursor keys and look for accessibility links that skip navigation to take you directly to the content. When you spot a link, press Enter to follow it, and use the z and x keys to navigate backwards and forwards respectively.
You can press / to search for specific content within the page, pressing n to jump to the next hit, or N to go to the previous one. Links doesn’t display images by default, but you can see where they appear in a page via the View > HTML Options menu – check both Display Links to Images and Display Image Filenames to locate them. You can then download images to your PC for viewing later.
Links comes with a comprehensive manual, so select Help > User’s Manual to take a look at what it’s capable of.
An alternative browser
If Links doesn’t float your boat, try w3m. It has one crucial advantage over Links: the ability to display web images from inside the shell. To gain this functionality, install the w3mimg variant ( sudo apt install w3m-img ). Then, use it thus: $ w3m news.bbc.co.uk Use the cursor to navigate, hit Enter to visit hyperlinks and – if you installed w3m-img – you’ll see images inline as you scroll, while text is colour-coded to aid navigation.
Get files using FTP
You can use wget (seetheboxtop-right) to retrieve files via FTP, but it’s one-way only and a better option comes with Linux. Type ftp and hit Enter to get started. The cursor changes to ftp> so type the following to connect to a remote server: ftp> open ftp.example.com
You’re prompted to enter a username and password if required. Use the same commands you use to navigate your filesystem – cd for changing directories, ls to list directory contents and so on. Type get filename to download a file to the directory you were in when you invoked ‘ftp’ or put filename to upload it from the same directory.
Type help for a list of supported commands, and if ‘ftp’ isn’t powerful enough, try ncftp ( sudo apt install ncftp ).
Send email
Email isn’t the simplest thing to set up via the Terminal, but it is possible. Start by installing mailutils:
$ sudo apt install mailutils
You’re prompted to set up Postfix during installation: choose Internet Site from the options. Leave the system mail name as it is, and click OK to complete the installation.
From here, you can use the built-in tools, like mail, but additional configuration is required. If you only want to send email from the Terminal, a simpler option is to install ssmtp: $ sudo apt install ssmtp $ sudo nano /etc/ssmtp/ssmtp.conf There’s a full configuration guide at https://wiki.debian. org/sSMTP – note the security implications of storing your email password in a plain text file – or if you’re a Gmail user, you can uncomment the FromLineOverride=YES line by deleting the # character, then add the following beneath it: AuthUser=yourname@gmail.com AuthPass=yourpassword mailhub=smtp.gmail.com:587 UseSTARTTLS=YES
If you’ve got two-step verification enabled for Gmail, you need to generate an app password via Account > Sign-in & Security > Signing in to Google > App Passwords, then use that. Finally, you need to change the line root=postmaster to read simply root= .
Once done, save the file and quit nano, then use the mail command to actually send email through ssmtp: $ mail recipient@email.com
You’re prompted to enter CC addresses, then a subject, and finally the body of your email. Hit Enter to move on to the next line, then finally press Ctrl+D to send the message.
Read emails
What if you want to read email as well as send it? Many command-line tools are complex to configure – and basically overkill for those who aren’t running an email server – but thankfully there’s one self-contained tool that’s relatively easy to set up: alpine ( sudo apt install alpine ). Once installed, launch it by typing alpine , and hit Enter.
Alpine creates a mail folder for you, then launches to a welcome screen. Press e to exit, then press s followed by l. With Mail selected, press Enter. You can configure multiple mail accounts here, so use the nickname field to differentiate between them.
The critical field is Server – this needs to follow the following syntax (this is based on using Gmail, so adapt for your own particular email provider): imap.gmail.com/ssl/user=yourname@gmail.com By default, the mail is stored in the main /home/mail folder, but you can divert it to a subfolder if you wish. Leave the View field blank, then press Ctrl+X to save. You’re prompted to enter your email password, then press y if prompted to create the mail subfolder and exit. Return to the setup screen, but now press c to access the configuration screen. Enter the following in the SMTP path: smtp.gmail.com/novalidate-cert/user=yourname@gmail.com/ ssl Now enter the following into the Inbox path: imap.gmail.com/novalidate-cert/ssl/user=yourname@gmail. com When prompted, type INBOX and hit Enter. Return to the main screen, then exit Alpine by pressing q followed by y. Open Alpine again and – after entering your password – you should see Alpine open your inbox and inform you as to its contents. Press l and hit Enter to view all your messages. Visit www.washington.edu/alpine/ to find out more about Alpine, and www.sjwrc.com/guides/alpine-andgmail/ – the latter resource focuses on Gmail, but includes a general primer and some handy tips, such as being able to store your password in a file to save having to enter it each time you launch Alpine.