Crazy Commands:
1. Another wonder of a simple shell variable is
One more dirty way to hack into the system is through continuous reboots, resulting in the total breakdown of a Linux machine. Here’s an option that you need root access for. Edit the file
1. Another wonder of a simple shell variable is !$
. Let’s say you have to create a directory, go into it and then rename it. So the flow of commands would be:
$ mkdir your_dir
$ mv your_dir my_dir
$ cd my_dir
Remedy: Well, Linux has a shorter and quicker way:
$ mkdir your_dir
$ mv !$ my_dir
$ cd !$
!$
points to the last string in the command string. This is useful in various scenarios where the last word of command string is to be used in subsequent commands (almost with all Linux commands like vi
, tar
, gzip
, etc). 2. Do you want to know what an
ls
or a date
command does internally? Just run the following code to get to know the basic block of any Linux command: $ strace -c /usr/bin/ls
strace
is a system call monitor command and provides information about system calls made by an application, including the call arguments and return value.3. What if you want to create a chain of directories and sub-directories, something like
/tmp/our/your/mine
?$ mkdir -p /tmp/our/your/mine
4. One very interesting way to combine some related commands is with
&&
. $ cd dir_name && ls -alr && cd ..
5. Now for some fun! Have you ever tried checking the vulnerability of your Linux system? Try a fork-bomb to evaluate this:
$ :(){ :|: & };:
It’s actually a shell function; look closely and it’s an unnamed function
Remedy: How to avoid a fork bomb? Of course, by limiting the process limit; you need to edit
:()
with the body enclosed in {}
. The statement ‘:|:
’ makes a call to the function itself and pipes the output to another function calls—thus we are calling the function twice. &
puts all processes in the background and hence you can’t kill any process. Finally ‘;
’ completes the function definition and the last ‘:
’ initiates a call to this unnamed function. So it recursively creates processes and eventually your system will hang. This is one of the most dangerous Linux commands and may cause your computer to crash!Remedy: How to avoid a fork bomb? Of course, by limiting the process limit; you need to edit
/etc/security/limits.conf
. Edit the variable nproc
to user_name hard nproc 100
. You require root privileges to modify this file.
No comments:
Post a Comment