I used to deal with some debian-based linux distributions including (Ubuntu, Biolinux, Linux-mint) and one of the most powerful features that had been always found fascinating me in linux is the terminal.
I missed this feeling in Windows, I missed this black screen and little blinking cursor, after using Linux for a while I thought I’m a genius just because I wrote my first command in the Terminal, especially when you know it was:
ls -alh
:D, anyway, in this post I decided to collect most of these commands that I use frequently, because searching Google for them every time has turned really exhausting, let’s get started!
1- I want to delete this directory and its sub files/folders!
I don’t need to say that this line saved my time a lot:
rm -rf directory-name-here
2- Copy all files and folders from directory to another
With also some good parameters like updating the old files with new ones, verbose mode, recursively go inside every sub-directory, use this magic:
cp -fiRuv /source/* /destination/
One useful hint there, you can use this copy command generator.
3- Useful trick for a VPS!
When I purchased my own VPS, I thought how I could get benefit of this really fast internet connection speed that Digitalocean has, after lots of search I came out with this idea, using it as a VPN, and as I have two small droplets one in San Francisco and the other one in Amsterdam, it means that I have two different static IP addresses that I can surf the internet anonymously with.
First, I followed this guide to install openvpn on centos server, then to initiate the whole thing, I must enter this line in my terminal:
sudo openvpn --config ~/path/to/client.ovpn
4- Downloading torrents to my VPS
Again, let’s take advantages from this fast internet connection (I’m from Egypt if you know what I mean -_-) to download torrents on VPS, then download them on my pc using ssh or even sftp with the maximum of my internet connection speed, no delays now for looking for seeds/peers and having irregular download rate.
I followed this guide to install transmission on centos server, then just navigating to your-server-ip:9091
will initiate the web service for transmission client, of course 9091 is the default port number for transmission which can be changed.
5- Encoding video on the fly
Well, handbrake is an amazing application which is intended for encoding videos and the most amazing part of it is that it’s free 🙂
I remember one of my friends had a 2.4GB video file in wmv on his dropbox, and he wanted to get it on his local PC in just 5 minutes, although this can be done with a fast internet connection, but again it’s really hard to get such one here..
So, I figured out this trick, converting the video file on the fly to a smaller mp4 file size will definitely decrease the time needed to download this video without a significant lose of the video quality, so that was what we have done:
- Downloading the video from my friend’s dropbox to my VPS (takes only minutes)
- Running Handbrake on my server using this line:
/HandBrakeCLI -i ~/Desktop/my_original_file.wmv -o ~/Desktop/my_new_file.mp4 --encoder x264 --vb 1800 --ab 128 --maxWidth 640 --maxHeight 480 --two-pass --optimize;
and voila! it really did the trick, and for more information about this command parameters, it is really worthwhile to check Jay Robinson’s blog post.
6- Transferring files/folders using resync from different servers
This line will do the trick, even with a custom SSH port:
rsync -avz -e "ssh -p XXXX" user@server.com:/path /local_path
Another command using tar (much more faster):
tar -c /path_to files_you_need_to_copy | ssh -i "/path_to_rsa_key" your_user@your_new_host 'tar -xvf - -C /path_to_the_new_host'
P.S. this post will be updated every time I find any useful terminal command.