Cheap Tickets to India

8 Examples of Touch Command

 Command Line  Comments Off on 8 Examples of Touch Command
May 092015
 

Touch is a useful command to be aware for those new to Linux.

System administrators use touch to quickly create empty files.

But that’s not the only use for the touch command.

Linux and Unix administrators routinely use touch to change timestamp of files.

So what are timestamps?

In the Unix and Linux environments, all files are associated with timestamps. Timestamps provide information about files such as their last access, modification and change time.

Timestamps are valuable in compiling source code, used in scripts, creating backups and for applications deployed or used across multiple time zones.

Also, commands like ls and find leverage timestamps for listing and finding files respectively.

With that brief introduction to touch, let’s consider a few key options for touch and then follow it up with some examples.

Key Touch Command Options

-a, change access time only
-c, if file does not exist, do not create it
-d, update access and modification times
-m, change modification time only
-r, use access and modification times of file
-t, creates a file using a specified time

Touch Illustrations

1. Create an Empty File

The most frequent use of touch is to quickly create an empty file.

Let’s start with an example.

$ touch Example.txt

Voila, you now have a file called Example.txt. Continue reading »

 Posted by at 2:05 pm

How To Find CPU Details on Linux

 Command Line, How To  Comments Off on How To Find CPU Details on Linux
Apr 292015
 

Which Processor Running on Linux?The command line interface is so versatile that you can find considerable information about even the hardware side of your Linux server or desktop.

In this post, we’ll take a look at a bunch of commands that provide details about the CPU inside a Linux computer.

We’ll dig down for information on the CPU vendor, check if it’s 32-bit or 64-bit, look for the number of cores, frequency, cache size and more.

1. Let’s start with lscpu, a favorite of both users and system administrators.

LSCPU Output
A quick glance at the above output tells us that our Linux box has an Intel, quad-core, 64-bit processor running at 2000MHz.

2. Another favorite of system administrators is /proc/cpuinfo.

Use it with the less prefix since the output is big and quickly vanishes beyond the top of the screen.

Using CPUInfo with less

As with the previous command, we see that the output of /proc/cpuinfo provides information about the processor, vendor, cores and frequency.

In the following two examples, we’ll tweak /proc/cpuinfo to get only the information we need.

3. If you’re interested in just knowing the CPU vendor, go with cat /proc/cpuinfo along with with the grep command.

$ cat /proc/cpuinfo | grep vendor | uniq
vendor_id       : GenuineIntel

The output spits out just the vendor name, nothing more.

4. Now that we have the vendor info (above) let’s dig into details of the Intel processor.

$ cat /proc/cpuinfo | grep 'model name' | uniq
model name	: Intel(R) Core(TM)2 Quad CPU    Q9400  @ 2.66GHz

Voila, your PC runs on a Core 2 Quad core Q9400 processor at 2.66GHz. Not the latest and greatest of processors but adequate for most users.

5. Hardinfo is another handy utility that provides a wealth of information about your Linux system.

Although installed on the command line, hardinfo is actually a GTK based GUI utility.

If hardinfo is not installed on your Linux box, you can do so with the following command on your Ubuntu system.

$ sudo apt-get install hardinfo

If you ask me, hardinfo is an embarras de richesses. Besides the CPU, it provides details on most aspects of the Linux box including memory, storage, PCI devices, storage, USB devices etc plus information on the OS, kernel, and networking.

An extremely handy tool, hardinfo also lets you quickly generate a HTML report that you can save to your machine.

I cannot recommend hardinfo strongly enough. Continue reading »

 Posted by at 6:40 am

Tasks on Command Line – Simple as Pie

 Command Line, Products  Comments Off on Tasks on Command Line – Simple as Pie
Apr 242015
 

Newton, Galileo, Dante and Shakespeare never used todo lists or notes apps to accomplish great feats.

Stalin and Hitler killed tens of millions without a single todo or notes app.

But lesser mortals, these days, it seems can’t function or get through the day without a collection of notes apps or todo lists on their PCs and mobile devices.

And if these apps are not cloud-powered to enable synchronization of the notes and todo lists across devices, the collective wrath of users descends on the hapless developer.

Such are the unusual times we live in!

Although I’m as guilty as the next Joe in hoarding notes and todo apps on my PC, tablet and smartphone, I’ve never been an intensive user of any of these apps. On the Mac, I use the free versions of Evernote and Eisenpower and on my Linux desktop my preferences are Task Coach and CherryTree.

If you ask me, there’s nothing you can’t accomplish by jotting down tasks on an index card. Nabokov famously wrote his masterpieces on index cards.

But lately I’ve been drawn to a todo utility called Taskwarrior.

A big plus of Taskwarrior for Linux administrators who live and breathe on the command line is that it’s convenient since you don’t have to go outside the command line and open an application to get to your todo list.

You see, Taskwarrior works essentially on the command line.

Installing Taskwarrior

Taskwarrior is available for both CentOS 7 (RedHat and Fedora) and Ubuntu (LinuxMint 17) distributions.

The latest version of task for Ubuntu is 2.2.0-3 and for CentOS it’s 2.4.2.

If you’re running Fedora, CentOS or RedHat, use yum to install task.

$ sudo yum install task

If you’re on an Ubuntu system, go with the below command.

$ sudo apt-get install task

How Task Works

The beauty of task lies in its simplicity. Continue reading »

 Posted by at 8:27 pm

How to Check Memory Use by Applications

 Command Line, Linux  Comments Off on How to Check Memory Use by Applications
Apr 232015
 

Once in a while I run into a situation where I feel one of the work computers running Linux (of course) might be running slow.

4GB Memory for Desktop PCs

The first thing I check is the memory installed and utilized through the use of free -m command.

The Free command is not perfect but good enough.

thomas@workpc ~ $ free -m
             total       used       free     shared    buffers     cached
Mem:          4798       1701       3097        147         70       1147
-/+ buffers/cache:        483       4315
Swap:         3930          0       3930

The data column under free in the second line is what you should look for.

With 4.31GB “free” under that column, no issues there!

Applications & Memory Use

Next, I look at applications that are drawing the most memory.

To check memory used by various applications, a plethora of options are available on the command line.

You can check memory use by all applications and processes or examine just the memory used by the top-5, top-10 or top-20 applications.

Here are a few commands to help you quickly check memory used by different applications. I have tested them on LinuxMint 17 but they should work on other Linux distros too.

1. Memory, CPU & others

The below command is one of my favorites because besides memory, it also provides CPU use and the PID (process ID).

$ ps -eo pmem,pid,pcpu,rss,vsz,time,args | sort -k 1 -r

2. Top 20 Processes
If you’re looking for memory use by the top 20 processes, go with the below command.

Unlike some of the other commands, this one will give you only memory use and percentage.

$ ps aux | awk '{print $2, $4, $11}' | sort -k2rn | head -n 20

3. Top 10 Processes
Now if you’re looking for memory use by the top 10 processes, run either of the below commands.

ps aux | awk '{print $2, $4, $11}' | sort -k2rn | head -n 10

or

$ ps aux --sort=-%mem | awk 'NR<=10{print $0}'

4. Top 5 Processes
If you’re looking for memory use by just the top five processes, issue the below command in the terminal.

$ ps -eo pmem,pcpu,vsize,pid,cmd | sort -k 1 -nr | head -5

5. Top is Tops
For a lot of folks, the top command is tops when it comes to checking memory and other parameters of their computer.

Run top
Once inside top, press m

A big plus is that top comes installed with every Linux computer.

6. Htop Tops Top

Lately, htop, a gussied up, ‘colored’ version of top, has drawn a lot of defectors from top.

$ htop

On Debian (or its spawns like Ubuntu and Linux Mint you can install htop easily:

$ sudo apt-get install htop

Go ahead and try out these commands on your Linux system and see which of your applications is grabbing the most memory.

 Posted by at 9:58 pm

10 Crucial Yum Commands for CentOS 7

 Command Line, Linux  Comments Off on 10 Crucial Yum Commands for CentOS 7
Apr 222015
 

Yum (Yellowdog Updater, Modified) is at the core of the CentOSRed Hat and Fedora package management systems.

On Linux distros like CentOS 7, RedHat 7 or Fedora 21, if you want to update, install or remove packages, list installed packages or update the entire system while at the same time ensuring automatic dependency resolution then the command line tool you must deploy is yum.

Yum also comes in handy while enabling or disabling repositories (package sources).

To update, install or remove packages via yum, you must have superuser privileges (via su or sudo).

Now let’s take a look at some of the key Yum commands you ought to be familiar for CentOS 7.

1. Check for Updates

$ yum check-update

The above command only checks for and lists available updates but it will not install them.

There’s no need to be logged in as a superuser to check for available updates.

2. Update a Single Package

More often not, you’ll be required to update only a single package, not all the packages.

Use the below command if you wish to update just a single package and you know its name.

$ yum update package_name

3. Update All Packages

If you intend to update all packages along with their dependencies, go with either of the below commands.

$ yum update

or

$ yum upgrade

I usually go with yum update if I’m updating multiple packages.

4. Search Packages

You can check enabled repositories for packages you wish to install on your CentOS 7 or RedHat 7 system.

There’s no need to know the name of the package during the search.

Let’s say you heard about a good RSS package but forgot its name. So just use rss in the search string.

$ yum search search_string

Search Multiple Packages
Yum lets you search for multiple packages simultaneously.

In the below example, I’m searching for the Cherrytree notes app and the Quiterss RSS reader. Continue reading »

 Posted by at 11:09 am  Tagged with:

Linux Software Installation Made Easy

 Command Line, How To, Linux  Comments Off on Linux Software Installation Made Easy
Mar 122015
 

Don’t let Windows or Mac users scare you that adding or removing software on a Linux computer is only for bravehearts.

Installing, upgrading or removing software on Linux systems is no longer the daunting chore it used to be some years back.

Broadly speaking, there are two ways to install software packages on a Linux system.

You can install software packages either through a graphical user interface (GUI) or do it via the command line.

Major desktop Linux distros like Fedora Workstation 21, Linux Mint and Ubuntu now have slick GUIs that make searching for and installing new software a breeze.

The big advantage with GUI based installers is that they take care of dependency resolution so newbies won’t have to fret whether the package they’re installing or upgrading will work without having to install other software.

But you can be sure that hardcore Linux enthusiasts and system administrators will always opt for the command line to install, upgrade or remove software.

In large business environments (such as a web hosting companies) where headless servers are often the norm, Linux system administrators work exclusively on the command line.

Command Line Installation

On the command line, two kinds of tools (low level and high level) are available to install software packages on a Linux system.

The first method (dpkg for Debian and rpm for Red Hat) does not resolve dependencies and are therefore considered low level tools.

The high level installation tools (apt-get or yum) take care of dependencies.

In case you didn’t know, dependencies are other software that an application requires before it can work.

dpkg and rpm are low-level tools while apt-get and yum are considered high-level tools because they take care of dependencies as part of the installation process.

In this post, we’ll look at installing and removing software packages on both Debian based distributions and Red Hat style distros (like Fedora, CentOS and OpenSUSE that follow the Red Hat methodology) via the command line.

As you no doubt guessed, the commands for Debian and Red hat are completely different.

So we’ll have to consider them separately to avoid confusion.

We’ll consider Debian and its derivative distros first.

Installation on Debian

Commands mentioned in this section should work on Debian, Ubuntu, Linux Mint, Xandros and more.

Install a Package

Linux users opt for dpkg with software that are not downloaded from a repository.

Here’s how you install a package with dpkg.

# dpkg -i package_name

When you install a .deb package via the low-level dpkg tool, be aware that there is no dependency resolution.

So if the package you’re installing requires other software you’re stuck.

To avoid dependency issues, you must use higher-level tools like apt-get to install software on Debian and its derivatives. Strictly speaking, this is not always possible because not all packages are in repositories.

When you use the high level apt-get install tool, you’re downloading software from a repository.

The first step is to run update and then search for the package you’re interested in.

# apt-get update
# apt-cache search search_string

If you’re looking for an RSS reader, you’d run the below command first.

# apt-cache search rss

That’s how I discovered RSS readers like Quiterss and Liferea.

Finally, when you’ve found the package you want just install it with the following command.

You can skip the search step if you already know the package you want to install.

# apt-get install package_name
List Packages Installed

Your Ubuntu or Linux Mint computer has dozens of packages installed on it.

If you want the entire lengthy list, go with the following command.

$ dpkg -l

I recommend you save the output to a text file for leisurely analysis later.

$ dpkg -l > MyPackageList.txt
Total Packages Installed

Say you want to find out how many packages are installed on a Linux system without the long list of all the individual packages.

You use the dpkg with the -l option and then pipe it to wc -l.

On my Ubuntu system, I was curious about the total packages installed.

Here’s what I did:

$ dpkg -l | wc -l
2215
Remove a Package

Removing a package on a Debian, Ubuntu or Linux Mint computer is no sweat with the below command.

# dpkg -r package_name

Alternatively, if it’s a package downloaded from a repository you should go with either of the following commands.

# apt-cache remove package_name

But the above command leaves behind configuration files.

If your goal is to remove the configuration files too, you must use the purge option.

apt-cache purge package_name
Information About a Specific Package

If you’re looking for more information on a specific package, what command would you run?

In the below example, I sought information on the popular Cherrytree notes application.

$ dpkg -l cherrytree | tail -1 | tr -s ' '
ii cherrytree 0.35.7-1~ppa1~trusty1 all hierarchical note taking application
Verify if Package is Installed

You can check if a particular software package is installed on your Debian or Ubuntu computer.

Say you want to see if an rss package is installed on your Ubuntu computer.

Here’s the command you ought to run:

$ dpkg -l | grep rss
ii  quiterss  0.17.6-0ubuntu1~trusty  amd64 RSS/Atom feed reader written on Qt

If quiterss weren’t installed on my Ubuntu PC, I wouldn’t have got any response.

Red Hat & Red Hat Syle Distros

Let’s now take a dekko at how to install software on Red Hat and its derivative distributions like CentOS and Fedora.

Red Hat is the favorite Linux distro for scores of large corporations around the world. Continue reading »

 Posted by at 6:41 pm