Showing posts with label linux file system commands. Show all posts
Showing posts with label linux file system commands. Show all posts

Wednesday, September 28, 2011

Linux file system

1. Standard directory structure
  • / - the topmost
  • /dev - all the devices are accessible as files
  • /var - "variable" data such as mails, log files, databases
  • /usr - almost all the packages installed
  • /etc - con?guration files
  • /home - home directories for all the users
  • /root - home directory of the privileged user root
  • /mnt - used to mount other directories/partitions
2. File Attributes
  • To see the file attributes type ls -l on your terminal
ls -l
total 156-rw-r--r--  1 root root   1053 Sep 22  2010 anaconda-ks.cfg-rw-r--r--  1 root root 127004 Sep 22  2010 CHECKSUMSdrwxr-xr-x  2 root root   4096 Aug  3 00:02 Desktop-rw-r--r--  1 root root    100 Jun  6 22:14 svn-checkout-command
    •  It has 10 characters, first character is d if its directory and - if its file.
    • Next 9 characters are divided into three groups with a set of 3 characters each
    • First 3 characters - Owner of the file or directory
    • Next 3 characters - Group
    • Last 3 characters - Others
    • r - Read i.e. File or directory is readable
    • w - Write i.e. File or directory is writable
    • x - Execute i.e. File or directory is executable
    • -rw-r–r– means it has read, write but not execute permissions for the owner of the file, only read permissions for the group and only read permissions for others.
    • The third column of the command ls -l tells about the owner of the file, next column tells to which group it belongs
3. Changing the File attributes
chmod Changing the permissions of the file
Usage: 
$ chmod o+x Testing.java
$ chmod 655 Testing.java

4. Changing ownership
chown command is used for changing the ownership and also group of the file
Usage:
$ chown guest Testing.java
$ chown guest:guest Testing.java

5. File system commands
  • Deleting Files - rm
  • Copying and moving files - cp, mv
  • Creating directories - mkdir
  • Deleting Empty Directory - rmdir
$ rm Testing.java
//deletes the file Testing.java
$ cp Testing.java Copy.java
//creates the copy of Testing.java
$ mv Testing.java Test.java
//renames the file Testing.java to Test.java
$ mkdir newDir
//Creates directory newDir
$ rmdir newDir
//deletes directory newDir newDir should be empty.