Saturday, 21 September 2013

Linux

Basic Bash commands for Beginners

Hi :) in My Previous post i have mentioned about Bash shell. Now in this Article i will tell you SOME of the Important Bash command’s and How to use them in Debian, Ubuntu, Backtrack, Redhat, or in Fedora:) So 1st i will start in alphabetic order. :D
But Before i would like to show you something, when you execute any command in Terminal . And after that you want to check wheather it successfully run or not. JUst use
1
# echo $?
This is how it looks in Backtrack

This is how it looks in Fedora :)
When you get the output 0 . Then it means you programmed successfully run, otherwise not.
Bash command’s start with A. :)

1. alias Create an alias 
2. apt-get Search for and install software packages (Debian/Ubuntu/Backtrack)
3. aptitude Search for and install software packages Debian/Ubuntu/Backtrack)
1. ALIAS

This alias command allow us to create command shortcuts within your shell for example type this fllowing command.
1
# alias vipul='uname -a'
(uname -a will give you the details of you Kerenel)
1
# vipul
This is how it looks in Backtrack.
This is how it looks in ubuntu.
Image and video hosting by TinyPic
This is How it looks in Fedora.
Image and video hosting by TinyPic

2. APT-GET

APT is acronym for Advanced Package Tool. It supports installing packages over internet such as ftp or http. We can also upgrade all packages in single operations, which makes it more attractive.For example,
1
# apt-get install
1
# apt-get install samba
(Here Samba is software that can be run on a platform other than Microsoft Windows, for example, UNIX, Linux, IBM System, OpenVMS, and other operating systems. it allows to interact with a Microsoft Windows client or server, as if it is a Windows file and print server. I will post about samba configuration in my coming article.)
This is how it looks in Backtrack.
Image and video hosting by TinyPic
This is how it looks in Ubuntu.
Image and video hosting by TinyPic
Note i have use ‘sudo’. As in ubuntu i Have loged in as bipul account. And you can remove this Package by simply using this command
1
# apt-get remove samba
Now for Fedora no ‘apt-get’. As they belongs to Redhat family,They uses ‘Yum’ which i will show you in next, in Y segment. :)
 3. APTITUDE

Same for this Command in Ubuntu and Backtrack as They Belongs to Debian Family :)
1
# aptitude-get install samba
YOu can use MAN page i.e man aptitude and also for the Other Bash command.
Bash command’s start with B (Basics)

1. bzip2 Compress The file(s)
bzip2 will compresses you files using the Burrows-Wheeler block sorting text compression algorithm, and Huffman coding. I will explain this in details in coming article.
1
2
# bzip2 file file1 file2
#ls
Image and video hosting by TinyPic
This is How it looks in Backtrack whear i have 1st creacted Directory name hacker with mkdir.
After that i went inside it by command cd and created two file (File, File1) with command.touch Now i am compressing it. As you can see the extension .bz2 in both by command bunzip ,Now i will Decompress it by using
1
# bunzip2 File.bz2
Try the second file File1.bz2 from you side
Image and video hosting by TinyPic
This is How it looks in Ubuntu whear i have 1st creacted Directory name hacker with mkdir
After that i went inside it, and created two file (file, file1) with touch command. Now i am compressing it as you can see the extension .bz2 in both by bunzip command,Now i will Decompress it by using
1
# bunzip2 file.bz2
Try the second file file1.bz2
Image and video hosting by TinyPic
This is how it looks in Fedora whear i have 1st creacted Directory name hacker with mkdir
After that i went inside it, and created two file (file, file1) with touch command. Now i am compressing it,as you can see the extension .bz2 in both by bunzip command,Now i will Decompress it by using
1
# bunzip2 file.bz2
Try the second file file1.bz2
Bash command’s start with C (Basics)
1. CAL
It display calendar and present date :) . Simply type
1
# cal
Image and video hosting by TinyPic
This is How in Backtrack
Image and video hosting by TinyPic
That’s how in Ubuntu

2. CAT

It is used to create file and also display the content of files. And it is most important command. Let me show you How you can create File even. Write data inside it and Display it, via cat command.
1
# cat > hacker
(Then type the data what ever you like to type in hacker file. you can Give the extension of a file also like .html .txt what ever you like :) and Press Ctrl + D to Save it )
1
# cat > hack.html
(It will create html file with name hacker.You can type data inside file hack.html. And press Ctrl + D to save it )
1
# cat hacker hack.html
(It will show you the contents of data of both file which you have writeen inside. which is called Concatenate files.[Concatenation means putting multiple file contents together] You can have singal command also ‘# cat hacker‘)
Image and video hosting by TinyPic
That’s how in Backtrack it Looks
Image and video hosting by TinyPic
That is how in Fedora it looks like. :)
You can overwritte the existing data by simple double operator “>>” i.e
1
# cat >> hacker
The exact meaning of “>” is to take out the STDN Out put of the given file. “<" is to take out the STDN input from a file
1
# cat &lt; anaconda-ks.cfg
Image and video hosting by TinyPic
This is how it looks in Fedora
3 CD To Change Directory

This command is used to change the Directory. :)
1
# cd
1
# cd .
(One level up)
1
# cd .
(Remain in same Directory)
1
# cd --
(will move in last working Directory)
Image and video hosting by TinyPic
That’s how it looks in Backtrack
Image and video hosting by TinyPic
This is How it looks in Fedora
CLEAR

This command is used to clear the terminal screen. And i think i don’t need to give a screen shot for that:)
1
# clear

EXIT

This command will help you to get out from Terminal and shell. And again i think i don’t need to give a screen shot for that :)
1
# exit
GREP

grep Search files for lines that match a given pattern.Grep command often used with pipes.
1
# grep hack /etc/passwd
1
# cat /proc/cpuinfo | grep -i 'Model'
Image and video hosting by TinyPic
This is how it looks in Backtrack
Image and video hosting by TinyPic
This is How it looks in Fedora

GZIP

1
gzip
Compress or decompress named file. File extension (.gz) are created using gzip program which reduces the size of the named files using Lempel-Ziv coding (LZ77).
1
2
3
# gzip file  (compress)
# gunzip file.gz (decompress)
Image and video hosting by TinyPic
This is how it looks in Backtrack
Image and video hosting by TinyPic
This is how it looks in Fedora
head /tail Output the first/last part of files
head command will show the beginning of a file. By default it will show the first 5 lines of a file.tail will show the end of it. Here’s an example. (dmseg=dmesg – print or control the kernel ring buffer).Here’s an example.
1
2
3
# head -n 5 /var/log/dmesg
# tail -n 5 /var/log/dmesg
Image and video hosting by TinyPic
This is How it looks in Backtrack
Image and video hosting by TinyPic
This is how it looks in Fedora
head /tail Output the first/last part of files. Head command will show the beginning of a file. By default it will show the first 5 lines of a file. Tail will show the end of it. Here’s an example. (dmseg=dmesg – print or control the kernel ring uffer).Here’s an example.
1
2
3
# head -n 5 /var/log/dmesg
# tail -n 5 /var/log/dmesg
Image and video hosting by TinyPic
This is How it looks in Backtrack
Image and video hosting by TinyPic
This is how it looks in Fedor
a

No comments:

Post a Comment