Mount a disk – Linux – cmd

To mount a disk (usually a file system that you usually go and click on using nautilus/caja (file browsers)) from the command line, use the following,

udisksctl mount -b /dev/disk/by-label/

Listing the content of /dev/disk/by-label/ will give you the names of the mountable disks/drives. Usually flash drives are mounted automatically so they do not have to be mounted. Unless you unmount it and want to mount it again. Use man udisksctl for more information. Also, I think it is udisks in some distributions.

Advertisements

Wget – Download from a list

If everyone started to read the manual then bloggers like me would…. eh no… I would still blog even if no one reads this.

This is pretty simple but it is really nice and may inspire you to investigate more. If you have a list of links to download all you have to do is put them all in a text file. One in each line. Then fire up wget from the terminal like this

wget -i path/to/textfile

 

This will download all of those files one by one and save it in the present working directory. Really good if you already have a list of links to download. Or if you have a set of links to download from on  the same page you can use some download plug in like downthemall on firefox.

You can use wget to do a lot lot more. Read the manual. You can use wget on bash scripts as well, since it is a command line tool. Imagine the possibilities. You could write a bash script with regex to get all files with certain patterns from a particular location. I once downloaded a full website containing more than a 1000 html pages with wget, and it was really good. But that was simple. Not much scripting involved though. You just have to look for the proper parameters to use with wget.

Get rid of the FAT(32)

Here is one good reason why you can stop using FAT32 file format for your drives.

The Story: I have been using computers since around 2000. I started out with windows 98 first of all and I have grown up using FAT32 for a very long time. When NTFS came in, right about when windows NT came in i guess? I am not sure, I never bothered to know what it was about and I continued using FAT32 on all my data drives till now. Although my C drive may have been in the new NTFS format, I was still using FAT32 for the other drives without realizing what I was doing. Then I switched to Linux where it was ext4. So for a lot of years NTFS and FAT32 did not bother me.

The Crux: Calamity struck now after so many years. I was trying to download an 8GB zip file containing a database and the downloads kept stopping at 4GB. A little investigation, and I came to know that the maximum file size in a FAT32 drive is only 4GB. Gladly, my trust wget command line downloader gave me a perfect error to search for. The only way out of this was to have an NTFS or ext4 drive. Maybe I would just go for ext 4. I dont see myself adding/installing windows anytime in the future on my laptop.

A good job for tomorrow. Backup everything on an external hard drive, format my hard disk, put it all back again.


Thu Oct 5 14:10:16 IST 2017: Related update here

Screen Record, on Linux

This is a quick way to make a tutorial or how-to video for someone. On my fedora, I already had this command line app called, recordmydesktop and it works well.

All you have to do is head to the command line and say recordmydesktop test.ogv. This will record the screen and save it to a file called test.ogv. To end recording, you can hit Ctrl + c.  It takes some time to process the file and save it. You might see something like the image below.

record

There a lot of options, including ways to specify an area of the screen to record and things like adding a short delay before it starts recording. Check out the man page (man recordmydesktop) for more details.

This records in OGV format. But you can quite easily convert it to an mp4 file, if you’d like, with ffmpeg or some other conversion software. With ffmpeg, use the following command.

ffmpeg -i test.ogv -c:v libx264 -preset veryslow -crf 22 -c:a libmp3lame -qscale:a 2 -ac 2 -ar 44100 output.mp4

I’m not sure if this is default or it got installed along with some other package. Anyway, installation is as simple as, dnf install recordmydesktop, as a root user. Happy recording.

LF, CR, CRLF – Pressing Enter

Story (Skip it if you don’t have time)

I had a tough time once when i was processing text. I usually work on linux machines. I got this text file that was made on a windows machine and I was going to process it. The process involved adding a few characters at the start of every line. To do this. The usual thing to do is to replace ‘\n’ with ‘\nabc’ assuming abc are those characters to be placed at the beginning of every line.  This just did not work on this particular file that i received. It was only after i used a tool that displays every single character on the file that i realized that text made on windows machines add something called a carriage return ‘\r’, along with the line feed character ‘\n’. Thus the need for a post.

TL;DR Start reading from here..

So all this goes long back to the age of the typewriter. LF stands for Line Feed. It would just move the paper up by a line space and keep the same horizontal position. CR on the other hand stands for Carriage Return and moves to the start of the line on the same line.

So intuitively it seems that the windows people have got this right. Because CR and LF would move the pointer to the start of the next line. But is it necessary in the current age? That is another question. On linux, only the line feed character is used. On Mac, only the carriage return character is used.

The ASCII codes are given below,
CR = \r = ASCII code 13
LF = \n = ASCII code 10
CRLF = \r\n = ASCII code 13 and then ASCII code 10

Keep this in mind when you are processing text files originating from these operating systems.

Thanks for reading.