pushd and popd – File Navigation Gems

pushd and popd are two commands that are absolutely worth their learning time if you are in the business of using the command line on a regular basis on linux. One of the biggest hindrances of using a command line for file manipulation and such would be navigation between folders. Sometimes its might be a pain to navigate between two folders, even using TABs for auto completion. This is where pushd and popd comes in to the picture.

What this does, in short, is, create a stack containing the paths that you have traversed using pushd. You can revisit these paths using popd. Remember that this is a stack in all aspects.

A short intro on how a stack works, if you haven’t come across it already. Skip this paragraph if you know what a stack is. Stack is a data structure that is like a stack of books or a stack of biscuits or best, pringles. You can stack one item on top of each other, but you can only take the item on top. Logical  right?. You stack an item using push. As in, pushing a potato chip into a pringles case. And you take one out using pop. Of course, you can only take the one on the top, a position called the ‘top of stack’.

Example:

Suppose you are in your home folder (~). You move to another directory by typing,

Command: pushd ~/Documents/work-docs

This will give you an output with two directory listings. The first one is the directory that you have navigated ‘to’. The second one is the directory that you just navigated ‘from’.

Output: ~/Documents/work-docs ~

You can navigate to another folder with something like say,

Command: pushd ~/Downloads

Now you will have the following output

Output: ~/Downloads ~/Documents/work-docs ~

What this shows is a history of your past navigations, or a ‘stack’ of your previous directories. The top of stack being the left most. Now to go back one step to ~/Documents/work-docs/, all you have to do is type,

Command: popd

and it will give you the following output

Output: ~/Documents/work-docs ~

That would be a quick intro of pushd and popd. Have a good time navigating through your directories.

Advertisements

Compress, Split and Join Tar files – Linux

Creating a tar file and splitting it for storing it in cds, dvds or any other storage with small capacity.

Create a tarball and compress it using bz2 or gz compression algorithms by using one of the following commands.

tar -cvjf tarofsomefolder.tar.bz2 /home/someone/Documents/*
tar -cvzf tarfileofsomeiso.tar.gz some.iso

To split you can use the split command
split -b 4500M tarofsomefolder.tar.bz2 "tarofsomefolder.tar.bz2.part"

You can use both of them together in a single command by piping the outputs of the tar command to the split command,

tar -cvzf downloads.tar.bz2 ~/Downloads/* | split -b 4500M - "downloads-part"

To extract these split tar files together, you have to cat those individual tar files either by listing them one after the other or by using a regular expression that covers all of it and then piping the output to a tar extract command. Something like,

cat downloads.tar.bz2.part* | tar -xvzf -

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.

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.

Following a Blog – RSS Feed

I am mainly creating this article so that I can send it to my friends who want a way to follow my blog easily. We will use this age old tradition of RSS. Most of us don’t even know that our browsers support something like that natively or via extensions.  RSS is Rich Site Summary. You can read more about it on the wiki page later but in short it is a subscription to a website. It helps you follow multiple sites easily. Used to be really popular long ago, but not now I guess.

Now wordpress blogs give you the option to follow a blog by email. You get notified each time a post is made. Which is awesome, but tumblr does not. We need a work around for that, without creating a tumblr account. So this blog is about that.

Firefox

There are two ways. You can either head to the RSS location of a particular website or use an option in the firefox boookmarks menu.

Bookmarks Menu

If you are using the Bookmarks menu, then this is the way.

  1. Head to the blog that you want to subscribe to. Example: beingjoys.tumblr.com or joyslearns.wordpress.com
  2. On the menu bar, look for the ‘Bookmarks’ menu and select, ‘Subscribe to this page’.
  3. You might see couple of options, choose the one that makes sense. For wordpress sites, you might get the option to subscribe to comments, which is not what you want.
  4. You will see the option to Subscribe Now.
  5. RSS are like bookmarks and are saved in the bookmarks menu. So when you subscribe, you will be asked where to save it. You can choose any place in your bookmarks. Bookmarks bar is a good place for RSS feeds. You can do this any website that gives you periodical content. You will get the updates in your bookmarks bar.
  6. You can view them in the dropdown list in the bookmarks bar or your bookmarks manager. Image shown below. As you can see. You will get an updated list of all the latest posts.

Joys Learns - Blog - RSS Feed

Chrome does not seem to support RSS. Probably because it is an age old tradition and people have moved on to apps like Feedly to subscribe to websites.

Opera has a pretty neat News app, where all you have to do is give the link to the blog and it forms a really nice interface. Image below. All I did was click on the news icon, click on add sources and entered by blog address and it was done. That was pretty neat.

Opera News

I liked the Opera method the best. You could also use some feed apps to get a richer experience across all websites and blogs.

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.