Skip to main content

LINUX COMMANDS -1

LINUX COMMANDS

ls - list directory contents
 $ ls

file1  sub_dir1

who am i – this command identifies the invoking user and list the username, terminal line ,date and time of login
 $ who am i

anuj     pts/1        2015-01-03 17:10 (:0)

who - (show who is logged on) this is more powerful than who am i . It displays the  data about all the users that have logged into the system . It is crucial for multi-user operating system

 $ who

anuj     tty7         2015-01-03 16:31 (:0)
anuj     pts/1        2015-01-03 17:10 (:0)

pwd     print name of current/working directory
 $ pwd

/home/anuj/dir1

mkdir    make directories
rmdir remove empty directories

 $ mkdir dir3
 $ ls
dir3  file1  sub_dir1
 $ rmdir dir3
 $ ls
file1  sub_dir1
 $ rmdir sub_dir1
rmdir: failed to remove `sub_dir1': Directory not empty

cd change directory
 $ cd sub_dir1
 /sub_dir1$

 man - an interface to the on-line reference manuals . man is the system's manual pager.
 /sub_dir1$ man pwd
// this will generate the manual for the command

clear clear screen


File Manipulation

cat concatenate files and print on the standard output

Create file
 $ cat > file1
this is a file
// press CTRL + D to come out of the file typing section

view file
 /sub_dir1$ cat file2
this is my second file which is in direcotry sub_dir1 wich is a sub-directory of dir1

view 2 files simultaneously
// here file1 is a file in this directory and file2 is a file in a subdirectory named sub_dir1
//So we have written full path of file2

 $ cat file1 sub_dir1/file2
this is a file
this is my second file which is in direcotry sub_dir1 wich is a sub-directory of dir1

view 3 or more files
 $ cat file1 sub_dir1/file2 file1
this is a file
this is my second file which is in direcotry sub_dir1 wich is a sub-directory of dir1
this is a file

copy files

move file
// this shows directory contents
 $ ls
file1  sub_dir1
 $ mv  sub_dir1/file3 dir1
// this now shows the new directory contents
 $ ls
dir1  file1  sub_dir1

delete file
// this shows directory contents
 $ ls
dir1  file1  sub_dir1
 $ rm file1
// this now shows the new directory contents
 $ ls
dir1  sub_dir1

Calculator

 $ bc
bc 1.06.95
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
5+4
9
2+5*8
42
2+5*8/4
12

WildCard Characters

  * character : It represents all characters including an empty space
// we have tried to match the sub_dir1 directory

 $ ls -x *_dir1
file2
          // we got our match but the terminal display its sub – files

  ? character : It represents a single character

 $ ls d???
dir1

  [] enclose a list of character where the match is on any single character enclosed  in the bracket

 $ ls d[i]*
dir1

Ownership & Protection
There are 3 classes of user who may have access to a file :

  Owner: The owner is the user who initially created the file.
  Group: Several users can be combined into a usergroup & so there is a group ownership associated with each file & directory.
  Public: All other users od Unix system that is , anyone who has a username and can gain access to the system.

There are 3 types  of permission :

  Read: User can look at the contents of that file.
  Write: User can change the contents of that file.
  Execute: User can use the file as a Unix command.
changing Permission with chmod


Two ways for doing this:
- As an absolute value given as an octal number.
-Symbolic mode

1) Absolute Value

 $ cat > file1
this is your file

 $ ls -l
total 4
-rw-rw-r-- 1 anuj anuj 18 Jan  7 21:04 file1

 $ chmod 644 file1
 $ ls -l
total 4
-rw-r--r-- 1 anuj anuj 18 Jan  7 21:04 file1

 $ chmod 777 file1
 $ ls -l
total 4
-rwxrwxrwx 1 anuj anuj 18 Jan  7 21:04 file1

2) Symbolic Mode

$ cat > file1
this is your file

$ ls -l
total 4
-rw-rw-r-- 1 anuj anuj 18 Jan  7 21:04 file1

$ chmod a=r,u=r+w+x file1

$ ls -l
total 4
-rwxr--r-- 1 anuj anuj 18 Jan  7 21:04 file1

User Mask

  umask - set file mode creation mask

$umask
0002

$umask 777
$ umask
0777
Input Output Process

Three standard files:
- Standard Input
- Standard Output
-Diagnostic Output

- Redirecting Standard Input

 $ cat file1 > sub_dir1/file3

// you can check the contents by using cat command

 $ cat  sub_dir1/file3
this is a file


- Redirecting Standard Output

$ ls -l >list_file

// you can check the contents by using cat command
$ cat list_file

total 76
drwxr-xr-x 2 anuj anuj  4096 Jan  8 08:20 Desktop
drwxr-xr-x 2 anuj anuj  4096 Jan  4 19:25 Documents
drwxr-xr-x 2 anuj anuj  4096 Jan  8 19:06 Downloads
-rw-r--r-- 1 anuj anuj  8445 Jan  4 19:18 examples.desktop
-rw-rw-r-- 1 anuj anuj 26032 Jan  8 18:35 linux_1348129829.jpg
-rw-rw-r-- 1 anuj anuj     0 Jan  8 19:16 list_file
drwxr-xr-x 2 anuj anuj  4096 Jan  4 19:25 Music
drwxrwxr-x 2 anuj anuj  4096 Jan  7 21:04 npgc
drwxr-xr-x 2 anuj anuj  4096 Jan  4 19:25 Pictures
drwxr-xr-x 2 anuj anuj  4096 Jan  4 19:25 Public
drwxr-xr-x 2 anuj anuj  4096 Jan  4 19:25 Templates
drwxr-xr-x 2 anuj anuj  4096 Jan  4 19:25 Videos

-Appending Standard Output
$ cat > xy_file
this is a file
anuj@anuj-G31M-ES2L:~$ cat > xy2_file
i want to append this to xy_file
anuj@anuj-G31M-ES2L:~$ cat xy2_file>>xy_file
anuj@anuj-G31M-ES2L:~$ cat  xy_file
this is a file
i want to append this to xy_file







Comments

Popular posts from this blog

PROGRAM TO PRINT COLOURS OF RAINBOW ACCORDING TO THE NO. INPUTTED BY THE USER

#include,stdio.h> #include<conio.h> void main() { int ch; printf("INPUT A NUMBER\n"); scanf("%d",&ch); switch(ch) { case 6: printf("Red"); break; case 5 : printf(" Orange"); break; case 4 : printf(" Yellow"); break; case 3 : printf(" Green"); break; case 2 : printf(" Blue"); break; case 1 : printf(" Indigo"); break; case 0 : printf(" Violet"); break; default : ("wrong input "); } } SIMPLE PROGRAMS FIND TYPE OF THE TRIANGLE TEMPERATURE CONVERSION COMMISSION OF A SALESMAN PRINT NUMBERS IN DESCENDING ORDER BIGGEST NUMBER AMONG THREE NUMBERS CALCULATE DIVISION A YEAR IS LEAP OR NOT A NUMBER IS ODD OR EVEN PRINT THE SQUARE ROOT ELSE PRINT N TO THE POWER 5 PRINT A NEW NUMBER BY ADDING 1 TO EACH DIGIT OF THE NUMBER PRINT THE NO. OF CURRENCY NOTES ACCORDING TO THE AMOUNT ENTERED DATA STRUCTURES ENTER DETAILS OF A STUDENT ENTER DETAILS OF A ST...

PROGRAM TO FIND OCTAL OF A NUMBER

LIST OF PROGRAMS #include<stdio.h> #include<conio.h> void main() { long int n,oct=0,r=1,pow=1;  clrscr(); printf("Enter a number "); scanf("%ld",&n); if(n<0) printf("WRONG INPUT"); else {  if(n<=7&&n>=0)  oct =n;  else  {  while(n>0)  { r=n%8; oct=oct+(r*pow); n=n/8; pow=pow*10;  }  }  printf("OCTAL = %ld",oct);  getch(); } } LIST OF PROGRAMS

PROGRAM TO PERFORM BINARY SEARCH USING RECURSION

LIST OF PROGRAMS #include<stdio.h> #include<conio.h> int binary(int ,int ); int a[10],md,s,c=0; void main() { int n,i; clrscr(); printf("ENTER LIMIT \n"); scanf("%d",&n); printf("ENTER ARRAY\n"); for(i=0;i<n;i++) { fflush(stdin); scanf("%d",&a[i]); } printf("ENTER NUMBER TO BE SEARCHED"); scanf("%d",&s); c=binary(0,n-1); if(c==-1) printf("NOT FOUND"); getch(); } int binary(int f,int l) {  md=(f+l)/2; if(f>l) { return(-1); } else if (a[md]<s) return(binary(md+1,l)); else if(a[md]==s) {printf("Found AT LOCATION %d IN WHICH 0 IS THE STARTING ADDRESS",md); return (1); } else return(binary(f,md-1)); } LIST OF PROGRAMS