Running previous commands in Linux

Most non linux people tend to be taunted by the Linux command line, it’s no beast nor is the user behind it a super geek just because you see him hammering away at the keyboard with lines after lines of commands. Chances are he is repeating commands or changing commands here and there to get some results. In Linux the first time takes time and practice to produce accurate results. This is what most sysadmins spend their time doing but once you get the hang of it, it became a walk in the park.

How often do you repeat commands while using the command line? I do this all the time but sometimes it’s good to learn some shortcuts now and then to reduce repetitive tasks and improve efficiency.

When you type a command in the command line, it’s saved into the .bash_history file within the home directory. The history file will hold the last 500 commands. To view them you can use “history” or “history | less” if the result is too long. The history file is also frequently use for user/security audits and RCA work.

You will that within the output below each line is numbered, these numbers will come in handy later in this tutorial.

danny@python:~> history
1  uname -r
2  man mount
3  PS -EF
4  ps -ef
5  ps -ef | grep kopete
6  kill -9 22632
7  /sbin/ifconfig
8  ping google.com
9  ping 192.168.0.1

If you want to execute the last command you typed in again you would normally have to scroll up with the arrow key but this can also be done with “!!“. See sample below.

 danny@python:~> ls -l
total 40
drwxr-xr-x 2 danny users 4096 2007-10-11 13:16 bin
drwxr-xr-x 4 danny users 4096 2007-10-11 16:11 deluge
drwx------ 4 danny users 4096 2007-10-17 22:38 Desktop
drwx------ 2 danny users 4096 2007-10-11 13:16 Documents
drwxr-xr-x 2 danny users 4096 2007-10-11 13:16 public_html
danny@python:~> !!
ls -l
total 40
drwxr-xr-x 2 danny users 4096 2007-10-11 13:16 bin
drwxr-xr-x 4 danny users 4096 2007-10-11 16:11 deluge
drwx------ 4 danny users 4096 2007-10-17 22:38 Desktop
drwx------ 2 danny users 4096 2007-10-11 13:16 Documents
drwxr-xr-x 2 danny users 4096 2007-10-11 13:16 public_html

You could also execute a command from the history file by referring to the corresponding line number by using “![##]“. See sample below.

danny@python:~> history
1  ls -l
2  ls -la
3  history
4  cd /
5  cd -
6  cd /nfs
7  cd /sto
8  ls
9  history
danny@python:~> !3
history
1  ls -l
2  ls -la
3  history
4  cd /
5  cd -
6  cd /nfs
7  cd /sto
8  ls
9  history
10  history

Using a string in place of the line number is also possible. The syntax for this is “![string]“. See sample below. The string value is matched against entries in the .bash_history file and the first matching entry will be excuted. For example if the “history” command existed on line 10, 100 and 450, line 450 would be returned.

danny@python:~> history
1  ls -l
2  ls -la
3  history
4  cd /
5  cd -
6  cd /nfs
7  cd /sto
8  ls
9  history
10  history
danny@python:~> !history
history
1  ls -l
2  ls -la
3  history
4  cd /
5  cd -
6  cd /nfs
7  cd /sto
8  ls
9  history
10  history

Hope you find this helpful. Drop me a comment if you have questions or comments.

Kings Of Chaos

Into online text based roll playing games? If your answer is yes then it will certainly be worth your time checking out Kings Of Chaos.

In Kings of Chaos, you are in command of an army of humans, elves, dwarves, orcs, or undead. To be successful, you must manage your army and defeat your enemies. You must keep your troops in top condition and recover from losses. A powerful army will be strong in all four aspects of the game: attacking, defending, spying, and counter-intelligence. This makes it important to keep your forces and efforts relatively balanced in all these areas. There are a number of ways to build your army and thus generate more gold and become more powerful: you can get people to click on your Unique Link, giving you an additional soldier each time it is clicked. In this age, you can click links up to 5 times per 24 hours. You can also recruit other people as your officers – for every two soldiers your officers gain from their links, you will gain an extra soldier. You may also buy mercenaries – soldiers that will fight for you but will not generate extra gold.

KOC started out as a simple experiment with PHP and MySQL by 4 high school juniors. It was a hit on campus and eventually out grew the high school servers it was hosted on with over 15,000 page views a day. KOC moved onto it’s own server and domain was really to take on the world.

Me, Alan, Abi and few others started playing KOC about 2 years back. It spread like wild fire through the office. Everyone and anyone was on KOC. Strategizing, building alliances, planning take overs, recruiting members, clicking to get more soldiers. Man, I miss those days.

Sounnd good? Get started here.

/usr/local/bin/oinkmaster.pl: Error: the output directory “/etc/snort/rules” isn’t writable by you.

I recently upgrade my IPCop to version 1.4.16 but my Snort (Intrusion Detection System) failed to load the latest rules set. The install logs revealed the error below.

/usr/local/bin/oinkmaster.pl: Error: the output directory “/etc/snort/rules” isn’t writable by you.

The fix was simple. simply change the permission for the “/etc/snort/rules” folder so that the owner is “snort” using the command below.

# chown -R snort:snort /etc/snort/rules
# ls -l /etc/snort/ | grep drw
drwxr-xr-x 2 snort snort 4096 2007-09-18 18:20 rules

How to enable DMA in Linux

While loading K3b to burn a DVD earlier today I received a warning that my DMA support had been turned off and write speeds would be slow. DMA is normally enabled by default, provided the disk supports it and is handled by the OS.

What is DMA?

DMA (Direct Memory Access) is the mechanism which allow your disk device to move data directly to memory without passing through the CPU. This shortens the distance the data needs to travel and reduces the load on the CPU thus improving performance and quality of the data. DMA eliminates errors that might occur when data is passed through the CPU. For example, you might hear pops and click while playing an audio CD or your video quality might be distorted when reading directly from a cdrom/dvd drive with DMA turned off.

I will have to investigate what happen later. But for now this is how I enabled DMA support for the DVD+-drive the manual way. read more

Firefox 2.0.0.7 released

The is a new version of Firefox out. Firefox 2.0.07.

2.0.0.7 is a security update to prevent an attacker from executing code via Quick Time Media Link file. MFSA 2007-28

Firefox will automatically download the latest update and prompt you to install. If you prefer the manual approach the Firefox is available download here. Release notes for 2.0.0.7 are availble here.

I’m running 2.0.0.7 now, are you?

© 2008-2009 The Danesh Project
Powered by Wordpress and made by Guerrilla. Best viewed in Mozilla Firefox