Monday, April 14, 2008

Linux Commands - Part 2

ls - This command is use to list files and folders.

   ls                       {list current directory}
   ls /media         {list /media files and folders in  directory media }
   ls -l                   {list permission}
   ls -a                  {list all, including hidden files, etc}

cp - This command is use to copy files and folders

   cp  test /home/melick { copy test file to /home/melick folder}
   cp  /root/s.txt  .        {copy s.txt to current directory (.)}
   cp -r /root  /home/melick      {copy entire root folder to melick}                 

mv - This is used t move and rename files and folders

  mv  test /home/melick       { move test file to /home/melick folder}
  mv  /root/s.txt  .   { move s.txt file in /root to current folder (.)}
  mv test1 test2         {rename test1 file to test2}          

rm - This is used t delete files and folders

  rm /home/Melick/test      {delete the test file}
  rm -r /home                        {delete the entire home folder}                
 rm -i /home    {ask confirmation to delete}    

mkdir - This is used to create folders.

  mkdir Melick            {create the Melick folder in current directory}
  mkdir /home/Sachika     {create Sachika folder in home directory} 

rmdir  - This is used to delete empty folders

  rmdir Melick            {delete the Melick folder in current directory}
  rmdir /home/Sachika    { delete Sachika folder in home directory}   

ln - This is used to create links (something like shortcuts) 

  ln -s test  shorttest             {create link 'shorttest' to file test }    
  ln -s /home/test  shorttest 
                         {create link 'shorttest' to file test ('home' folder)}
  ln test test2  
 {create hard link 'test2' to file test.create a nother copy of test}              

 Out put of above commands 

lrwxrwxrwx 1 melick melick    4 2008-12-30 00:21 shorttest -> test
  -rw-r--r-- 2 melick melick    0 2008-12-30 00:20 test
  -rw-r--r-- 2 melick melick    0 2008-12-30 00:20 test2

Linux Commands - Part 1

chmod this is the command hat we use to change the permission.

 ex:-

chmod 777  test
{change the permission to 777 the file test in the current directory}
chmod 777 /home/melick/test
{change the permission to 777 the file test in the /home/melick directory}
chmod  g-r test {remove read permission in the group}
chmod  g+r test {add read permission in the group}
chmod  o-r test {remove read permission in the other}
chmod  o+r test {add read permission in the other}
chmod  u-r test {remove read permission in the user/owner}
chmod  u+r test {add read permission in the user/owner}
chmod  u=r test {read permission only to the user/owner}
chmod  u=w test {write permission only to the user/owner}

chownthis command is use to change the owner of the file.

chown root test 
  { if we want to change ownership to the file to the root }
-rw-r--r-- 1 root melick 0 2008-12-21 21:11 test
chown Melick:Sachika test
{change 'test' files owner as Melick and group as Sachika}           

chgrp - this command is use to change the group of the file.

chgrp root test     {change the group to 'root' in the file 'test' }