Enter your email address:

Delivered by FeedBurner

Linux command line

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

du - Shows the disk space a file or directory is using in your disk

This is a very useful command you may use to find which file or directory is filling you disk.

So if you need to check the file and directory size in your home directory you can enter

cd

to switch to your home directory

du -S * | sort -n

How to find files, using command line (locate)

Continuing reviewing some of my old posts, I found this one Examples of find command, now I want to show you a faster and easier way to find files.

We are going to use the commands updatedb and locate

updatedb

How to find which service is listening on a given port

It is really important to know which ports are open in your PC, this is not only useful for Linux, but also for other operating systems, Linux has a lot of tools to check which ports are open, the most common is nmap which is a command line tool, but also exist a Graphical frontEnd for it if you prefer that way.

So to scan you own PC and find open ports you can enter:

sudo nmap -T Aggressive -A -v 127.0.0.1 -p 1-65000

wget - Resume downloads, limit the speed and much

wget is a command line tool used to download files, or complete webpages, it is a great utility with lots of options, as you can see if you read the wget man page

Some months ago, I have written about how to download files with wget, now I want to add some other tips to those already explained that day.

Resume a download

The /etc/default/rcS file

There is some behavior of your Linux Operating System which is easy to change, but not too common to know how.

The things you can change are:

  • Frequency to erase /tmp/ directory
  • Use UTC or local time
  • How Verbose are the boot messages of your Linux
  • If a disk error should be always repaired while booting automatically

There are more than those, but I will touch only those, for the rest, you can enter:

man /etc/default/rcS

vnstat - Command Line Tool to check how much bandwidth you use

It is always useful to know how much bandwidth you are using, also to check if your provider is honoring the contract you signed with them.

At my office I have installed Cacti and as I have a layer 3 SNMP capable switch, I can graph the bandwidth that all my office's PCs uses, and also the main pipe to the Internet (My ADSL connection), but at home, I do not have such an expensive switch (and I do not need it), and my ADSL modem is not SNMP capable, so Cacti is not a solution, but with Linux Operating System there is always a solution, and the one for this kind of problem is vnstat.

command line scientific calculator

I was looking for a good and light calculator for Linux, and found some command line ones, I liked this one wcalc it is really light, and accept almost all mathematical expressions, and I say "almost" because I do not want to say that are all and make a mistake.

The use of it is really simple, just enter wcalc followed with the math expression in the command line, press ENTER and you will the result.

To install it on Debian run:

sudo aptitude install wcalc

Trash can or Recycle bin in Linux Desktop (managed from console)

Linux Desktops, at least Gnome and KDE has a trash can, where your deleted files go, (only when deleted from a Desktop utility).

Now if you want to manage it from the console, you can, first we need to know that the trash can is only another folder in the File system structure and it is located at:

$HOME/.Trash

so you can send files to Trash just moving them to there, as an example, lets suppose you have a file in your home called balance.ods and want to move it to the trash can.

mv $HOME/balance.ods $HOME/.Trash/

How to assign a password to root user in Ubuntu

Ubuntu by default has no root password, and you can also configure Debian in that way if you choose the advanced installation option, and decide not to use the root password.

But what to do if later you need the root user? well you just need to assign a password to the root user and then you will be able to switch to root user.

sudo passwd

Type a good strong password twice, and you are done.

su -

Type the root password and voila! you are logged as root, you know you have to be carefull on what you do being root right?

Terminator - multiple terminals in one window

I really like to work with the console, and to connect to my servers using ssh, to administrate them, so sometimes I found myself with lots of terminal windows open, I have explored some solutions in the past, that you can see on this post about Terminal emulators, now I have found a new one which I really like, it is called terminator.

For Debian users it is available only on Sid, and as I use Lenny I had to install it from the sources.

Reading compressed Files

I did not know this, but if you need to show a compressed text file on the screen, you do not actually need to uncompress it.

You can use zcat to send the file to the standard output, uncompressed, but the original file remains untouched.

The syntax of the command is:

zcat file.gz

or you can also use,

gunzip -c file.gz

mplayer - command line movie and music player - music over ssh

Mplayer is one of most known movie players in Linux, and also in Mac OS, and Windows.

To install it in Debian / Ubuntu run:

sudo aptitude install mplayer

Mplayer has lots of options, and we will explore some of them here, the files format it can play according to its official site are:

MPEG/VOB, AVI, Ogg/OGM, VIVO, ASF/WMA/WMV, QT/MOV/MP4, RealMedia, Matroska, NUT, NuppelVideo, FLI, YUV4MPEG, FILM, RoQ, PVA files, supported by many native, XAnim, and Win32 DLL codecs. You can watch VideoCD, SVCD, DVD, 3ivx, DivX 3/4/5 and even WMV movies..

for - Control flow statement in shell scripts

One real important part of programming is to control the flow of the program, you need to be able to repeat some part of the code, jump to another part, etc, depending on the estate of some variables, there are a lot of commands to achieve that, and one of them is for

It can be used directly at the command line like this example using basename

for i in *.jpg; do echo $i $(basename $i .jpg); done

basename - removing directories and suffix from file names

If you need to remove the directory or any suffix from a file name you may use basename, this is really useful when you are creating shell scripts.

In the man page, there are this examples

basename /usr/bin/sort

Output "sort".

basename include/stdio.h .h

Output "stdio".

you can enter

info basename

Syndicate content

This site is proudly hosted at Bluefur Hosting