top of page
  • Writer's pictureblkrishnarao

A Brush up on Unix Fundamentals Part - 03 | Linux File Directory Management | Unix 101

Updated: Apr 16

The following opinions expressed in this post are my own and in no way connected to my employer. 



Common type of files:

         

a) Ordinary/General File : text/data/instructions/scripts

b) Directories : same as folders

c)  Special Files : shortcuts/aliases


Listing files:
ls     	: list all files and directory
ls -l  	: list all information about the files
ls -ltr	: list all information and sort them in reverse order of time

Eg:

drwxrwxrwx    2    user    group   4004   Dec 22   10:40  file.txt
col 1  		col 2   col 3  col 4  col 5   col 6    col 6  col7

col 1  --  type and permission on file (details will follow later)

col 2  --  memory consumed (size)

col 3 --   owner of file

col 4 --   owner's group

col 5 --   file size

col 6 --   date and time

col 7 --   file/directory name


Values in Column 1 (col 1) indicate:

-        regular file (text/binary/executable)

b       block special file (block device file such as a physical hard drive)

c       character special file

d       directory

l        symbolic file (acts as a shortcut)

p       named pipe (mechanism for inter-process communication)

s       socket used for inter-process communication


We can use wild characters for matching a pattern:

*     to match 0 or more characters

?     to match with single character


Hidden file are those which start with '.' (dot).

Usual examples are profile file for a user and other files which contain confidential information as ssh or shell configuration files

.profile /.bash_profile    		Bourne shell init script
.kshrc                          	kourn shell init script
.cshrc                        	c shell script
.rhosts                   		remote shell configuration file

Creating a new file:

Using visual Editor (vi)  

Eg:       vi filename.txt
Press 'i'            	insert mode
Press 'l'            	move right side
Press 'h'           	move left side
Press 'k'           	move upside
Press 'j'            	move down
Shift + ZZ       		to exit from vi
:wq!                 	to exit by saving             
:q!                    	to exit without saving

Using touch                               

touch filename.txt

Viewing a file:
cat filename.txt                        displays file content
cat filename.txt -b                    to display with line number
more filename.txt  			display some content of file (press space bar to read more  or press q to exit)
view filename.txt                    	view file in vi in read mode

Copy file:
cp filename.txt filename_copied.txt

Move file or rename a file:                                                           
mv filename.txt rename.txt --> renames a file in same directory
mv  filename.txt  /directory/   --> moves a file to a directory
Deleting a file:
rm  filename.txt  --> deletes a file
rm -rf directory/ --> deletes files and directory

Count number of lines in a file:
 wc filename.txt

       	2      19    103    filename
    	col1  col2   col3     col4

col1   -- number of lines in file

col2   -- number of words in file

col3   -- number of bytes in file

col4   -- filename



Working with Directory:
cd ~                                

takes to home directory of current user

cd -                                

 takes to previous directory 

cd /first/second/third/directory   

Absolute pathname (starts from root /)

cd fourth/fifth                     

Relative pathname ( starts from current directory)

pwd                                 

provides path of current directory

ls -ld  directory                   

displays directory with details

mkdir    dir                        

make a directory

mkdir -p dir/dir2/dir3              

checks existence of parent directory and creates if missing

rmdir dir                          

remove the directory


File/Directory Permission:

       

read, write, execute       read, write, execute         read, write, execute

owner of file               owner's group mates         outside group audience       

             
rwx  -- read write execute

owner permission: determines what kind of operation can be performed on file
group permission:  determines what people of same group can do on file (dba/dev)
others permission:  determines what people outside ur group can do with file

Changing Permission:

                  chmod  777  filename/directory                     : gives permission on a file/directory only
                  chmod -R 777 directory                               : gives recursive permission to all files
                  chown   user:group       file                           : change owner/group of file owner

Number and their significance in giving permission:

                  0       no permission                                                           ---

                  1       execute permission                                                   --x

                  2       write permission                                                       -w-

                  3       execute and write  permission                                  -wx

                  4       read permission                                                         r-- 

                  5       read+execute permission                                           r-x

                  6       read+write permission                                               rw-

                  7       all permission                                                            rwx 

                 


2 views0 comments

Recent Posts

See All

Comments


bottom of page