Thursday, June 27, 2013

Crazy Commands

1. When commands on CLI get longer and you need to edit it try this:
CTRL+E -- move to end
CTRL+A -- move to start
CTRL+W --delete word.

2. Use !$ that points to the last string in the last command.Many times we need last word of command in next command.

3. What ls or date does internally? Know the basic block of a command:
#strace -c /usr/bin/ls

strace is a system call monitor command and provice info about system calls made by an app.

4. Create a chain of dir:
#mkdir -p /tmp/dir1/dir2

5. Combine related commands:
#cd dir1 && ls && cd ..

6. fork-bomb
$ :(){:|:&};:

This is an unnamed function :() and body inside {}
Statement :|: makes a call to the function itself, and pipes the output to another function call.
& put all processes in bg.
; finishes the function.
: initiates a call to this unnamed function.

7. Edit /etc/inittab and modify line id:5:initdefault: to id:6:initdefault:
User mode 6 is for reboot. So the system keeps on rebooting.
As rescue, modify GRUB config and login to single user mode. Revert the changes.


No comments:

Post a Comment