Taking a screenshot in command-line is very easy using the import tool, which is included in the ImageMagick suite. To take a screenshot of a single window use:
To take a screenshot of a single window and include window decorations, use:
To take a screenshot of the entire screen or a region, type:
And then select with the mouse the region which you want to save.
To mount an ISO image, we’ll first create a mount point (an empty directory) and then we will use the mount command:
pidof is a command which will return the PID of the process specified as argument. To kill an application we would use:
The first one kills Amarok, while the second one kills Firefox.
For this one we will use a tool called nrg2iso:
wc is a command-line tool which returns the number of lines, words or characters in a file, depending on which parameter we specify at the command-line. To count the number of lines:
To count the number of words:
And to count the total number of characters:
For this one we’ll need conver, a tool which comes included with ImageMagick. convert allows to convert between various image formats, and apply tons of effects to images. Here’s an example on resizing an image:
Which will resize an image to 30% keeping its aspect ratio.
This is a way of converting Matroska Video files to AVI with mencoder:
We will use genisoimage for this one. Here’s how to create an ISO 9660 image from a directory, keeping that directory as root:
And to create an image from several files, without including a root directory:
First, to see what ports are opened on your system use nmap:
This will output a list of open ports and the protocol currently using them. To close any of them, use the following syntax as root:
Which will close port 80, the default port used by the web server.
For this one we will need the packages cuetools and shntool, which include the tools needed to split a big FLAC or WAV when a CUE file is available. Here’s the command:
The same goes for WAV, just replace the .flac extension.
For APE files, we will first need to convert them to WAV using the mac tool, which comes in monkeys-audio package:
And then split the WAV file just like it was showed above.
indent is a tool which allows to format and change the appearance of C code by inserting/deleting whitespace characters to make the code clearer and easier to read. Some of the coding styles it supports are GNU indent style (the default, also invoked with -gnu), Kernighan & Ritchie style (invoked with -kr) or Berkeley style (invoked with -orig). The example is as follows:
Which will format source_file.c using the Kernighan & Ritchie style.
By default in Bash Ctrl+D will exit the current shell (unless used in a running application to mark end of file). To prevent this you can add the following line in ~/.bashrc:
And then source the file to read it again:
To temporarily disable the PC speaker you can remove its module from the kernel using the following command as root:
To permanently disable it, you can blacklist this module so it doesn’t load when the system starts. To do so, edit the /etc/modprobe.d/blacklist file as root and add the following line in it:
For this we will use mplayer like this:
You can eventually concatenate VOB files first, e.g.:
And then proceed and use the mplayer on the newly create output_file.vob.
For this we will need the lm-sensors package. After installing it, you will have to load several kernel modules for temperature detection (this is done automatically and you only have to agree or disagree loading the specified module). To run it, just type sensors in a terminal:
ffmpeg2theora is a frontend to ffmpeg which will allow us to convert various video files to the open format Theora video. Here’s an example:
This will convert input_file.avi to Theora video using a video quality factor of 6 and an audio bitrate of 192 kbps. Here’s another example, which will use the default settings:
Or this one, which also adds meta tags to the video:
We’ll use the ffmpeg audio and video encoder for this one:
To shrink the size of the resulting video use something like this:
To use a specific audio codec for audio output use the -acodec switch:
Aliases are a way of assigning a shorter, custom command to another single or a set of commands (or a one-liner and so on). To create aliases we can edit the ~/.bashrc file and add aliases like this:
The first one will define a new custom alias, called killfx, which will kill Firefox when used. The second one will go back to the previous working directory, while the third one will make the ls to be aliased to ls -lhXa, which shows hidden files, detailed information, human readable sizes and sorts the files according to their type.
For this one we will use the iat utility:
iat can supports many image formats, including ISO, NRG, BIN and MDF.
For converting FLAC or WAV to Vorbis or MP3 we’ll need the vorbis-tools and lame packages. To convert from FLAC/WAV to Ogg Vorbis:
Which will convert input_file.flac to Ogg Vorbis using a bitrate of 256 kbps. To convert FLAC to MP3 you will first need to convert it to WAV using flac -d input_file.flac and then convert the obtained WAV to MP3 using:
Which will use a bitrate of 192 kbps.
Have some more one-liners or tips? Please share them with us in the comments below!