Saturday, March 28, 2015

Basic Ubuntu/linux Commands


"""
Linux commands are case sensitive(capital letters are different from small letters)

==============        ==============
   Command            Action
 =============        ==============

 1. ls           lists directories and files

 2. cd           changes current directory

 3. cat          concatenates(add) and displays files

 4. echo          Displays arguments to the screen(print)

 5. man          Displays the manual.




 Ex 1:

 ls name_of_the_directory  
 note:if you have spaces in the name of your folder,you've to use "folder name"

 Ex:2

 ls "name of the directory with spaces"
 Shows all the files and directories inside the directory on which ls is performed


Ex:3

cd directory 

this can be bit confusing at first.Every directory is in some hierarchy.you cannot jump from one path to other..
Check the screenshot.

use pwd to know where you are.
Your prompt will start at /home/username
On my Desktop you can see there is only one directory D.
Inside D there are many directories.
To access my directories in D i've to use this commands.
cd Desktop/java
but for you to access usr directory which is in root directory you have to use this

cd /usr


Ex:4

echo My name is Ajay

Displays the line on terminal

echo $PATH 

Output

/usr/local/sbin:/usr/local/bin:


This may vary from user to user


Ex:

man cd 

man man (funny)

displays the documentation page of cd

well i know command cd so i can type man cd.what if i don't know which command to search for but i know just a word.
I want to edit a file.so i'll search a term edit rather a command.

doing vague search on man

man -k search_term



Output:

cam@hack3r:~/Desktop$ man -k edit
atobm (1)            - bitmap editor and converter utilities for the X Window...
bitmap (1)           - bitmap editor and converter utilities for the X Window...
bmtoa (1)            - bitmap editor and converter utilities for the X Window...
dconf-editor (1)     - Graphical editor for dconf
desktop-file-edit (1) - Installation and edition of desktop files
desktop-file-install (1) - Installation and edition of desktop files
djvused (1)          - Multi-purpose DjVu document editor.
ed (1)               - line-oriented text editor
..........      ....................
........     ...................
..........      ...................
Many more editors displayed


*** Extra
There is a command called tac reverse of cat command.
Can you guess what it does??
cat displays contents of file,so tac should display contents of file in reverse order[last line first;first line last].

nano is a tex editor that can be accessed from terminal by typing nano

cam@hack3r:~/Desktop$ nano trytac.txt     ==>check how to use nano
cam@hack3r:~/Desktop$ tac trytac.text      |
             |
i'm in last lines                          |
i'm in 2                                   |
i'm in 1                                   |
cam@hack3r:~/Desktop$                      |
                                           |
how to write and save in nano:    <=========

nano filename
A text editor will open in terminal don't panic.
type some lines hit enter...
now to save (ctrl+o) but now the cursor blinks after trytac.txt press enter.
Now you need to press (ctrl+x) to exit out of the editor







"""
Learn python for fun.The popular blog with questions and answers to the python.Solutions to facebookhackercup,codejam,codechef.The fun way to learn python with me.Building some cool apps.

No comments:

Post a Comment