Enter your email address:

Delivered by FeedBurner

Linux tips

Change shell's built in functions

So, do you ever needed to change the behavior of a shell's built in command? O.K. the command builtin comes to save the day.

First thing is to know which are built in commands, to do that, read the man of your shell

echo $SHELL

Small tip - Reboot your system and force or avoid a disk scan/check

There is a simple command that will make your Linux system to reboot, and inmediately after check the disks, useful trick.

Here is the command:

shutdown -Fr now

And if you on the other hand want to skip the fsck to work after reboot, you know that after some number of mounts the fsck is activated and a check disk is forced, and you may need to be sure this is not going to happen because you need your system to reboot fast, enter this command

shutdown -fr now

Small tip - Call a command from history

History is a Linux Operating System command, that lets you review the last commands used, so you can use it again.

To learn a bit more about history read: History Linux command, once you have found the command you need, there is no need to re-write it or cut and paste it, just enter ! followed with the number of the command you want to reuse, with no spaces in the middle, and that is:

Check this example:

history

small tip - List the biggest files in your home or other directory - du or ls -

When you are running out of disk space, you will want to know which are the biggest files in your home directory or in the disk itself.

This way if you find some big useless file you may erase it and recover the disk space.

This small command will do the job

du /home/user/* -s| sort -nr | head

Will show you the biggest directory and or file in your home directory.

If you want to list more lines just add the number of lines you want to list, at the end of the command.

du /home/user/* -s| sort -nr | head -50

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

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.

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

Small tip, System Memory information

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

cat /proc/meminfo

Small tip, how to recreate fluxbox menu

If you like me use Fluxbox may be aware that when you install a new program it is not automatically added to the menu, yes you can always edit it manually and add the new program to fluxbox menu.

But you can also run:

fluxbox-generate_menu

Then from the old menu choose restart, and voila, you will have almost all your installed applications in the menu.

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:

Convert Youtube videos to Cell phone format

If you want to play a youtube video on your cellular you may need to convert it to the format you cell phone can actually play, I have tested this process with a Sony Ericsson K550i and it worked great, I suppose it should work on almost all modern cellphones.

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'

Making grub menu to wait for you -change timeout-

On my PC I have installed, Mandriva, Ubuntu, Gentoo, Sabayon and Debian (my main Linux operating system), but when I turn it on, usually I did not get the grub menu, and I am forwarded directly to Debian, sometimes I have to restart the system to start another Linux flavor.

So, the solution was to put the timeout of grub menu to 15 seconds, so I have enough time to react even when I am not paying attention to the PC startup.

The timeout parameter is stored in the file

/boot/grub/menu.lst

So, to change it edit that file with your favorite text editor. (mine is vim)

How to play a DVD video ISO image

I have this new video camera Sony that records on mini DVDs, and I got a video from my daughter dancing for the mother's day, I copied it as an image to the hard disk of my Linux Operating System machine

cat /dev/dvd/ > $HOME/video.iso

But now how to play that iso image from my disk with out using my DVD player?

These are the simple commands needed.

sudo mkdir /media/iso

To create a mount point

sudo mount -t iso9660 -o loop /home/ggarron/dvd_video.iso /media/iso

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

Which runlevel are you in?

I wrote a little runlevel explanation, now I will show you how to know in which runlevel your Linux Operating System is actually running.

Which runlevel are you in?

Enter the following command:

sudo runlevel

My output is:

N 2

Switch to other runlevel

To do that enter:

telinit [number of runlevel]

Showing line numbers on vim

Sometimes you really need to see the number of the line where you are while editing a text file, if you like vi / vim, this will help you how to turn on and off the numbering of lines.

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

Another way to populate your apt-cacher

If you have some Debian machines already installed, and you plan to install some others, you maybe are going to use the net-install CD, which is the most common way to install Debian.

That may take a long time, to install all the Desktop Gnome or KDE, all the applications or servers, etc, and if you have just installed your apt-cacher server as me, you will not be able to use it this first time .... unless you populate it.

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

Syndicate content

This site is proudly hosted at Bluefur Hosting