Enter your email address:

Delivered by FeedBurner

Linux command line

Navigate on Linux command shell history

history is a very useful command in Linux, because it helps you remember the commands you have used in the past.

Well, the way most of people use it, is by typing

history

Check the spell of your documents from command line

To check the spell of a text file, maybe written with vi/vim, emacs, or any other text editor even sed, awk or a here-document, you may use aspell.

From the man page:

aspell is a utility program that connects to the Aspell library so that
it can function as an ispell -a replacement, as an independent spell
checker, as a test utility to test out Aspell library features, and as
a utility for managing dictionaries used by the library.

The Aspell library contains an interface allowing other programs direct
access to it’s functions and therefore reducing the complex task of
spell checking to simple library calls. The default library does not
contain dictionary word lists. To add language dictionaries, please
check your distro first for modified dictionaries, otherwise look here
for base language dictionaries http://aspell.net.

Execute a command in a regular interval - watch Linux command

If you anytime need to execute a command once and again and again, you can use watch and tell it to execute the Linux command in a give interval.

The syntax of the command is:

watch [option(s)] command

The default interval of execution of the given command is two (2) seconds, but you define a different interval using the option -n.

Here are two useful uses of watch.

watch -n 5 free -m

small tip - Which applications are using a given directory

If you ever need to know which application(s) are using (writing or reading) a given directory on your disk, lets say because it is a usb memory stick that you need to unmount and you cant because you do not know which application is still using it.

And the Operating system says that the unit is busy

This is what happens when I try to unmount it

sudo umount /media/usb

umount: /media/usb: device is busy

Use this command.

lsof +D /media/usb

Define a static IP on Linux, and assign a Default Gateway

There are some networks where DHCP is not yet implemented, and when you enter into those networks asking for connection, the Admin of the network will give you these data.

IP, Netmask, Gateway and sometimes DNS, I see myself in this situations lots of times as I travel with my Laptop, and in the offices where I have to work I found this types of networks with no DHCP server installed.

Well, what will you do with those info?, I like the command line, so I will show you how to assign this IP through the Linux command line console.

nohup - make commands keep running after leaving a terminal session or ssh session

When you start a session on a Linux Server, and then you need to run a program or a process that is going to take a long time to finish, you will have to let your session open until that process finish, because Linux Operating System, by default will end the process if you exit your session.

Now it is not secure to let your session open while you are not there, or maybe not possible to let it open if you are over a ssh connection, so you may want to use nohup to let the process running even when you exit your session.

Here is an example on a Debian Linux machine.

nice - modify the scheduling priority of a command

nice is a command that allows you to change the scheduling priority of a command from -20 the most favorable to 19 the least favorable.

Sintax

nice -n NUMBER

Where NUMBER is an integer number from -20 to 19, if you do not use the -n option, the niceness will be increased in 10 by default.

Example:

sudo nice -n 4 tail -f /var/log/messages

Now if you start htop you may see that tail is running with a niceness of 4.

ps - How to check the running processes on Linux

ps, is a Linux command tool, that lets you view the current running processes, it is very useful when you are trying to kill a process or to view which applications other users are running (if you are the admin).

You may use it to check your own applications, some other user's application or a full list of the applications running on the operating system, you may also combine it with grep.

running it alone with no atributes

ps

cpio - copy files to and from archives

cpio is a tool to copy files from one place to another, and to create archives, (like tar), or extract files from an archive file.

The good thing is that cpio takes its input from other commands like ls, or find

So you can archive all .mp3 in your home directory by entering this command:

ls *.mp3 | cpio -o --format=tar -F mymp3.tar

Or if you want to include subfolders

find $HOME -name "*.mp3" | cpio -o --format=tar -F mymp3.tar

Tilda - Linux pop-up console

Tilda is just another Linux terminal emulator, but it has some useful properties coming with it, like, no borders, transparency, but most important, it can appear on your window with the press of a key.

Installing it

As usually it is very easy, just ask your package manager to install if for you.

sudo aptitude install tilda

for Debian,

sudo emerge tilda

[Ctrl+z] Stop jobs, put it in background, or resume them later.

Another good shortcut is [Ctrl+z], which stops a currently running job, which you can later terminate or resume it, either in foreground or background.

The way to use this is to press [CTRL+z] while executing a job (task), this can be done with any application started from the console.

i.e.:

htop

Then press [CTRL+z], and htop will be stopped, you can now check the running jobs.

jobs

<CRTL+R> Search in your last used commands

This is a Linux shortcut, it is very usable, and with it you will be able to search in your history of commands, by just starting to write the command, it is something like Firefox works, when you start typing an address, and it try to guess where you are trying to go.

history, a command to display your last used commands

History is a great command to use, I use it daily, today I have found a real good application of it.

It is the way to list the most used commands by you.

Here is how, type this in the console:

history|awk '{print $2}'|awk 'BEGIN {FS="|"} {print $1}'|sort|uniq -c|sort -r

Small tip, System Memory information

To check your memory information, just enter this command on the terminal

cat /proc/meminfo

How to kill user's processes and logout the user

The other day a friend of mine was asking me how to stop all users' processes and then logout him.

Well maybe the first thing you need is to send a message to the user, so he can actually save his work.

to do that you may use the command wall to let your users know you are about to log them out.

Now at the given time end all of your users' applications, using pkill

sudo pkill -u username

How to broadcast a message to all users - using wall -

Sometimes as the administrator of a Linux Operating System Server, y may need to send a message to all users in a multi-user system.

There are some different ways to do this, but we will now see just one of them.

We will use wall

As the main input of wall is a file, we will first create our message file.

Let's say you want to tell users that in two more ours the main SQL database is going to be unavailable because of maintenance.

So type:

Alias - create alias for your commands

Alias is a command that lets you create command aliases, it is very useful when you usually use commands with options.

As an example in my case I use a lot these commands

du -h

and

df -h

In both cases the "-h" option makes the output be in Kbytes or Mbytes instead of bytes, so it is more human redeable.

To create aliases for this commands just need to enter.

alias du='du -h'

and

alias df='df -h'

whowatch - Monitor who is doing what on your system

whowatch is a console application that lets you monitor what different users are doing on the Linux operating system in a given moment, it works in real time.

First install it

sudo aptitude install whowatch

at - command to schedule actions

One of the most uses I give to this command is to turn the PC off after some time, sure there are other ways.

I like the way you may execute batch jobs at a given time, all you need is:

1. Write your shell script

Which actually is a list of commands in a text file

2. Execute the at command

at now + 5 minutes < $HOME/listofcommands.txt

You can use times like "now", "noon", "midnight", or a date in the format of DD.MM.YY

check man at in order to have more details

Installing and uninstalling .deb package

Debian uses .deb binary packages and you manually install and uninstall them using dpkg tool.

dpkg has lots of options but maybe the most important or used ones are:

-i
Installs and configures a package
-r
Removes the package but keeps the configuration files on your systems, thus you may reinstall it later and does not need to configure it again
-p
Purges a package, meaning it will remove the package and also all configuration files

How to use it

Syndicate content

This site is proudly hosted at Bluefur Hosting