Thursday, October 4, 2012

Directory Structure and basic commands to start using linux



Directory Structure In 'Linux' :
' / '  - Root Mount Point
' ~ '  - Home Directory For User
' . '  - Reference To Current Directory
' .. ' - Reference To Parent Directory Of Current Directory


  
Purpose Of The Above Directories:

root :
Like Administrator In Windows.




bin/sbin
Contains Files Which Can Be Accessed From Any Where .
Eg: date , cal ....

dev:
Contains Files Like "Device Drive Files"(Eg:Device Driver For USB etc) Which Are Necessary For Applications To Run On OS.

etc:
Contains Various Files And Folders For Modification Of System Properties (Like Control Panel In Windows). Basically Accessed By 'root/admin' user. 

home:
Contains Various Folders For Different Users On The Network.


Command/Shell Prompt In Linux:

$ -  For Regular User
# -  For Root/Admin User

[user@Host WD]$ - Is The Way We See The Terminal Prompting Us.

Eg: [user2@system5 ~]$ - Implies we are currently working in '~' (Which is The Home Folder allotted For user2) and he is working on system5 in the network.
'~'means home folder.

Basics Commands :

Imagine This Is The Directory Structure Present In A Linux System:


vi editor

ls - to list files and folders in current working directory

cd - change directory
eg : Assume We Are Currently working In 'dir1' 
1. ' cd dir2 ' --- changes the current directory to 'dir2' from 'dir1' .
2. ' cd .. ' -----changes current directory to parent directory i.e; 'user2'  in this case.

cal - Shows calender for current month.

clear - To clear screen for a good visibility .

mkdir - To Create A New Directory (make Directory) in The Current Working Directory.
eg : ' mkdir dir1 ' - creates a new directory ' dir1 ' in current working directory

cat - For Editing Files
eg : Assume Current Directory is 'user2'

1. ' cat>test.c ' -- Creates a New File Named 'test.c' in Current Directory And Prompts Us To         Enter Data Into The File.
Note : [ctrl+d] to stop entering data .

2. ' cat test.c ' -- Displays The Contents Of  test.c ,if it already exists.

3. ' cat>>test.c ' -- Opens test.c to append (or) add at the End Of File .

Note : Editing A File Using  ' cat ' Command Is not possible .

cp  - To Copy a File To Other Location/Locations.

eg : ' cp file1 file2 ' -- Copies Contents in 'file1' to 'file2'

mv - This Is Like Cut & Paste In Windows .

eg: ' mv file1 file2 ' -- copies contents of 'file1' to' file2' and deletes 'file1'.

rm - Remove An Existing File

eg : ' rm file1 ' -- deletes 'file1'

rmdir - To Remove An Empty Folder

rm -r - To delete A Directory (Recursive Deletion)



linux commands for beginners


Task :
1. Assume Our Current Working Directory Is 'dir1'

Task 1: To Copy test.c to 'dir1' directory .
Command :  cp  ../test.c  dir1
                       or
              cp  ../test.c  ./

Task 2 : Batch Removal of Directories .
Command : rm -r  dir1  dir2


Vi Editor Commands:

' vi welcome.c ' - Creates And Opens A File Named welcome.c in vi Editor For Editing.(Remember we can not edit files Using cat command,so using an editor like vi editor is mandatory to modify/edit a file).

In Vi Editor : Use 

' esc :wq '  -To Save And Exit
' esc :w '    -To Save 
' esc :q '     -To Exit with out saving

Note : press 'a' to append or modify or to take vi editor into INSERT mode.

Note : ' ctrl+d ' in Linux is like ' alt+f4 ' in Windows , which is used to close the current window/application/task .

' ctrl+d ' can also be used to logout from current user .
' poweroff ' or ' halt ' commands in terminal will directly shutdown the system .













 






No comments:

Post a Comment

Please Comment...