Search This Blog

Sunday, 3 July 2016

LINUX FILE SYSTEM AND COMMAND LINE UNDERSTANDING

Unix Command Line Interface

To get around Unix / Linux file system we use the following commands.
But first look at the following Linux file structure,

most files in Linux are stored in directory hierarchy shown here,

                                        root       /
                                                     |
                ----------------------------------------------------------
                 home       usr            etc        bin            var          
                    |              |                 |                            |
                   Pi            bin             X11                     log



for example we have command line,

pi@raspberrypi ~ $  

home directory is

/home/pi

to find home directory use     whoami

to find present working directory use     pwd

to get back to home folder use teldar key    cd ~

to change directory use      cd /   (forward slash)  to goto root directory

to change to etc use    cd /etc

etc  store many of the system configuration files

to see the contents of etc use "  ls  "   list command

list command has certain options

ls -a  list all system files including the hidden files

ls -l will list all files length wise in a directory

ls -p will show a slash after directory so we can easily distinguish a file

from a directory

ls --color will show the types of files via color

to combine more than one option we can use " ls -lap"  option this will

combine all the previous option in one command

to take us back one directory use command " cd . . "

to take us back two directories use command " cd .. / .. "

single dot represent one current directory "  cd . "

to list the root directory component use

to root then type   ls  list command

/bin

this root folder is for commands and binaries

/sbin

sbin is for systems and admin commands

/usr

has usr related stuff it also has its own usr/bin and usr/sbin folder

/var

/var stands for variable it also has var/log folder

/home

is user directory

/mnt

this is for mount this for mounting any external drive we can even mount

folders

/dev

device interfaces for any hardware

/lib

this for programs and libraries

To make a directory
===============

use mkdir dir1

To remove a directory
=================

use rmdir dir1

this will throw an error if their is some file in the directory

but if you know what you are doing then you can do the following,

to create file in the directory use touch command

touch test

to remove and directory that contains file contents use

rmdir -rf dir1

r and f options

r stands for do the removing recursively drilling down the sub files you want to remove

f stands for force this to happen

Moving and copying files and directories
===============================

Use the cp command to copy

create a file

touch filename1

then use cp to copy one file to second file

cp filename1 filename2

To move a file from one file location to other use

mv filename1 filename2

to copy host files in etc to home/pi use

cp /etc/hosts /home/pi

to rename it use

cp /etc/hosts /home/pi/localhost

cp will work but mv will not work because user pi doesn't have permission

to modify files in etc directory

cp -R dir1 dir2

this will copy everything in this folder and beneath it

If you want to find out man command

man mv

No comments:

Post a Comment

Linux Partitioning Disk & Formatting commands

Linux Partitioning Disk & Formatting commands fdisk man fdisk pi@rasberrypi ~$ sudo fdisk -l