The Linux terminal is something with many more features than you can imagine, there are several curious things that you can do through it, from listening to music and watching videos up until some less useful things, but still fun.
We we prepared for you a special Bash course for you to be a ninja at the terminal, but that doesn’t mean that all the tips have ended, quite the contrary, here are 7 more tips for you to use on your terminal and who knows, maybe a little more productivity with it.
If you want some more free video tips click here and check out Tiago’s epic journey, Canonical developer who helped us come up with the course.
Come on then, time to learn some new commands!
1 – wc (word count)
This command is for you to count how many words, characters and lines there are within a given text file, its use is very simple. If you do not pass any option, it reports the 3 counts, but you can specify whether you want only lines with -l, only words with -w or only characters with -c. Here are some examples:
wc -l /etc/hosts
wc -w /etc/hosts
wc -c /etc/hosts
2 – arecord and aplay
These are commands in the alsa-utils package that, among other things, allow you to record and play sounds directly on the terminal.
The command «arecord -f cd”By default prints on stdout * the result of the audio recording (a .wav file) from an available microphone, and this will dirty the screen with binary data, so we use bash’s redirect functionality * to play the content to a file. Note that in the example, the file created “meu_podcast” does not contain the extension .wav. This is purposeful as we will use the same file to explain the next command. See the example:
arecord -f cd 1> meu_podcast
And to play the file just use the command aplay:
3 – file
In linux, file extensions are optional, so it is not always possible to tell which type of file is by looking at its name.
For this we can use the command filet (from the package called filet on Ubuntu), which analyzes the inside of the file and tries to tell us what type it is. ex:
The result might look something like this:
meu_podcast: RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, stereo 44100 Hz
Or another example:
That will bring a result like this:
/bin/bash: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=0428e4834e687e231fa865562d32fbb64ce45577, stripped
4 – head and tail
These are commands to respectively list the first and last lines of a file, or the content received in standard input (stdin *). Head comes from the English “head” and tail «tail».
The -n parameter indicates the number of lines. If the -n parameter is not passed, the commands assume that there will be 10 lines.
head -n 5 /etc/hosts
tail -n 2 /etc/hosts
The following command shows how the head it’s the tail can be used in a more complex example, such as in a bash pipeline *.
ps aux | tail -n 7
5 – du
The “du” command helps us to find out how much space a directory / folder is taking up on the disk.
But for it to be really useful you need some extra options.
The following command allows “du” to create a summary of each of the directories at the root of the system. This of course can take a while, after all it will go through the entire disk and generate a summary in megabytes.
sudo du -m --max-depth=1 /
Let’s assume that you discover that the / home directory is taking up a lot of space, so you can start a real “witch hunt” and look for the directory that is stealing your disk space:
sudo du -m --max-depth=1 /home
And so on.
6 – lime
The “cal” command shows us a calendar for the current month right on the terminal:
The output will look something like this:
But the cal command can also show the full year calendar with the -y command.
Showing the current year:
Showing some other year:
cal -y 2017
Enjoy the trip and see what day of the week your birthday falls next year.
7 – history
The command history is an internal command in bash. (builtin *). It is used to print previous commands already executed on the command line.
It is basically a history that Bash maintains, just as browsers store the websites you have already visited.
If you are not familiar with these command line terms (stdin, stdout, pipeline, builtin, redirects, etc.) and want to learn more about the terminal and the Bash interpreter (which is the Linux standard, regardless of the distro), see this presentation of the course dominating the Linux terminal, where we spent 3 more command line tips that will make your life easier.
Want more tips? Have video forty minutes on our channel about it, check it out.
To the next!