Advertise

Monday, 16 September 2013

Beginners Guide to Linux [ Part 2 ]

All Series :-
Linux Part 1 [ First Series ]
Linux Part 2 - Current Page
Linux Part 3
Linux Part 4 [ Last Series ]
In this Part 2 of Beginner Linux Guide, you will see how to deal with command line, all basic and useful commands.




First Let us see some, time saving feature we call them shortcut keys.

1). Tab - I have discussed this in part 1 too. what it does is if there is no other files with similar words it will complete the wordsl
E.g,
/usr/local/my

What it will do is, it will make.
/usr/local/mysql as there might not be other file starting with my, now next :)

2). Wildcards - The most common wildcard is (*). This *(asterisk) will display all commands.. as in mysql too * means all. similar in linux too

E.g, ls /usr/local/* this will display all files and folders located in directories local.

3). ~ (tilde) - This character is short for the current users home directory, for e.g, mine is 
/home/Kro-Kite, similarilt it could vary as per your username. If you enter cd ~/my_dir, the linux will take you to 
Code:
/home/Kro-Kite(your_username_here)/mydir  folder.
4). (.) dot - This character refers to the current directory. For example if you have downloaded some file and you want to execute the program in same folder than just type
Code:
./my_program

5). (..) two dots - This directory will change the foder from current directory to parent directory. for E.g, If you are in /home/Kro-Kite/Desktop/WOH than typing 
Code:
cd ..

It will take you to /home directory

6). & (ampersand) - If you use this command this will help in running the file in background E.g,
Code:
yourfile &

this will let file to run in background.

Common Commands


1). ls - In Linux, ls means "dir". we have -al as parameter which means to list all files(including hidden files {do you remember when I(kro-kite) said any file which has (.) dot in intial letter means those files are hidden}.

now, what if we have huge no. of files there, than it will bring all pages at once and we will be able to see only last page, thus we have command called |more which pauses the display after each screenful. overall this command is 
Code:
ls -al|more
2). cd - This command means "change directory", so when cd is followed by directory name, than that directory becomes active directory, for e.g, suppose we are in /home/Kro-Kite/Desktop and when we type cd /usr/local than /usr/local will become current directory.

3). pwd - This means "print working directoy", and displays the current working directory.

File Management


The Most Important and Common things which you must know, -> How to Copy files, How to move files, and How to rename files in Command Line.

a). cp - "cp" is the command for copying the file, and how to use it.
Code:
cp [your source directory here] [directory where to put copied files]
E.g,
Code:
cp /usr/local/woh /var/www/

Above Command will copy woh file/folder to www folder of /var/ directory.

If you use "-r" after cp, it will copy all files as "-r" means recursive, For Example.
Code:
cp -r ~ /backup/username/
This will copy all files from current directory to your user folder in backup directory.

b). mv - "mv" command is for move and it is done in same way as copy command, try this yourself as i have already taught you above how to copy.

c). ln - This command is not much used but can be sometime very handy too, What this does is this creates link and link can be of two types, [One] Hard Link which means after making link if you do change in 1 directory the other will remain as it is, so not always recommendable and the [Second]-> [ln -s] is soft links which means when you make link and so some changes in 1 directory the other directory will get updated too.

d). rm - This command is used to delete the files, but remember to delete the files you need to have rights to delete the file, most of the time linux will ask for authentication but using "-f" command will force delete the file without asking you. Kro-Kite will continue with some more handy command below.
  • Deleting large number of files :- Use this command
    Code:
    rm -f *
    to delete all the files from the directory.
  • Removing Directories :- Use
    Code:
    rmdir directory_name
    to delete the directory.
  • Removing Directories and Files :- Use [-rf] to remove all folders, subfolders and directories all at once.
    Code:
    rm -rf /usr/local/apache
    all files and folder in apache directory will get out from your linux distro, Kro-Kite likes this lol.


d). mkdir - "mkdir" command will make directory.
Code:
mkdir blackbuntu

A new directory of blackbuntu will get created in current directory the one you are using.

e). Viewing and Editing Files:- 
  • cat filename |more :- "cat your_filename" will display all the content of your filename, If you dont use more than all the page will be scrolled to last, it doesnt matter if you have 1 page but if you have more than one page than its recommended to use "|more" or "|less" command. To terminate, press withour brackets
  • vi filename :- This command will provide you simple and standard text editor. There are other text editor to choose too like :-
    Code:
    emacs your_filename -> This will open your file with emacs text editor.
    kwrite your_filename -> This will open your file with kwrite text editor.
    nedit your_filename -> This will open your file with nedit text editor.
    vim your_filename -> This will open your file with vim text editor.
  • Finding files If you are thinking how to find files than Kro-Kite will teach you here how to find files what you need to do is just follow below commands:-
    Code:
    1). find / -name "filename"  -> This command wil find your file of "filename" from root directory. "-name" is command type and "find /" means find from root directory, as we know whole linux is setup in 1 directory thus it will search from "/" root.
    Now, we have command
    2). locate "filename" -> This command will find the file of name "filename", it is quick.


4). Shutting Down
  • exit - If there is one shell running than system will be shutdown, if there is more than 1 shell than it will just logout current user
  • shutdown -h now - This command when used by root user will shutdown the system to a halt.
  • halt- This command will halt the machine.
  • reboot- Kro-Kite think he dont need to explain what this will do.
  • reset- This command will reset the machine if it gets frozen, in linux few times when you type something than its not visible but machine will do its work whatever valid command you have type.
  • poweroff- Similar to shutdown.
Copyright © Kro-Kite [Read Common Creative License at Footer]
 
World of Hacker © 2011 Creative Commons License
World of Hacker by KroKite is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Based on a work at http://www.worldofhacker.com.
Permissions beyond the scope of this license may be available at https://groups.google.com/forum/#!newtopic/hackerforum.