SlideShare una empresa de Scribd logo
1 de 32
Command                             Purpose                          Output / activity taken
$ cat file1           to see the contents of the file1            It is a fun.
                      Suppose file1 contains the text:            You are encouraged to work
                      It is a fun. You are encouraged to          with the Linux.
                      work with the Linux.
$ more                screen by screen view of file if it is It is a fun.
                      lengthy                                You are encouraged to work
file1                                                        with the Linux.
$ cat file1           file1 sends the output to the standard file1 is copied into file2 also
                      output but the redirection operator
> file2               (>) sends
                      (redirects) output of the standard
                      output to the file2. The redirection
                      operator (>) prevents the output
                      from going to the screen.
                      The part after > is executed first.

                      If file2 does not exist, file2 will be
                      created and the contents of file1 will
                      be copied into file2.
                      if the file already exists, then contents
                      of file2 will be destroyed and made
                      fresh and then contents file1 will be
                      copied
                      Then contents of the left hand side
                      file namely file1
                      is sent to the standard output. The
                      output of the standard output is
                      taken
                      as the input for file2. In short the
                      contents of the file1 is copied into
                      the
                      file2.

$ cat file2           To see the contents of the file2            It is a fun.
                                                                  You are encouraged to work
                                                                  with the Linux.
cat file1 >            empties the file1 (Since RHS & LHS         file1 content will be nothing
                       name are same). So the command
file1                  fails.
           You can set the noclobber feature to prevent overwriting an existing
  file by the redirection operation. In this usage, overwriting of the existing file will fail.
$ cat file1            To overcome the difficulty of           appends the contents file1 to
                       overwriting the existing file append the contents of file2.
>> file2               (>>) operator is used. The append
                       (>>) operator adds the contents of
                       the file, appearing left side of “>>”
                       operator to the file appearing to the
                       right side of the same operator, at
                       the end of the existing material


                                                                                        page 1
Command                         Purpose                     Output / activity taken
$ cat                  The cat command without any            expects data from the
                       argument takes the input from the      standard input.
                       standard input                         After receiving it displays
                                                              immediately in the next line
                       ***                                    ***
                       The entered message is taken to the SRM
                       standard input from                    SRM
                       the buffer, which is directed to the   Chennai
                       cat command. Since there is no         Chennai
                       redirection operator, cat displays the
                       message on the screen
                          After completion inform it to
                          computer by pressing ctrl+D keys in a
                          separate line
  Note: Data can be compared to the water in a dam. Buffer is like a dam where water is
collected before sending for irrigation (the standard output) when there is copious supply of
    water (data). It stores and sends water (data) in more orderly manner when there is a
 request for water or when the dam is full. Ctrl+D character is the end-of–file character for
                                            Linux file.
          Combination of the cat command with output redirection operator (>)
$ cat >              Here LHS name is not mentioned
                     So from standard input i.e keyboard
file3                input is received and redirected to
                     file3
                     On completion in a new line press
                     ctrl+D.




                                                                                    page 2
Command                     Purpose                   Output / activity taken
      Combination of the cat command with input redirection operator (<)
$ cat <         To make the cat command to get       Displays contents of file3 on
                data from the file3 (not from        the screen
file3           keyboard)

                     Standard input to receive data from
                     files also.

                     This is made possible by the
                     redirection input operator.


cat < file3          If the standard input is to be             file3 contents are redirected
                     redirected to receive its data from        to file4
> file4              file3, and the standard output is to
                     be redirected
                     to place its data in file4,
 Piping operator(|) is used to redirect output of one command to another command
   whereas redirection operator used to redirect output of one file into another file.
        The piping symbol is the vertical bar “|” (key before to backspace key).




$ cat file3          to have the contents of file to be
                     printed. The cat command gets
| lpr                contents of a file and sends it to the
                     standard output. The output of cat is
                     piped to lpr (line print i.e the printer
                     connected to the system currently).

                     Here cat is one command and lpr is
                     another command




$ cat | lpr          User has to type in the input              expects data from the
                                                                standard input.
                                                                After receiving it prints in the
                     While completion press ctrl+D.             printer immediately in the next
                     The typed matter is printed in the         line
                     current printer




                                                                                       page 3
Command                           Purpose                      Output / activity taken
$ cat –n                contents of file3 is sent to the printer Content of file3 is printed with
                        (each line will be numbered)             their line number
file3 | lpr

                            The cat command with the option –n
                            sends the contents of the file3 to the
                            standard output after numbering
                            each line.
   If the file is lengthy and if you use the cat command, you can see only the last page. To
                         overcome this difficulty the command more is used
$ cat file3 | more          The contents will be displayed screen page by page contents are
                            by screen, by getting the              displayed
                            confirmation from the user
$ cat –n file3 | more . page page display with line                page by page contents are
                            numbering of each line                 displayed with each line
                                                                   numbers
$ cat –n                    displaying more than one file page
                            by page with line numbered for
file1 file2                 more than one file
file3 |                 Note: Comma should not be used
more.                   between file names; only blank
                        space/
                        spaces should separate them.
           Sort command helps in arranging the contents in alphabatical order.
$ sort               sorts each line of the given file     file3 is sorted & sent to
                     alphabetically and sends the sorted monitor.
file3 |              version to the standard output.
more
$ sort                  You can send the sorted output to       file3 is sorted & displayed
                        more, cat –n, lpr or to any of the      screen by screen
file3 | cat             suitable combinations of these.         file3 is sorted & sent to printer
-n | more
$ sort
file3 | cat
-n | lpr




                                                                                         page 4
Command                           Purpose                    Output / activity taken
The tee command copies the standard output to a file. It takes as its argument the name of
the new file to which the standard output is copied. It seems when the standard output sees
 the tee command; it will split into two copies. Normally, one of them is redirected to the file
     appearing after the tee command and the other goes to the screen. The following
  example not only copies file5 to file6 but also displays the contents of file5 on the screen.
$sort file5             The sorted contents of the file can be sorted o/p of file5 is copied
                        copied into another file and also can into file6 & displayed on
| tee file6             be displayed on the screen.            monitor.
                        *** file5 contents will not be affeted
                        ***
$ sort
file5 | tee                                "

sfile5
$ sort                  sfile5 created (sorted content) and     The output is :
                        displayed on screen,                    Ashok
file5 | tee             and printed                             Chandran
                                                                Malar
sfile5 |
lpr
$ sort                  sfile5 created (sorted content) and     The output is :
                        displayed with number on screen,        1 Ashok
file5 | cat             and printed                             2 Chandran
                                                                3 Malar
-n | tee
sfile5 |
lpr
Copying file - to copy the contents of one file into another in a straightforward manner - use
                           cp command ( one of the command)


Syntax : $
cp
[options]
<source
file/s>
<destinatio
n
directory/f
ile>



                                                                                       page 5
Command                             Purpose                          Output / activity taken
$ cp file1                The cp command copies the                   file1 contents are copied into
                          contents of source file after creating      file6
file6                     destination file. If the destination file
                          already exists then the existing file is    **** be careful in giving
                          destroyed then a new file with              destination file name ****
                          same name is created

$ cp -i                   -i option gives warning about               $ cp -i file1 file2
                          overwriting of destination file (if exists) overwrite file2 ? n $
file1 file2

   If files are not in the current directory, then the full path should be given. If you want to
                establish a link between file1 and file2, you should replace –i by –l.
$ cp -r                     copies a directory to another              copies all the files and sub-
                            directory                                  directories of the alpha
alpha                                                                  directory to the alpha1
                            If directory alpha1 exists already, all directory recursively.
alpha1                      the contents are put inside the
                            directory. If alpha1 des not exist it will
                            be created and all the files and the
                            sub-directories are stored. This alpha1
                            is created under the current working
                            directory.
            There are two more options -s and -v. The option -s creates a symbolic
              link and the option -v (stands for verbose) explains in detail, what is
                                          being done.
                       Removing Files
To delete files or directories the rm command is used. This is superior to rmdir.
rm can be employed even when the directory is not empty, whereas the rmdir can be
employed only when the directory is empty
$ rm file1                removing files and folders             file1 and file2 are deleted

file2
$ rm -r                   to delete even the subdirectories           removes alpha1 directory
                                                                      along with its subdirectories.
alpha1
$ rm -i                   gets confirmed and deletes.                 removes only after
                                                                      confirmingalpha1 directory.
alpha1
$ rm -v alpha1




                                                                                              page 6
Command                            Purpose                     Output / activity taken
  Wildcard entries & filename arguments - giving clue by providing partial information
                          * stands for any number of characters
              ? fixes the number of characters. i.e ? Is = single character
             [ ] gives you a set of characters to search the file with them



$ ls                                                         main.c fact.c swap.c char1
                                                             char2.ex doc1 doc2

$ ls ch*                                                     char1 char2.ex


$ ls *.c                                                     main.c fact.c swap.c



$ ls char?            While the first four characters are   Char1
                      fixed, the last one may be any
                      character including numbers
                      Note: char2.ex will not be displayed,
                      since the length of char2.ex is
                      greater than 5 characters.

$ ls                                                         doc1 doc2

doc[12]

doc[1-5]              search for doc1, doc2, doc3, doc4,
                      doc5. doca, docb, docc, docd,
doc[a-g]              doce, docf, docg




                                                                                    page 7
Command                           Purpose                     Output / activity taken
                                Moving and Renaming the Files.
The mv (move) command is used
Role of mv command
     1. to move a file or directory from one location to another.
     2. to change the name of a file or a directory.


     Moving a file from one location to another is different from copying a file in that no file
     is created while moving a file.
Syntax: mv [options ] <source> <destination>

mv temp                 renaming                                the temp directory is renamed
                                                                into a temporary directory.
temporary
$ mv                    moving                                  file1 of current directory is
                                                                moved to the location
file1                                                           /home/ilamathi/personal/
/home/ilama
thi/persona
                   –i, -v and –f options along with this type of commands




                                                                                        page 8
Command                        Purpose                  Output / activity taken
                         Viewing the System Date and Time
$ date                                                  Mon Jan 05 11:41:12 EST 2009

       The day, the month, the year, the date, the time in hours, in minutes and
                   in seconds can be referred to, as shown below.
$ date     “+        Displays day of month in digits                       5

%d”
$ date     “+       Displays Month of the year (in digits)                1

%m”
$ date     “+       Displays Year(last two digits)                        9

%y”
$ date     “+       Displays Date as mm/dd/yy                        01/05/2009

%D”
$ date     “+       Displays Time as HH:MM:SS                         11:43:14

%T”
$ date     “+       Displays Hour(00 to 23)                              11

%H”
$ date     “+       Displays Seconds(00 to 59)                           43

%S”
$ date     “+       Displays Minutes(00to 59)                            14

%M”
$ date     “+       Displays Abbreviated weekday(sun                    MON
                    to sat)
%a”
$ date     “+       Displays Abbreviated month(jan to                   JAN
                    dec)
%h”
$ date     “+       Displays Time in the AM/PM notation             11:43:14 AM

%r”
  Note: With the help of the above options, the SA can change any part of the date
                                     command.




                                                                                   page 9
Command                               Purpose                    Output / activity taken
                                  File Systems: mount and umount
The files themselves are organized into one perfect tree of directories beginning from the
root.
Although the root may be located in a file system on your hard drive partition, there will be
a path name to files located on the file system for your CD-ROM and floppy.
The floppy or even CD-ROM completely dependent upon the root directory.
If you want to access the contents of the files, in the file system, you should start from the
root directory.
For that you have to connect the sub-tree to the main
tree.
Until it is attached, you will not be able to access the files on your floppy disk.
 This applies to all the storage mediums unless they are connected already.
Even the file system on your hard disk partition has to be mounted with a mount command.
But the system takes care of this activity.

Establishing the connection between a file system on a storage device and your main
directory tree is called mounting the device. This is done with the mount command.
Only the root user SA can access this command (Drawback)
The syntax for the mount command is :
# mount device destination

Device means the device files which are locted in /dev directories
  /dev/fd0            refers to first floppy drive

  /dev/fd1               refers to second floppy drive

  /dev/hda2              refers to hard disk second drive

# mount                 mounting first floppy drive in the
                        mentioned destination
/dev/fd0
/destinatio
n




                                                                                     page 10
Command                          Purpose                  Output / activity taken
Disconnecting a file system on a storage device from your main directory tree is called
Unmounting the device. This is done with the umount command.
Only the root user SA can access this command (Drawback)
   The mounted file systems should be unmounted whenever
   1) before you shut down your system
   2) before you want to replace a mounted file system with another
   Syntax: # umount device (or destination )
# umount                 unmounts the floppy drive

/dev/fd0




                                                                                 page 11
page 12
page 13
page 14
page 15
page 16
page 17
page 18
page 19
page 20
page 21
page 22
Keys used for editing text in the command
                    line
                             alternative key
     Activity       Key
                              combination
moving one character to the
                                   ç            ctrl + B
left
moving one character to the
                                   è            crtl + F
right
                                   Back space
Erasing characters                 and Delete   ctrl + H - backspace
                                   key


Deleting entire line                            ctrl + U




We can enter more than one command in the same line but we
should separate them with a semicolon ( ; ).

We can also enter only one command in several lines by typing a
backslash in each line.

Example

$cat file1; sort file1; cp -i file1 file2


$cp 
-i 
file1 
file2
Linux commands for IX std

   Command                                             Purpose
pwd                     Present Working Directory - to be seen
cd                      to change Directory
cd ..                   to move to parent directory
cd /usr/local/lib       to move to some other directory named to be /usr/local/lib
ls                      to list files of current directory
ls /usr/local           to list files of mentioned directory /usr/local
ls a*                   listing files whose names are starting with letter a
                        listing files whose names are starting with letter a and following
ls a??
                        which only 2 charactyers which may be anything
                        listing files named subject and ending with any numbers from
ls subject[0-9]
                        0-9
ls -d                   listing only directory names
ls -l                   long format listing
ls -m                   listing names separated by commas
ls -a                   listing all files including hidden files
ls -c                   listing files column wise
ls -F                   identity directions, links and executables
ls -R                   list Directory contents recursively
ls -S                   listing by sorting files by size
ls -color               use color to identify files
                        gets i/p by keyboard
cat
                        displays on monitor
                        gets i/p by keyboard
cat >nineth
                        and stores on file named nineth
cat nineth              displays the contents of file named nineth
cat file1.txt file2.txt file1.txt and file2.txt combined and stored into file3.txt
                         > file3.txt
cat fil1>>file3         file3 contents are appended with the fil1 contents
mkdir srm               creates the directory namely srm
                        copies srm into another name rms
cp srm rms              if rms already exists then overwrites the old content with new
                        entry
                     copies srm into another name rms
cp -i srm rms
                     if rms already exists then gets confirmation before overwriting
cp -r dir1 dir2     Copies whole directory dir1 into another name dir2
mv abc marks        renames abc into marks
mv -I abc marks     gets confirmed and then replaces
mv marks /tmp       moves the file marks to the directory tmp
cp -b student       makes the student file to be the back up in the name marks
    marks           back up files ended with ~ symbol
rm student          deletes the file student
rm -I students      gets confirmed and then deletees
rm -r tmp           deletes the directory
locate file*        shows the directory names of files named file*
whereis man         displays manual page for man command
chown               to change ownership
chmod               to chane the permissionto individual files
                    Only owner has rwx permission others
chmod 644 file1.txt
                    read only
chown arasu tiger.html to change the ownership toarasu for tiger file
                    Helps
Linux commands for IX std
Command                          Purpose                        Command                        Purpose


                                                                                    listing files named subject and ending
pwd                 Present Working Directory - to be seen        ls subject[0-9]
                                                                                    with any numbers from 0-9


cd                  to change Directory                           ls -d             listing only directory names



cd ..               to move to parent directory                   ls -l             long format listing


                    to move to some other directory named to
cd /usr/local/lib                                                 ls -m             listing names separated by commas
                    be /usr/local/lib


ls                  to list files of current directory            ls -a             listing all files including hidden files


                    to list files of mentioned directory
ls /usr/local                                                     ls -c             listing files column wise
                    /usr/local


                    listing files whose names are starting with                     identity directions, links and
ls a*                                                             ls -F
                    letter a                                                        executables

                    listing files whose names are starting with
ls a??              letter a and following which only 2           ls -R             list Directory contents recursively
                    charactyers which may be anything
Command                             Purpose                          Command                        Purpose


                                                                                       copies srm into another name rms
ls -S                listing by sorting files by size                cp srm rms        if rms already exists then overwrites
                                                                                       the old content with new entry

                                                                                       copies srm into another name rms
ls -color            use color to identify files                     cp -i srm rms     if rms already exists then gets
                                                                                       confirmation before overwriting

                     gets i/p by keyboard                                              Copies whole directory dir1 into
cat                                                                  cp -r dir1 dir2
                     displays on monitor                                               another name dir2


                     gets i/p by keyboard
cat >nineth                                                          mv abc marks      renames abc into marks
                     and stores on file named nineth


cat nineth           displays the contents of file named nineth      mv -I abc marks   gets confirmed and then replaces


                       file1.txt and file2.txt combined and stored                     moves the file marks to the directory
cat file1.txt file2.txt > file3.txt                                  mv marks /tmp
                       into file3.txt                                                  tmp

                                                                                       makes the student file to be the back
                     file3 contents are appended with the fil1       cp -b student
cat fil1>>file3                                                                        up in the name marks back up files
                     contents                                            marks
                                                                                       ended with ~ symbol


mkdir srm            creates the directory namely srm                rm student        deletes the file student
Command                             Purpose                      Command   Purpose



rm -I students        gets confirmed and then deletees



rm -r tmp             deletes the directory


                      shows the directory names of files named
locate file*
                      file*


whereis man           displays manual page for man command



chown                 to change ownership



chmod                 to chane the permissionto individual files


                      Only owner has rwx permission others
chmod 644 file1.txt
                      read only


                   Helps to change the ownership toarasu
chown arasu tiger.html
                   for tiger file
File Commands Of Linux  Ii
File Commands Of Linux  Ii
File Commands Of Linux  Ii

Más contenido relacionado

La actualidad más candente

Unix commands in etl testing
Unix commands in etl testingUnix commands in etl testing
Unix commands in etl testingGaruda Trainings
 
SGN Introduction to UNIX Command-line 2015 part 1
SGN Introduction to UNIX Command-line 2015 part 1SGN Introduction to UNIX Command-line 2015 part 1
SGN Introduction to UNIX Command-line 2015 part 1solgenomics
 
intro unix/linux 08
intro unix/linux 08intro unix/linux 08
intro unix/linux 08duquoi
 
Linux commands part -2
Linux commands part -2Linux commands part -2
Linux commands part -2bhatvijetha
 
Tool Development 08 - Windows Command Prompt
Tool Development 08 - Windows Command PromptTool Development 08 - Windows Command Prompt
Tool Development 08 - Windows Command PromptNick Pruehs
 
Course 102: Lecture 17: Process Monitoring
Course 102: Lecture 17: Process Monitoring Course 102: Lecture 17: Process Monitoring
Course 102: Lecture 17: Process Monitoring Ahmed El-Arabawy
 
Introduction to UNIX Command-Lines with examples
Introduction to UNIX Command-Lines with examplesIntroduction to UNIX Command-Lines with examples
Introduction to UNIX Command-Lines with examplesNoé Fernández-Pozo
 
Windows command prompt a to z
Windows command prompt a to zWindows command prompt a to z
Windows command prompt a to zSubuh Kurniawan
 
Basic unix commands
Basic unix commandsBasic unix commands
Basic unix commandsswtjerin4u
 
intro unix/linux 02
intro unix/linux 02intro unix/linux 02
intro unix/linux 02duquoi
 

La actualidad más candente (20)

Basic linux commands
Basic linux commandsBasic linux commands
Basic linux commands
 
Unix commands in etl testing
Unix commands in etl testingUnix commands in etl testing
Unix commands in etl testing
 
Linux basic commands
Linux basic commandsLinux basic commands
Linux basic commands
 
Report
ReportReport
Report
 
SGN Introduction to UNIX Command-line 2015 part 1
SGN Introduction to UNIX Command-line 2015 part 1SGN Introduction to UNIX Command-line 2015 part 1
SGN Introduction to UNIX Command-line 2015 part 1
 
intro unix/linux 08
intro unix/linux 08intro unix/linux 08
intro unix/linux 08
 
Know the UNIX Commands
Know the UNIX CommandsKnow the UNIX Commands
Know the UNIX Commands
 
Linux commands
Linux commandsLinux commands
Linux commands
 
Linux commands
Linux commandsLinux commands
Linux commands
 
The Galaxy toolshed
The Galaxy toolshedThe Galaxy toolshed
The Galaxy toolshed
 
Linux
LinuxLinux
Linux
 
Linux commands part -2
Linux commands part -2Linux commands part -2
Linux commands part -2
 
Tool Development 08 - Windows Command Prompt
Tool Development 08 - Windows Command PromptTool Development 08 - Windows Command Prompt
Tool Development 08 - Windows Command Prompt
 
Linux
LinuxLinux
Linux
 
Course 102: Lecture 17: Process Monitoring
Course 102: Lecture 17: Process Monitoring Course 102: Lecture 17: Process Monitoring
Course 102: Lecture 17: Process Monitoring
 
Introduction to UNIX Command-Lines with examples
Introduction to UNIX Command-Lines with examplesIntroduction to UNIX Command-Lines with examples
Introduction to UNIX Command-Lines with examples
 
Windows command prompt a to z
Windows command prompt a to zWindows command prompt a to z
Windows command prompt a to z
 
Basic unix commands
Basic unix commandsBasic unix commands
Basic unix commands
 
Dns
DnsDns
Dns
 
intro unix/linux 02
intro unix/linux 02intro unix/linux 02
intro unix/linux 02
 

Similar a File Commands Of Linux Ii

File Commands - R.D.Sivakumar
File Commands - R.D.SivakumarFile Commands - R.D.Sivakumar
File Commands - R.D.SivakumarSivakumar R D .
 
Basics of files and its functions with example
Basics of files and its functions with exampleBasics of files and its functions with example
Basics of files and its functions with exampleSunil Patel
 
basics of file handling
basics of file handlingbasics of file handling
basics of file handlingpinkpreet_kaur
 
Basics of file handling
Basics of file handlingBasics of file handling
Basics of file handlingpinkpreet_kaur
 
Linux Cheat Sheet.pdf
Linux Cheat Sheet.pdfLinux Cheat Sheet.pdf
Linux Cheat Sheet.pdfroschahacker
 
Implementation of Pipe in Linux
Implementation of Pipe in LinuxImplementation of Pipe in Linux
Implementation of Pipe in LinuxTushar B Kute
 
Linux command for beginners
Linux command for beginnersLinux command for beginners
Linux command for beginnersSuKyeong Jang
 
File Handling in c++
File Handling in c++File Handling in c++
File Handling in c++SoniKirtan
 
File handling in_c
File handling in_cFile handling in_c
File handling in_csanya6900
 
Unix And Shell Scripting
Unix And Shell ScriptingUnix And Shell Scripting
Unix And Shell ScriptingJaibeer Malik
 
Course 102: Lecture 12: Basic Text Handling
Course 102: Lecture 12: Basic Text Handling Course 102: Lecture 12: Basic Text Handling
Course 102: Lecture 12: Basic Text Handling Ahmed El-Arabawy
 
Basic Commands-part1.pptx
Basic Commands-part1.pptxBasic Commands-part1.pptx
Basic Commands-part1.pptxGOGOMASTER2
 
Presentation aix basic
Presentation   aix basicPresentation   aix basic
Presentation aix basicxKinAnx
 
File management in C++
File management in C++File management in C++
File management in C++apoorvaverma33
 

Similar a File Commands Of Linux Ii (20)

Unix_QT.ppsx
Unix_QT.ppsxUnix_QT.ppsx
Unix_QT.ppsx
 
Unix_QT.ppsx
Unix_QT.ppsxUnix_QT.ppsx
Unix_QT.ppsx
 
File Commands - R.D.Sivakumar
File Commands - R.D.SivakumarFile Commands - R.D.Sivakumar
File Commands - R.D.Sivakumar
 
40 basic linux command
40 basic linux command40 basic linux command
40 basic linux command
 
40 basic linux command
40 basic linux command40 basic linux command
40 basic linux command
 
Basics of files and its functions with example
Basics of files and its functions with exampleBasics of files and its functions with example
Basics of files and its functions with example
 
basics of file handling
basics of file handlingbasics of file handling
basics of file handling
 
Basics of file handling
Basics of file handlingBasics of file handling
Basics of file handling
 
Linux Cheat Sheet.pdf
Linux Cheat Sheet.pdfLinux Cheat Sheet.pdf
Linux Cheat Sheet.pdf
 
Implementation of Pipe in Linux
Implementation of Pipe in LinuxImplementation of Pipe in Linux
Implementation of Pipe in Linux
 
Linux command for beginners
Linux command for beginnersLinux command for beginners
Linux command for beginners
 
File Handling in c++
File Handling in c++File Handling in c++
File Handling in c++
 
File handling in_c
File handling in_cFile handling in_c
File handling in_c
 
Unix And Shell Scripting
Unix And Shell ScriptingUnix And Shell Scripting
Unix And Shell Scripting
 
Course 102: Lecture 12: Basic Text Handling
Course 102: Lecture 12: Basic Text Handling Course 102: Lecture 12: Basic Text Handling
Course 102: Lecture 12: Basic Text Handling
 
Filehandlinging cp2
Filehandlinging cp2Filehandlinging cp2
Filehandlinging cp2
 
Basic Commands-part1.pptx
Basic Commands-part1.pptxBasic Commands-part1.pptx
Basic Commands-part1.pptx
 
Presentation aix basic
Presentation   aix basicPresentation   aix basic
Presentation aix basic
 
File management in C++
File management in C++File management in C++
File management in C++
 
Assignment OS LAB 2022
Assignment OS LAB 2022Assignment OS LAB 2022
Assignment OS LAB 2022
 

Último

Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 

Último (20)

Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 

File Commands Of Linux Ii

  • 1. Command Purpose Output / activity taken $ cat file1 to see the contents of the file1 It is a fun. Suppose file1 contains the text: You are encouraged to work It is a fun. You are encouraged to with the Linux. work with the Linux. $ more screen by screen view of file if it is It is a fun. lengthy You are encouraged to work file1 with the Linux. $ cat file1 file1 sends the output to the standard file1 is copied into file2 also output but the redirection operator > file2 (>) sends (redirects) output of the standard output to the file2. The redirection operator (>) prevents the output from going to the screen. The part after > is executed first. If file2 does not exist, file2 will be created and the contents of file1 will be copied into file2. if the file already exists, then contents of file2 will be destroyed and made fresh and then contents file1 will be copied Then contents of the left hand side file namely file1 is sent to the standard output. The output of the standard output is taken as the input for file2. In short the contents of the file1 is copied into the file2. $ cat file2 To see the contents of the file2 It is a fun. You are encouraged to work with the Linux. cat file1 > empties the file1 (Since RHS & LHS file1 content will be nothing name are same). So the command file1 fails. You can set the noclobber feature to prevent overwriting an existing file by the redirection operation. In this usage, overwriting of the existing file will fail. $ cat file1 To overcome the difficulty of appends the contents file1 to overwriting the existing file append the contents of file2. >> file2 (>>) operator is used. The append (>>) operator adds the contents of the file, appearing left side of “>>” operator to the file appearing to the right side of the same operator, at the end of the existing material page 1
  • 2. Command Purpose Output / activity taken $ cat The cat command without any expects data from the argument takes the input from the standard input. standard input After receiving it displays immediately in the next line *** *** The entered message is taken to the SRM standard input from SRM the buffer, which is directed to the Chennai cat command. Since there is no Chennai redirection operator, cat displays the message on the screen After completion inform it to computer by pressing ctrl+D keys in a separate line Note: Data can be compared to the water in a dam. Buffer is like a dam where water is collected before sending for irrigation (the standard output) when there is copious supply of water (data). It stores and sends water (data) in more orderly manner when there is a request for water or when the dam is full. Ctrl+D character is the end-of–file character for Linux file. Combination of the cat command with output redirection operator (>) $ cat > Here LHS name is not mentioned So from standard input i.e keyboard file3 input is received and redirected to file3 On completion in a new line press ctrl+D. page 2
  • 3. Command Purpose Output / activity taken Combination of the cat command with input redirection operator (<) $ cat < To make the cat command to get Displays contents of file3 on data from the file3 (not from the screen file3 keyboard) Standard input to receive data from files also. This is made possible by the redirection input operator. cat < file3 If the standard input is to be file3 contents are redirected redirected to receive its data from to file4 > file4 file3, and the standard output is to be redirected to place its data in file4, Piping operator(|) is used to redirect output of one command to another command whereas redirection operator used to redirect output of one file into another file. The piping symbol is the vertical bar “|” (key before to backspace key). $ cat file3 to have the contents of file to be printed. The cat command gets | lpr contents of a file and sends it to the standard output. The output of cat is piped to lpr (line print i.e the printer connected to the system currently). Here cat is one command and lpr is another command $ cat | lpr User has to type in the input expects data from the standard input. After receiving it prints in the While completion press ctrl+D. printer immediately in the next The typed matter is printed in the line current printer page 3
  • 4. Command Purpose Output / activity taken $ cat –n contents of file3 is sent to the printer Content of file3 is printed with (each line will be numbered) their line number file3 | lpr The cat command with the option –n sends the contents of the file3 to the standard output after numbering each line. If the file is lengthy and if you use the cat command, you can see only the last page. To overcome this difficulty the command more is used $ cat file3 | more The contents will be displayed screen page by page contents are by screen, by getting the displayed confirmation from the user $ cat –n file3 | more . page page display with line page by page contents are numbering of each line displayed with each line numbers $ cat –n displaying more than one file page by page with line numbered for file1 file2 more than one file file3 | Note: Comma should not be used more. between file names; only blank space/ spaces should separate them. Sort command helps in arranging the contents in alphabatical order. $ sort sorts each line of the given file file3 is sorted & sent to alphabetically and sends the sorted monitor. file3 | version to the standard output. more $ sort You can send the sorted output to file3 is sorted & displayed more, cat –n, lpr or to any of the screen by screen file3 | cat suitable combinations of these. file3 is sorted & sent to printer -n | more $ sort file3 | cat -n | lpr page 4
  • 5. Command Purpose Output / activity taken The tee command copies the standard output to a file. It takes as its argument the name of the new file to which the standard output is copied. It seems when the standard output sees the tee command; it will split into two copies. Normally, one of them is redirected to the file appearing after the tee command and the other goes to the screen. The following example not only copies file5 to file6 but also displays the contents of file5 on the screen. $sort file5 The sorted contents of the file can be sorted o/p of file5 is copied copied into another file and also can into file6 & displayed on | tee file6 be displayed on the screen. monitor. *** file5 contents will not be affeted *** $ sort file5 | tee " sfile5 $ sort sfile5 created (sorted content) and The output is : displayed on screen, Ashok file5 | tee and printed Chandran Malar sfile5 | lpr $ sort sfile5 created (sorted content) and The output is : displayed with number on screen, 1 Ashok file5 | cat and printed 2 Chandran 3 Malar -n | tee sfile5 | lpr Copying file - to copy the contents of one file into another in a straightforward manner - use cp command ( one of the command) Syntax : $ cp [options] <source file/s> <destinatio n directory/f ile> page 5
  • 6. Command Purpose Output / activity taken $ cp file1 The cp command copies the file1 contents are copied into contents of source file after creating file6 file6 destination file. If the destination file already exists then the existing file is **** be careful in giving destroyed then a new file with destination file name **** same name is created $ cp -i -i option gives warning about $ cp -i file1 file2 overwriting of destination file (if exists) overwrite file2 ? n $ file1 file2 If files are not in the current directory, then the full path should be given. If you want to establish a link between file1 and file2, you should replace –i by –l. $ cp -r copies a directory to another copies all the files and sub- directory directories of the alpha alpha directory to the alpha1 If directory alpha1 exists already, all directory recursively. alpha1 the contents are put inside the directory. If alpha1 des not exist it will be created and all the files and the sub-directories are stored. This alpha1 is created under the current working directory. There are two more options -s and -v. The option -s creates a symbolic link and the option -v (stands for verbose) explains in detail, what is being done. Removing Files To delete files or directories the rm command is used. This is superior to rmdir. rm can be employed even when the directory is not empty, whereas the rmdir can be employed only when the directory is empty $ rm file1 removing files and folders file1 and file2 are deleted file2 $ rm -r to delete even the subdirectories removes alpha1 directory along with its subdirectories. alpha1 $ rm -i gets confirmed and deletes. removes only after confirmingalpha1 directory. alpha1 $ rm -v alpha1 page 6
  • 7. Command Purpose Output / activity taken Wildcard entries & filename arguments - giving clue by providing partial information * stands for any number of characters ? fixes the number of characters. i.e ? Is = single character [ ] gives you a set of characters to search the file with them $ ls main.c fact.c swap.c char1 char2.ex doc1 doc2 $ ls ch* char1 char2.ex $ ls *.c main.c fact.c swap.c $ ls char? While the first four characters are Char1 fixed, the last one may be any character including numbers Note: char2.ex will not be displayed, since the length of char2.ex is greater than 5 characters. $ ls doc1 doc2 doc[12] doc[1-5] search for doc1, doc2, doc3, doc4, doc5. doca, docb, docc, docd, doc[a-g] doce, docf, docg page 7
  • 8. Command Purpose Output / activity taken Moving and Renaming the Files. The mv (move) command is used Role of mv command 1. to move a file or directory from one location to another. 2. to change the name of a file or a directory. Moving a file from one location to another is different from copying a file in that no file is created while moving a file. Syntax: mv [options ] <source> <destination> mv temp renaming the temp directory is renamed into a temporary directory. temporary $ mv moving file1 of current directory is moved to the location file1 /home/ilamathi/personal/ /home/ilama thi/persona –i, -v and –f options along with this type of commands page 8
  • 9. Command Purpose Output / activity taken Viewing the System Date and Time $ date Mon Jan 05 11:41:12 EST 2009 The day, the month, the year, the date, the time in hours, in minutes and in seconds can be referred to, as shown below. $ date “+ Displays day of month in digits 5 %d” $ date “+ Displays Month of the year (in digits) 1 %m” $ date “+ Displays Year(last two digits) 9 %y” $ date “+ Displays Date as mm/dd/yy 01/05/2009 %D” $ date “+ Displays Time as HH:MM:SS 11:43:14 %T” $ date “+ Displays Hour(00 to 23) 11 %H” $ date “+ Displays Seconds(00 to 59) 43 %S” $ date “+ Displays Minutes(00to 59) 14 %M” $ date “+ Displays Abbreviated weekday(sun MON to sat) %a” $ date “+ Displays Abbreviated month(jan to JAN dec) %h” $ date “+ Displays Time in the AM/PM notation 11:43:14 AM %r” Note: With the help of the above options, the SA can change any part of the date command. page 9
  • 10. Command Purpose Output / activity taken File Systems: mount and umount The files themselves are organized into one perfect tree of directories beginning from the root. Although the root may be located in a file system on your hard drive partition, there will be a path name to files located on the file system for your CD-ROM and floppy. The floppy or even CD-ROM completely dependent upon the root directory. If you want to access the contents of the files, in the file system, you should start from the root directory. For that you have to connect the sub-tree to the main tree. Until it is attached, you will not be able to access the files on your floppy disk. This applies to all the storage mediums unless they are connected already. Even the file system on your hard disk partition has to be mounted with a mount command. But the system takes care of this activity. Establishing the connection between a file system on a storage device and your main directory tree is called mounting the device. This is done with the mount command. Only the root user SA can access this command (Drawback) The syntax for the mount command is : # mount device destination Device means the device files which are locted in /dev directories /dev/fd0 refers to first floppy drive /dev/fd1 refers to second floppy drive /dev/hda2 refers to hard disk second drive # mount mounting first floppy drive in the mentioned destination /dev/fd0 /destinatio n page 10
  • 11. Command Purpose Output / activity taken Disconnecting a file system on a storage device from your main directory tree is called Unmounting the device. This is done with the umount command. Only the root user SA can access this command (Drawback) The mounted file systems should be unmounted whenever 1) before you shut down your system 2) before you want to replace a mounted file system with another Syntax: # umount device (or destination ) # umount unmounts the floppy drive /dev/fd0 page 11
  • 23. Keys used for editing text in the command line alternative key Activity Key combination moving one character to the ç ctrl + B left moving one character to the è crtl + F right Back space Erasing characters and Delete ctrl + H - backspace key Deleting entire line ctrl + U We can enter more than one command in the same line but we should separate them with a semicolon ( ; ). We can also enter only one command in several lines by typing a backslash in each line. Example $cat file1; sort file1; cp -i file1 file2 $cp -i file1 file2
  • 24.
  • 25. Linux commands for IX std Command Purpose pwd Present Working Directory - to be seen cd to change Directory cd .. to move to parent directory cd /usr/local/lib to move to some other directory named to be /usr/local/lib ls to list files of current directory ls /usr/local to list files of mentioned directory /usr/local ls a* listing files whose names are starting with letter a listing files whose names are starting with letter a and following ls a?? which only 2 charactyers which may be anything listing files named subject and ending with any numbers from ls subject[0-9] 0-9 ls -d listing only directory names ls -l long format listing ls -m listing names separated by commas ls -a listing all files including hidden files ls -c listing files column wise ls -F identity directions, links and executables ls -R list Directory contents recursively ls -S listing by sorting files by size ls -color use color to identify files gets i/p by keyboard cat displays on monitor gets i/p by keyboard cat >nineth and stores on file named nineth cat nineth displays the contents of file named nineth cat file1.txt file2.txt file1.txt and file2.txt combined and stored into file3.txt > file3.txt cat fil1>>file3 file3 contents are appended with the fil1 contents mkdir srm creates the directory namely srm copies srm into another name rms cp srm rms if rms already exists then overwrites the old content with new entry copies srm into another name rms cp -i srm rms if rms already exists then gets confirmation before overwriting cp -r dir1 dir2 Copies whole directory dir1 into another name dir2 mv abc marks renames abc into marks mv -I abc marks gets confirmed and then replaces mv marks /tmp moves the file marks to the directory tmp cp -b student makes the student file to be the back up in the name marks marks back up files ended with ~ symbol rm student deletes the file student rm -I students gets confirmed and then deletees rm -r tmp deletes the directory locate file* shows the directory names of files named file* whereis man displays manual page for man command chown to change ownership chmod to chane the permissionto individual files Only owner has rwx permission others chmod 644 file1.txt read only chown arasu tiger.html to change the ownership toarasu for tiger file Helps
  • 27. Command Purpose Command Purpose listing files named subject and ending pwd Present Working Directory - to be seen ls subject[0-9] with any numbers from 0-9 cd to change Directory ls -d listing only directory names cd .. to move to parent directory ls -l long format listing to move to some other directory named to cd /usr/local/lib ls -m listing names separated by commas be /usr/local/lib ls to list files of current directory ls -a listing all files including hidden files to list files of mentioned directory ls /usr/local ls -c listing files column wise /usr/local listing files whose names are starting with identity directions, links and ls a* ls -F letter a executables listing files whose names are starting with ls a?? letter a and following which only 2 ls -R list Directory contents recursively charactyers which may be anything
  • 28. Command Purpose Command Purpose copies srm into another name rms ls -S listing by sorting files by size cp srm rms if rms already exists then overwrites the old content with new entry copies srm into another name rms ls -color use color to identify files cp -i srm rms if rms already exists then gets confirmation before overwriting gets i/p by keyboard Copies whole directory dir1 into cat cp -r dir1 dir2 displays on monitor another name dir2 gets i/p by keyboard cat >nineth mv abc marks renames abc into marks and stores on file named nineth cat nineth displays the contents of file named nineth mv -I abc marks gets confirmed and then replaces file1.txt and file2.txt combined and stored moves the file marks to the directory cat file1.txt file2.txt > file3.txt mv marks /tmp into file3.txt tmp makes the student file to be the back file3 contents are appended with the fil1 cp -b student cat fil1>>file3 up in the name marks back up files contents marks ended with ~ symbol mkdir srm creates the directory namely srm rm student deletes the file student
  • 29. Command Purpose Command Purpose rm -I students gets confirmed and then deletees rm -r tmp deletes the directory shows the directory names of files named locate file* file* whereis man displays manual page for man command chown to change ownership chmod to chane the permissionto individual files Only owner has rwx permission others chmod 644 file1.txt read only Helps to change the ownership toarasu chown arasu tiger.html for tiger file