Showing posts with label Lilux OS. Show all posts
Showing posts with label Lilux OS. Show all posts

Watch Netflix on Linux with These 4 Tricks


A shiny new Linux installation is on your computer, all prepped for hours and hours of free and open source office work. But there’s something wrong. “What happened to putting the fun back into computing?” you may be asking yourself. “If only I could watch Netflix!”

Here are four ways you can watch Netflix in Linux, and the benefits and downsides of each method. In Linux, you have the power or choice, so make your pick… or choose them all!


Watch Netflix Using Google Chrome Browser

Perhaps the most popular web browser in a vast field of options on Linux, Google’s Chrome browser has been changing the way people view the web for the better part of a decade now. Up until somewhat recently, Google Chrome had only been available on Windows and Mac, but is now available on most Linux distributions and derivatives, through native binaries for Debian and Red Hat based systems, or through compiled source for distros like Arch Linux.

Why you might want to use Google Chrome Browser to watch Netflix

Installing Google Chrome is easy. It is a self contained application, which comes with the necessary available plugins baked right into the app. By installing Chrome, you can watch movies and television shows from nearly any streaming site, including Netflix and Amazon Prime Instant Video, without installing any additional software. You also have access to the vast library of Chrome extensions, the wide variety of web applications in the Chrome ecosystem, and the excellent web and JavaScript rendering engine, Blink.

Why you might want to skip using Google Chrome to watch Netflix


Google Chrome is closed source. The Free Software Foundation and the GNU Project (big names in the Linux world) believe users should be able to acquire and run software freely, while also being able to study and redistribute the underlying code. Some Linux users value the openness found in the Linux community and refuse to install closed source software and drivers.

Chrome can slow down your entire system by sandboxing every tab open and extension installed, and even running in the background after you have closed Chrome completely. This could be a deal breaker if you are running older hardware, or value snappiness from your operating system and applications.

Google. Google hoards your data like a Viking hoards treasure. For instance, if you have the auto-complete feature turned on to save time when searching the web from the address bar, that data is sent to Google. Some would call it a keylogger. You may want to steer clear of Google Chrome if you value your privacy.




Watching Netflix Using the Widevine Plugin


The Widevine plugin is an HTML5 video player developed by Google to allow streaming playback of encrypted DRM files without the use of Adobe Flash or Microsoft Silverlight. Widevine was released with support for all major operating systems, through Google Chrome, and is not officially supported on any other browser. But, due to some enterprising Arch Linux developers, Widevine has been successfully modified to run in Chromium (the open source version of Google Chrome ), and has begun being modified for use in the Firefox and Vivaldi (Opera based) web browsers.

Why you might want to use the Widevine plugin in Chromium or Firefox web browsers


The freedom of choice. Using Linux is all about the freedom to choose what software you run on your system and how that software is configured. Installing plugins which enable you to view content on the web should apply as well.

The Firefox web browser is open source. Chromium Browser is open source. Again, these browsers fall in line with the philosophy behind using Linux.

Why you might want to skip the Widevine plugin in Chromium or Firefox web browsers


Installing an unsupported plugin could have negative effects on your system. In this case, Widevine might not work correctly, or at all, leaving you with a black screen instead of a streaming movie. Additionally, browser updates or Netflix updates could be incompatible with your installed version of Widevine, forcing you to wait until someone in the Linux community uploads a new version of the plugin. While this could only take a few hours, there is no guarantee Widevine will be updated at all.



Watching Netflix Using Pipelight

Another option providing you the ability to watch Netflix and Amazon Prime Instant Video content is Pipelight. Pipelight is an open source version of the Microsoft Silverlight plugin, which Netflix used for streaming videos, and Amazon Prime Instant Video currently uses to stream video. This plugin is available for nearly all web browsers, and is usually included in the repositories for whichever Linux distro you are using.

Why you might want to use Pipelight to watch Netflix

Pipelight is readily available for nearly all major web browsers in Linux, and most of the time, just works. Pipelight works with Flash, Shockwave, Silverlight and the Unity Web Player, allowing you to stream just about any video content and play games powered by the Unity game engine, all through your web browser.

Why you might want to skip using Pipelight to watch Netflix

Pipelight is not 100% Linux code. It is actually a compatibility layer which allows you to run Windows code inside Linux, and actually requires Wine (a Windows compatibility layer application) to run at all. If you are running a slim operating system, or do not need to run additional Windows applications in Linux, you might want to steer clear of this plugin.


How to Watch Netflix Using a Virtual Machine

Another option you have to watch Netflix in Linux is through a Virtual Machine. A Virtual Machine runs a copy of Windows or OS X in a virtualized environment, allowing you to open up a native version of your chosen web browser with all the native plugins available to that browser.

Why you might want to use a Virtual Machine to watch Netflix

You have a dual boot setup installed on your computer and want to run native applications off your existing Windows or OS X installation. Your virtualization software creates a virtual machine using the hard drive partition containing your Windows or OS X installation. This is very handy if you use Linux for testing or developing software, but your OS of choice is Windows or OS X.

Why you might want to skip using a Virtual Machine to watch Netflix

Hard disk space. When installing a virtual machine, you must allocate a certain amount of physical space to your virtual hard drive. On older systems with small hard drives, this might not be an option.

Your computer must support virtualization. Some older hardware lacks the ability to virtualize machines. Most newer hardware supports this, but if you installed Linux because Windows no longer supports your hardware, you may not be able to virtualize.

While just a few years ago, watching streaming video from a Linux based operating system was difficult; today it has become easy to watch Netflix in just about any web browser. Any one of the four choices discussed will display picture perfect movies, in a matter of minutes!

Configure DHCP on RHEL 7 & CentOS 7


Step 1. Set host name and set IP Address


Keeping it simple I just used dhcp.rhg.local here. It will be likely your system will run DHCP with other services so name accordingly. To check your current hostname use the cat command on /etc/hostname
cat /etc/hostname

Use the vi command to change /etc/hostname
vi /etc/hostname

After the change is made you need to restart the network service to see the name change
systemctl restart network
cat /etc/hostname

I set the ip address at installation time but if you did not and are still on DHCP use nmtui to change it. nmtui stands for Network Manager Text User Interface.  It’s a nice easy way to update ip configurations from the command line




Remember to restart the network service after making a change
systemctl restart network

Step 2. Install DHCP Service

Here we are going to get the service installed with the yum command
yum install dhcp

After DHCP is installed, one of the next steps would be to configure it. If you did not know where the configuration files are located then you could query the RPM file it was installed from. In this example we are using RPM -qc where -qc stands for query config. This will return the files in the RPM marked as configuration. There is also rpm -qd to see documentation included with the RPM.


Step 3. Configure DHCP


So now that DHCP is installed we have to configure the range of addresses we want it to hand out. As shown in the previous step, the configuration file we want to edit is /etc/dhcp/dhcpd.conf
vi /etc/dhcp/dhcpd.conf

The above image shows an example of an ip range going form 192.168.1.50 thru 192.168.1.250. I have the same config below if you want to copy and paste and just change the parameters.

option domain-name "rhg.local";
option domain-name-servers 192.168.1.1;
default-lease-time 600;
max-lease-time 7200;
authoritative;
subnet 192.168.1.0 netmask 255.255.255.0 {
range dynamic-bootp 192.168.1.50 192.168.1.250;
option broadcast-address 192.168.1.255;
option routers 192.168.1.1;
}

Step 4. Start DHCP and configure to start at boot


Now we have DHCP configured but the service is not running. Along with starting the service we want DHCP to auto start on each boot. We will use the systemctl command to accomplish both of these. The D at the end on dhcpd is the daemon that runs the service so don’t forget the d at the end of dhcpd.
systemctl start dhcpd
systemctl enable dhcpd

Step 5. Open Firewall to DHCP requests


DHCP is running now but the firewall has to be opened to allow incoming DHCP requests. The Firewalld service is the default firewall for RHEL 7 so we will configure that to allow DHCP.
firewall-cmd --permanent --add-service=dhcp
firewall-cmd --reload

If you wanted the DHCP service to only be available to a certain network, you could do so with the below command. Please note that you would not want the firewall-cmd –permanent –add-service=dhcp command used with this because it is an allow all rule.

firewall-cmd --permanent –add-rich-rule=’rule family=”ipv4″ source address=”192.168.1.0/24″ service name=”dhcp” accept’
firewall-cmd --reload

Step 6. Verify its working


So now the test just to verify it works. I am using a Windows notebook right now so I disabled the adapter and checked it settings.


That .254 address is the DHCP server we just configured. Configure DHCP on RHEL 7!

How to Find and Remove Duplicate Files on Linux


Whether you’re using Linux on your desktop or a server, there are good tools that will scan your system for duplicate files and help you remove them to free up space. Solid graphical and command-line interfaces are both available.

Duplicate files are an unnecessary waste of disk space. After all, if you really need the same file in two different locations you could always set up a symbolic link or hard link, storing the data in only one location on disk.

FSlint

FSlint is available in various Linux distributions’ software repositories, including Ubuntu, Debian, Fedora, and Red Hat. Just fire up your package manager and install the “fslint” package. This utility provides a convenient graphical interface by default, but it also includes command-line versions of its various functions. Like many Linux applications, the FSlint graphical interface is just a front-end that uses the FSlint commands underneath.

Don’t let that scare you away from using FSlint’s convenient graphical interface, though. By default, it opens with the Duplicates pane selected and your home directory as the default search path. All you have to do is click the Find button and FSlint will find a list of duplicate files in directories under your home folder. Use the buttons to delete any files you want to remove, and double-click them to preview them.


Note that the command-line utilities aren’t in your path by default, so you can’t run them like typical commands. On Ubuntu, you’ll find them under /usr/share/fslint/fslint. So, if you wanted to run the entire fslint scan on a single directory, here are the commands you’d run on Ubuntu:

cd /usr/share/fslint/fslint
./fslint /path/to/directory
This command won’t actually delete anything. It will just print a list of duplicate files — you’re on your own for the rest.



The fdupes command isn’t usually installed by default, but it’s available in many Linux distribution’s repositories. It’s a simple command-line tool. This is probably the most convenient, quickest tool you can use if you want to find duplicate files in an environment where you only have access to a Linux command line, not a graphical user interface.

Using it is simple. Just run the fdupes command followed by the path to a directory. So, fdupes /home/chris would list all duplicate files in the directory /home/chris — but not in subdirectories! The fdupes -r /home/chris command would recursively search all subdirectories inside /home/chris for duplicate files and list them.

This tool won’t automatically remove anything, it will just show you a list of duplicate files. You can then delete the duplicate files by hand, if you like. You can also run the command with the -d switch to have it help you delete files. You’ll be prompted to choose the files you want to preserve.


Yes, we’re going to recommend dupeGuru once again. It’s an open-source and cross-platform tool that’s so useful we’ve already recommended it for finding duplicate files on Windows and cleaning up duplicate files on a Mac.

dupeGuru is a bit less convenient because it’s not available in most Linux distributions’ software repositories — although it is available in Arch Linux’s repositories. However, the dupeGuru website offers a PPA that lets you easily install their software packages on Ubuntu and Ubuntu-based Linux distributions. Users of other Linux distributions could even compile it from source.

As on Windows and Mac, dupeGuru offers three different editions — a standard edition for basic duplicate-file-scanning, an edition designed for finding duplicate songs that may have been ripped or encoded differently, and an edition intended for finding similar photos that have been rotated, resized, or otherwise modified. You can get them all from the dupeGuru website, and all three are available in the Ubuntu PPA.

This application works just as it does on other platforms. Launch it, add one or more folders to scan, and click Scan. You’ll see a list of duplicate files, and you can check them off and remove them — or move them to other platforms. You can also easily open and examine the file with a double-click.

After installation, the Ubuntu package must be launched from a command line — for example, with the dupeguru_se command for the standard edition. There appears to be no desktop shortcut installed by default. This lack of system integration is the only reason we can’t recommend this utility more highly, as it works well once you get it installed and launched.



How to Uninstall Software Using the Command Line in Linux


Linux provides different methods for installing software. You can install software from the standard Ubuntu software repositories using the Ubuntu Software Center, from outside of the standard Ubuntu software repositories, or by compiling source code. However, what if you need to uninstall a program?

If you’ve installed software from the Ubuntu software repositories using the Ubuntu Software Center, you can use the Ubuntu Software Center to uninstall that software as well. However, if you’re more comfortable using the command line, we’ll show you an easy way to see what’s installed on your system and uninstall programs.

If you have an idea of what you want to uninstall, but you don’t know the exact name, see our article about finding out exact package names in Linux. You can also use the “dpkg” command to see a list of all installed packages on your computer, press “Ctrl + Alt + T” to open a Terminal window. Type the following command at the prompt and press “Enter”.

dpkg --list

NOTE: There are two dashes before “list”.


Scroll through the list of installed packages in the Terminal window to find the one you want to uninstall. Note the full name of the package.


To uninstall a program, use the “apt-get” command, which is the general command for installing programs and manipulating installed programs. For example, the following command uninstalls gimp and deletes all the configuration files, using the “--purge” (there are two dashes before “purge”) command.

sudo apt-get --purge remove gimp

Enter your password when prompted and press “Enter”.

NOTE: The password does not display as you type it. However, you can choose to display asterisks as you type the password.


The uninstallation process begins and a summary of the actions to be taken displays. When asked if you want to continue, type a “y” and press “Enter”.


The installation process continues. When it’s done, type “exit” at the prompt and press “Enter” to close the Terminal window, or click the “X” button in the upper-left corner of the window.


If you don’t want to remove the configuration files, simply leave out the “--purge” command, as shown in the following command.

sudo apt-get remove gimp


As discussed in this article, programs installed in Linux depend on other packages to function. When you uninstall a program, there may be packages that the uninstalled program depended upon that are no longer used. To remove any unused packages, use the “autoremove” command, as shown in the following command.

sudo apt-get autoremove


You can combine the two commands for removing a program and removing dependencies that are no longer being used into one, as shown below (again, two dashes before “auto-remove”).

sudo apt-get purge --auto-remove gimp


If you’re short on space, you can use the “clean” command to remove downloaded archive files, as shown below.

sudo apt-get clean

This command removes the aptitude cache in “/var/cache/apt/archives”. When you install a program, the package file is downloaded and stored in that directory. You don’t need to keep the files in that directory. However, the only drawback of deleting them, is that if you decide to install any of those programs again, the packages would have to be downloaded again.


The “apt-get” is a handy tool that makes downloading, installing, and uninstalling programs quick and easy. For more information about using the “apt-get” command, type “apt-get” at the prompt and press “Enter”.

Understanding the Linux file system – The root partition

In this guide I am going to show you how the Linux file system is laid out and show it’s difference compared to a Windows filesystem. I am writing this assuming you primary come from a Windows background. The Mac OSX file is called Darwin and is based off of Unix the same as Linux is. The filesystems are so close in operation from Mac to Linux that it should feel like a natural fit. I will be showing the GUI file manager instead of the command line because Windows people will have experience with Explorer.

One of the first thing you should understand is the root of the filesystem. In Linux the root of the filesystem is written as / and under root is everything installed on the file system including all hard drives. In Windows there are multiple roots, each hard disk usually will have its own root filesystem written as C:\ or D:\. The C:\ in Windows is the root of hard drive used by default to install all the operating system files and programs installed on Windows. In Linux the root filesystem where everything gets installed is /. The differences are how the disk are mounted. In Linux the disk is mounted to a folder under the / filesystem. In Windows, disk get their own independent file system.

A default install of Linux has a filesystem under root that looks like this.

This is a default Windows root.


So when you reference file or folder location in Windows it would look like this:
C:\Program Files\Internet Explorer\iexplore.exe

When you reference file or folder location in Linux it would look like:
/etc/httpd/conf/httpd.conf

Both of these start at a root partition and then move through a directory structure until a file is reached. The root partitions are different and one uses back slash while the other uses forward slash. It is essentially two different ways to write a path to a file or folder.

You will notice that the Linux filesystem has more default folders then what Windows has at default. The Linux system in general does not try to hide the complexities of an operating system like Windows or Mac OSX.

In Windows under root the following directories exist:

C:\
PerfLogs – Performance metrics log
Program Files – Install directory for x64 software
Program Files (x86) – Install directory for x32 software
         Users – Location for users personal data
         Windows – Core operating system files

In Linux under root the following directories exist:

/
boot – Files needed by the boot loader
dev – Devices attached to the system
etc – System configuration files
home – Location for users personal data
media – Mount folder for removable device (USB Flash Drives)
mnt – User defined mount directory
opt – Optional packages directory
proc – Process information directory. This is the running kernel parameters. Similar to Windows Registry
root – Home directory for root user
run – Runtime variables
srv – Services directory
sys – system files
tmp – Temporary files (flashed on reboot)
usr – User applications
var – Variable files

You may notice that I left a few out like /bin but if you look at the icon you can a little down arrow.

Another difference that needs to be looked at is how other disk or partitions are organized.

In Windows most disk will get their on drive letter with a root filesystem, although it is possible to mount a disk as a folder on an exist filesystem. With Linux you will not see multiple filesystems on a single computer. Lets look at an example of inserting an USB flash drive on both systems and look how they go about mounting it.

Windows


Linux


When using Linux you have the throw the whole concept of drive letters out the window and understand that everything will happen in the / root filesystem.

10 Useful Linux Command Line Tricks for Newbies – Part 2

I remember when I first started using Linux and I was used to the graphical interface of Windows, I truly hated the Linux terminal. Back then I was finding the commands hard to remember and proper use of each one of them. With time I realised the beauty, flexibility and usability of the Linux terminal and to be honest a day doesn’t pass without using. Today, I would like to share some useful tricks and tips for Linux new comers to ease their transition to Linux or simply help them learn something new (hopefully).


his article intends to show you some useful tricks how to use the Linux terminal like a pro with minimum amount of skills. All you need is a Linux terminal and some free time to test these commands.

1. Find the right command


Executing the right command can be vital for your system. However in Linux there are so many different command lines that they are often hard to remember. So how do you search for the right command you need? The answer is apropos. All you need to run is
# apropos <description> 
Where you should change the “description” with the actual description of the command you are looking for. Here is a good example:
# apropos "list directory"
dir (1) - list directory contents
ls (1) - list directory contents
ntfsls (8) - list directory contents on an NTFS filesystem
vdir (1) - list directory contents 
On the left you can see the commands and on the right their description.

2. Execute Previous Command


Many times you will need to execute the same command over and over again. While you can repeatedly press the Up key on your keyboard, you can use the history command instead. This command will list all commands you entered since you launched the terminal:
# history
1 fdisk -l
2 apt-get install gnome-paint
3 hostname tecmint.com
4 hostnamectl tecmint.com
5 man hostnamectl
6 hostnamectl --set-hostname tecmint.com
7 hostnamectl -set-hostname tecmint.com
8 hostnamectl set-hostname tecmint.com
9 mount -t "ntfs" -o
10 fdisk -l
11 mount -t ntfs-3g /dev/sda5 /mnt
12 mount -t rw ntfs-3g /dev/sda5 /mnt
13 mount -t -rw ntfs-3g /dev/sda5 /mnt
14 mount -t ntfs-3g /dev/sda5 /mnt
15 mount man
16 man mount
17 mount -t -o ntfs-3g /dev/sda5 /mnt
18 mount -o ntfs-3g /dev/sda5 /mnt
19 mount -ro ntfs-3g /dev/sda5 /mnt
20 cd /mnt ... 
As you will see from the output above, you will receive a list of all commands that you have ran. On each line you have number indicating the row in which you have entered the command. You can recall that command by using:
!# 
Where # should be changed with the actual number of the command. For better understanding, see the below example:
!501 
Is equivalent to:
# history

3. Use midnight Commander


If you are not used to using commands such cd, cp, mv, rm than you can use the midnight command. It is an easy to use visual shell in which you can also use mouse:


Thanks to the F1 – F12 keys, you can easy perform different tasks. Simply check the legend at the bottom. To select a file or folder click the “Insert” button.

In short the midnight command is called “mc“. To install mc on your system simply run:
$ sudo apt-get install mc [On Debian based systems] 
# yum install mc [On Fedora based systems] 
Here is a simple example of using midnight commander. Open mc by simply typing:
# mc 
Now use the TAB button to switch between windows – left and right. I have a LibreOffice file that I will move to “Software” folder:


To move the file in the new directory press F6 button on your keyboard. MC will now ask you for confirmation:

Once confirmed, the file will be moved in the new destination directory.

4. Shutdown Computer at Specific Time


Sometimes you will need to shutdown your computer some hours after your work hours have ended. You can configure your computer to shut down at specific time by using:
$ sudo shutdown 21:00 
This will tell your computer to shut down at the specific time you have provided. You can also tell the system to shutdown after specific amount of minutes:
$ sudo shutdown +15 
That way the system will shut down in 15 minutes.

5. Show Information about Known Users

You can use a simple command to list your Linux system users and some basic information about them. Simply use:
# lslogins 
This should bring you the following output:
UID USER PWD-LOCK PWD-DENY LAST-LOGIN GECOS
0 root 0 0 Apr29/11:35 root
1 bin 0 1 bin
2 daemon 0 1 daemon
3 adm 0 1 adm
4 lp 0 1 lp
5 sync 0 1 sync
6 shutdown 0 1 Jul19/10:04 shutdown
7 halt 0 1 halt
8 mail 0 1 mail
10 uucp 0 1 uucp
11 operator 0 1 operator
12 games 0 1 games
13 gopher 0 1 gopher
14 ftp 0 1 FTP User
23 squid 0 1
25 named 0 1 Named
27 mysql 0 1 MySQL Server
47 mailnull 0 1
48 apache 0 1 Apache
 ... 

6. Search for Files


Searching for files can sometimes be not as easy as you think. A good example for searching for files is:
# find /home/user -type f 
This command will search for all files located in /home/user. The find command is extremely powerful one and you can pass more options to it to make your search even more detailed. If you want to search for files larger than given size, you can use:
# find . -type f -size 10M 
The above command will search from current directory for all files that are larger than 10 MB. Make sure not to run the command from the root directory of your Linux system as this may cause high I/O on your machine.

One of the most frequently used combinations that I use find with is “exec” option, which basically allows you to run some actions on the results of the find command.

For example, lets say that we want to find all files in a directory and change their permissions. This can be easily done with:
# find /home/user/files/ -type f -exec chmod 644 {} \; 
The above command will search for all files in the specified directory recursively and will executed chmodcommand on the found files. I am sure you will find many more uses on this command in future.

7. Build Directory Trees with one Command


You probably know that you can create new directories by using the mkdir command. So if you want to create a new folder you will run something like this:
# mkdir new_folder 
But what, if you want to create 5 subfolders within that folder? Running mkdir 5 times in a row is not a good solution. Instead you can use -p option like that:
# mkdir -p new_folder/{folder_1,folder_2,folder_3,folder_4,folder_5} 
In the end you should have 5 folders located in new_folder
:# ls new_folder/ folder_1 folder_2 folder_3 folder_4 folder_5

8. Copy File into Multiple Directories


File copying is usually performed with the cp command. Copying a file usually looks like this:
# cp /path-to-file/my_file.txt /path-to-new-directory/ 
Now imagine that you need to copy that file in multiple directories
# cp /home/user/my_file.txt /home/user/1
# cp /home/user/my_file.txt /home/user/2
# cp /home/user/my_file.txt /home/user/3 
This is a bit absurd. Instead you can solve the problem with a simple one line command:
# echo /home/user/1/ /home/user/2/ /home/user/3/ | xargs -n 1 cp /home/user/my_file.txt 

9. Deleting Larger Files


Sometimes files can grow extremely large. I have seen cases where a single log file went over 250 GB large due to poor administrating skills. Removing the file with rm utility might not be sufficient in such cases due to the fact that there is extremely large amount of data that needs to be removed. The operation will be a “heavy” one and should be avoided. Instead, you can go with a really simple solution:
# > /path-to-file/huge_file.log 
Where of course you will need to change the path and the file names with the exact ones to match your case. The above command will simply write an empty output to the file. In more simpler words it will empty the file without causing high I/O on your system.

10. Run Same Command on Multiple Linux Servers


Recently one of our readers asked in our LinuxSay forum, how to execute single command to multiple Linux boxes at once using SSH. He had his machines IP addresses looking like this:
10.0.0.1
10.0.0.2
10.0.0.3
10.0.0.4
10.0.0.5 
So here is a simple solution of this issue. Collect the IP addresses of the servers in a one file called list.txt one under other just as shown above. Then you can run:
# for in $i(cat list.txt); do ssh user@$i 'bash command'; done 
In the above example you will need to change “user” with the actual user with which you will be logging and “bash command” with the actual bash command you wish to execute. The method is better working when you are using passwordless authentication with SSH key to your machines as that way you will not need to enter the password for your user over and over again. 

Note that you may need to pass some additional parameters to the SSH command depending on your Linux boxes setup.

Conclusion


The above examples are really simple ones and I hope they have helped you to find some of the beauty of Linux and how you can easily perform different operations that can take much more time on other operating systems.

3 Useful Hacks Every Linux User Must Know

The world of Linux is filled with so much fun and interesting stuffs, the more we go in, the more we find stuffs. In our efforts to bring those little hacks and tips for you that makes you different from others, here we have came up with three little tricks.

1. How to Schedule a Linux Job Without Cron


Scheduling a job/command in Linux is acronym to cron. Whenever we need to schedule a job, we call cron, but do you know we can schedule a job at a later time without corn? You can do it as suggested below..

Run a command (say date) every 5 sec and write the output to a file (say date.txt). To achieve this scenario, we need to run the below one liner script directly on the command prompt.
$ while true; do date >> date.txt ; sleep 5 ; done & 
Anatomy of the above one liner script:
  • while true – Ask script to run while the condition is true, it acts as a loop which makes the command to run again-and-again or say in a loop.
  • do – do perform what follows, ie., execute command or set of commands that lies ahead of do statement.
  • date >> date.txt – here the output of date command is being written to a file date.txt. Also note that we have used >> and not >.
  • >> ensures that the file (date.txt) is not overwritten every time the script execute. It just append the changes. Whereas > overwrite the file again and again.
  • sleep 5 – It ask the shell to keep a time difference of 5 seconds before it executed again. Note the time here is always measured in seconds. Say if you want to execute the command every 6 minutes, you should use (6*60) 360, in succession of sleep.
  • done – marks the end of while loop.
  • & – Put the whole process in loop to background.
Similarly, we can execute any script in the same manner. Here is the command to call a script after certain interval (say 100 sec) and the name of script is script_name.sh.

Also worth mentioning that the script above should be run in the directory where the script to be called lies, else you need to provide full path (/home/$USER/…/script_name.sh). The syntax for calling script at above described interval is:
$ while true; do /bin/sh script_name.sh ; sleep 100 ; done & 
Conclusion: The above one liner is not a replacement of Cron, because Cron utility supports a whole lots of options, as compared and is very flexible as well as customizable. However if we want to run certain test cases or I/O benchmark, then the above singe command will serve the purpose.

2. How to Clear Terminal without Using ‘clear’ Command


What we do to clear the screen? Well you may think how silly it is to ask such question. Well, we all know it’s ‘clear‘ command. However if we make a habit of using key combination ‘ctrl+l‘ to clear terminal, we will save a lot of time of ours.

Key combination ‘Ctrl+l‘ has the same effect as ‘clear‘ command. So from next time use ctrl+l to clear your Linux Command Line Interface.

Conclusion: Since ctrl+l is a key combination, so we can not use it inside a script. If we need to clear screen inside a shell script, call command ‘clear’, for all other cases I could think of now, ctrl+l is more than sufficient.

3. Run a command and come back to the current working directory automatically.


Well this is an amazing hack not many people know. You may run a command no matter what it return back to the current directory. All you need to do is to run the command in parentheses i.e., in between ( and ).

Let see the example,
avi@deb:~$ (cd /home/avi/Downloads/) 
Sample Output
avi@deb:~ 
First it cd to directory Downloads and then again return back to home directory in one go. May be you believe that the command didn’t executed and for some reason one or another it is not throwing error, since there is no change in prompt. Lets do a little more tweak.
avi@deb:~$ (cd /home/avi/Downloads/ && ls -l) 
Sample Output
-rw-r----- 1 avi avi 54272 May 3 18:37 text1.txt
-rw-r----- 1 avi avi 54272 May 3 18:37 text2.txt
-rw-r----- 1 avi avi 54272 May 3 18:37 text3.txt
 avi@deb:~$ 
So in the above command it first changed the current directory to Downloads and then list the content of that directory before returning back to current directory. Also, it proves that command executed successfully. You may run any sort of command in the parentheses and return back to your current working directory without a hitch.

That’s all for now, if you know any such Linux hacks or tricks you may share with us via our comment section and don’t forget to share this article with your friends….

4 Useful Tips on mkdir, tar and kill Commands in Linux

We keep on accomplishing a task conventionally until we come to know that it can be done in a much better way the other way. In continuation of our Linux Tips and Trick Series, I am here with the below four tips that will going to help you in lots of ways. Here we go!


1. You are supposed to create a long/complex directory tree similar to given below. What is the most effective way to achieve this?

Directory tree structure to achieve as suggested below
$ cd /home/$USER/Desktop
$ mkdir tecmint $ mkdir tecmint/etc
$ mkdir tecmint/lib
$ mkdir tecmint/usr
$ mkdir tecmint/bin
$ mkdir tecmint/tmp
$ mkdir tecmint/opt
$ mkdir tecmint/var
$ mkdir tecmint/etc/x1
$ mkdir tecmint/usr/x2
$ mkdir tecmint/usr/x3
$ mkdir tecmint/tmp/Y1
$ mkdir tecmint/tmp/Y2
$ mkdir tecmint/tmp/Y3
$ mkdir tecmint/tmp/Y3/z 
The above scenario can simply be achieved by running the below 1-liner command.

$ mkdir -p /home/$USER/Desktop/tecmint/{etc/x1,lib,usr/{x2,x3},bin,tmp/{Y1,Y2,Y3/z},opt,var}

To verify you may use tree command. If not installed you may apt or yum the package ‘tree‘.
$ tree tecmint

We can create directory tree structure of any complexity using the above way. Notice it is nothing other than a normal command but its using {} to create hierarchy of directories. This may prove very helpful if used from inside of a shell script when required and in general.

2. Create a file (say test) on your Desktop (/home/$USER/Desktop) and populate it with the below contents.
ABC
DEF
GHI
JKL
MNO
PQR
STU
VWX
Y

What a normal user would do in this scenario?

a. He will create the file first, preferably using touch command, as:
$ touch /home/$USER/Desktop/test 
b. He will use a text editor to open the file, which may be nano, vim, or any other editor.
$ nano /home/$USER/Desktop/test 
c. He will then place the above text into this file, save and exit.

So regardless of time taken by him/her, he need at-least 3 steps to execute the above scenario.

What a smart experienced Linux-er will do? He will just type the below text in one-go on terminal and all done. He need not do each action separately.
cat << EOF > /home/$USER/Desktop/test
ABC
DEF
GHI
JKL
MNO
PQR
STU
VWX
Y
Z
EOF 
You may use ‘cat‘ command to check if the file and its content were created successfully or not.
$ cat /home/avi/Desktop/test


3. We deal with archives (specially TAR balls) very often on Linux. In many cases we have to use that TAR ball on some location other than Downloads folder. What we do in this scenario?

We normally do two things in this scenario.

a. Copy/Move the tar ball and extract it at destination, as:
$ cp firefox-37.0.2.tar.bz2 /opt/ or $ mv firefox-37.0.2.tar.bz2 /opt/ 
b. cd to /opt/ directory.
$ cd /opt/ 
c. Extract the Tarball.
# tar -jxvf firefox-37.0.2.tar.bz2 
We can do this the other way around.

We will extract the Tarball where it is and Copy/Move the extracted archive to the required destination as:
$ tar -jxvf firefox-37.0.2.tar.bz2
$ cp -R firefox/ /opt/
or
$ mv firefox/ /opt/ 
In either case the work is taking two or steps to complete. The professional can complete this task in one step as:
$ tar -jxvf firefox-37.0.2.tar.bz2 -C /opt/ 
The option -C makes tar extract the archive in the specified folder (here /opt/).

No it is not about an option (-C) but it is about habits. Make a habit of using option -C with tar. It will ease your life. From now don’t move the archive or copy/move the extracted file, just leave the TAR-ball in the Downloads folder and extract it anywhere you want.

4. How we kill a process in a traditional way?

In most general way, we first list all the process using command ps -A and pipeline it with grep to find a process/service (say apache2), simply as:
$ ps -A | grep -i apache2 
Sample Output
1006 ?          00:00:00 apache2
 2702 ?         00:00:00 apache2
 2703 ?         00:00:00 apache2
 2704 ?         00:00:00 apache2
 2705 ?         00:00:00 apache2
 2706 ?         00:00:00 apache2
 2707 ?         00:00:00 apache2 
The above output shows all currently running apache2 processes with their PID’s, you can then use these PID’s to kill apache2 with the help of following command.
# kill 1006 2702 2703 2704 2705 2706 2707 
and then cross check if any process/service with the name ‘apache2‘ is running or not, as:
$ ps -A | grep -i apache2 
However we can do it in a more understandable format using utilities like pgrep and pkill. You may find relevant information about a process just by using pgrep. Say you have to find the process information for apache2, you may simply do:
$ pgrep apache2 
Sample Output
15396
15400
15401
15402
15403
15404
15405 
You may also list process name against pid by running.
$ pgrep -l apache2 
Sample Output
15396 apache2
15400 apache2
15401 apache2
15402 apache2
15403 apache2
15404 apache2
15405 apache2 
To kill a process using pkill is very simple. You just type the name of resource to kill and you are done. I have written a post on pkill which you may like to refer here : http://www.tecmint.com/how-to-kill-a-process-in-linux/.

To kill a process (say apache2) using pkill, all you need to do is:
# pkill apache2 
You may verify if apache2 has been killed or not by running the below command.
$ pgrep -l apache2 
It returns the prompt and prints nothing means there is no process running by the name of apache2.

That’s all for now, from me. All the above discussed point are not enough but will surely help. We not only mean to produce tutorials to make you learn something new every-time but also want to show ‘How to be more productive in the same frame‘. Provide us with your valuable feedback in the comments below. Keep connected. Keep Commenting.

How to Find and Remove Duplicate/Unwanted Files in Linux Using ‘FSlint’ Tool

Very recently I have written a post on fdupes utility which is used to find and replace duplicate files in Linux. This post was very much liked by our readers. If you have not gone through the fdupes utility post, you may like to go through it here:

  • fdupes Tool to Find and Delete Duplicate Files
This post aims at throwing light on what is fslint, its features, installation and usages.


What is fslint?


fslint is a Linux utility to remove unwanted and problematic cruft in files and file names and thus keeps the computer clean. A large volume of unnecessary and unwanted files are called lint. fslint remove such unwanted lint from files and file names. Fslint help fight against unwanted files by coping with duplicate files, empty directories and improper names.

Features of fslint


  • It is a combination of different tools that look after duplicate files, empty directories and improper name.
  • Simple GTK+ Graphic front-end as well as command-line.
  • Fslint cope with lint that relates to Duplicate files, Problematic filenames, Temporary files, Bad Symlinks, Empty directories and Non-stripped binaries.
  • Help you in reclaiming disk space that were used by unnecessary and unwanted files.

Install fslint on a Linux


Installation of latest version of fslint package can be installed as easy as executing following command onDebian based systems such as Ubuntu and Linux Mint.
$ sudo apt-get install fslint 
On CentOS/RHEL based distributions, you need to active epel repository to install fslint package.
# yum install fdupes
# dnf install fdupes [On Fedora 22 onwards] 

How do I use fslint Command?

Hope you know one of the basic rule of computation and understand the risk – have backup. Before you start testing this application make sure you have backup of everything on your system, so that even if an important file gets deleted you may restore almost immediately.

Now as you know that fslint is one such application that has a command-line interface as well as a front-end GUI at the same time. You may use either.

For developers and administrators, CLI version is preferred as it gives you immense power. GUI front-end is best suited to newbies and those who prefer GUI over CLI.

fslint Command Line Usage


The command line version of fslint is not on the path of most of the Linux users. You may access it at the location /usr/share/fslint/.
$ ./usr/share/fslint/fslint/fslint 
Sample Output

-----------------------------------file name lint ./.config/google-chrome/Default/Pepper\ Data/Shockwave\ Flash/WritableRoot/#SharedObjects/NNPAG57S/videos.bhaskar.com/[[IMPORT]] ./Documents/.~lock.fslint\ -\ Remove\ duplicate\ files\ with\ fslint\ (230).odt#
 ./Documents/7\ Best\ Audio\ Player\ Plugins\ for\ WordPress\ (220).odt
./Documents/7\ Best\ WordPress\ Help\ Desk\ Plugins\ for\ Customer\ Support\ (219).odt .
./Documents/A\ Linux\ User\ using\ Windows\ (Windows\ 10)\ after\ more\ than\ 8\ years(229).odt ./Documents/Add\ PayPal\ to\ WordPress(211).odt ./Documents/Atom\ Text\ Editor\ (202).odt ./Documents/Create\ Mailchimp\ account\ and\ Integrate\ it\ with\ WordPress(227).odt ./Documents/Export\ Feedburner\ feed\ and\ Import\ it\ to\ Mailchimp\ &\ setup\ RSS\ Feed\ Newsletter\ in\ Mailchimp(228).odt ----------------------------------DUPlicate files
 Job 7, “/usr/share/fslint/fslint/fslint” has stopped 
Important: Two things you should be kept in mind at this point. First fslint don’t delete any file on its own, It just shows you the lint files, their location and their name. You have to decide what to do with them. Second is fslint by default start searching from your ‘/home’ directory.

To search a different other than your /home directory, you must pass the directory name with the command, as:
$ /usr/share/fslint/fslint/fslint /home/avi/Pictures


To search recursively to all the sub-folders, you should use flag ‘-r’, simply as:
$ /usr/share/fslint/fslint/fslint -r /home/avi/Music/


fslint GUI Usage


You may fire the GUI Application built on top of fslint by typing fslint from Linux terminal or from theApplication Menu.
$ fslint-gui

Everything in GUI is simple to understand. All you need to do is:
  • Add/remove the directories to scan.
  • Select to scan recursively or not by checking/unchecking checkbox on the top-right.
  • Click on ‘Find’. And all done!
Again you should remember, this utility do not delete the lint files but provide you with the information only and leaves everything on you.

Conclusion


fslint is a perfect tool that remove lint of various types from a file system. Though it needs improvement in certain gray areas: –
  • A bit slow for duplicate photo detection.
  • Requires some improvement in User Interface.
  • No Progress meter.
Hope you liked the post. If yes! Be audible. Post your valuable feedback in the comments below. Stay tuned and connected to Tecmint while I am working on another post you will love to read. Like and share us and help us get spread.