R.D.SIVAKUMAR, M.Sc.,M.Phil.,M.Tech.,
Assistant Professor of Computer Science &
Assistant Professor and Head, Department of M.Com.(CA),
Ayya Nadar Janaki Ammal College,
Sivakasi – 626 124.
Mobile: 099440-42243
e-mail : sivamsccsit@gmail.com
website: www.rdsivakumar.blogspot.in
File Commands
File Commands
File tests each argument in an attempt to classify it. There are three sets of
tests, performed in this order: file system tests, magic number tests, and
language tests. The first test that succeeds causes the file type to be printed.
Displaying the Contents of the file
The cat command lets the cat (contents of the file) out of the bag (file) but the
more command does more. The cat command shows the contents of the specified
file normally on the screen. If the file is lengthy, it will run so quickly, what you
see, in the end, is the last page.
The command more is handy, in such situations. It will show one page at a time;
if you want to move to the next page or the previous page you have to press f
(forward) or b (backward) keys respectively. Strictly speaking the cat and more
are filters. They filter the data that pass through them.
File Commands
There is one tee command, which does double the work of the cat command. The tee
command is just like the T pipe. This pipe is made up of two tubes. The first part is a
horizontal tube and the second part is a vertical tube.
If water is allowed to flow through the T pipe, (placed in a horizontal plane) water flows
horizontally and vertically simultaneously. In a similar manner the tee command takes
the input from the standard input and displays the content on the screen (just like cat
command) and stores the same in the file specified, after the tee command.
In Linux all files are arranged as a continuous stream of bytes. There is only one
standard type of file in Linux,the byte-stream file.The input data stream is called as the
standard input and the output stream is called as standard output.
If you input the data, the data are converted into the data stream of continous set of
bytes. This is called the standard input. Normally the standard input is connected to the
key board. The standard output is also data stream of continous set of bytes. Normally the
standard output is connected to the printer. You can redirect the standard input to the
floppy disk etc.
File Commands
While you deal with files, you will need frequently to copy the contents of one file into
another. Even though you have been introduced to several sophisticated commands by
means of which copying of files is made possible, you can do the same in a
straightforward manner by the command cp (copy).
Syntax
$ cp [options] <source file/s> <destination directory/file> The word/words appearing
within brackets will be taken as optional. You can include or exclude word /words
appearing in the bracket. Here you can either include “options” or exclude them. The
word/words appearing within angle brackets (“< >”) should be given compulsorily and
actual names should be substituted while the actual command is issued. Now you want to
copy the contents of the file1 into file6. The command is
$ cp file1 file6 The file1 is the source file (that is data emanate from file1) and file6 is the
destination file (that is data go to file6). The above command will not affect the contents of
the file1. If file6 already exists its contents will be overwritten by the contents of file1.
The cp command copies the contents of source file after creating destination file. If the
destination file already exists then the existing file is destroyed then a new file with same
name is created.
File Commands
Removing Files
To delete files or directories the rm command is used. This is superior to rmdir.
Example:
$ rm file1 file2
Now file1 and file2 are removed from your current directory. If the file/s is /are not in
the current directory then the complete path name has to be given. You have already seen
the command rmdir, is not of any help if the directory is not empty. But rm can be
employed in such conditions with the –r or –R (for recursion) option to remove the
directory.
Example:
$ rm -r alpha1
The above command removes alpha1 directory along with its subdirectories. You can
use –i -v with the usual meanings. There is one more option –f, you will be in a better
position if you do not make use of it.
File Commands
Wildcard entries and filename arguments
If you have partial information about the names of files, the Linux provides
special characters *, ?, [ ] (comma is not included in the list) which will help you to
find out the exact name(s). if you want to list out the files which start with ch or
end with .c, the special character * will be helpful to you.
The special character * stands for any number of charactersn $ rm * This
command is a very dangerous command, which will wipe out all the files. The
question mark,?, matches only a single incomplete character in filenames.
Edit Text and Commands.
Before pressing the Enter key you can edit the command line with the help of left
arrow (or ctrl + B ) , right arrow ( or crtl + F ). Back space (ctrl + H ) and Delete
key are used to erase the character as usual. Ctrl + U deletes the entire line. You
can enter more than one command in the same line but you should separate them
with a semicolon ( ; ).
You can also enter only one command in several lines by typing a backslash in each
line.
File Commands
Moving and Renaming the Files.
The mv (move) command is used for
1. to move a file or directory from one location to another.
2. to change the name of a file or a directory.
Note: 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>
Viewing the System Date and Time
You can view the system date and time by giving the command date after $ prompt.
Example:
$ date
Wed July 07 11:41:12 EST 2004
There are several options that can be used to format the date and time before
displaying them. The options are specified within double-quotes, and within the quotes,
they must begin with a +symbol
File Commands
Thank you..!!

File Commands - R.D.Sivakumar

  • 1.
    R.D.SIVAKUMAR, M.Sc.,M.Phil.,M.Tech., Assistant Professorof Computer Science & Assistant Professor and Head, Department of M.Com.(CA), Ayya Nadar Janaki Ammal College, Sivakasi – 626 124. Mobile: 099440-42243 e-mail : sivamsccsit@gmail.com website: www.rdsivakumar.blogspot.in File Commands
  • 2.
    File Commands File testseach argument in an attempt to classify it. There are three sets of tests, performed in this order: file system tests, magic number tests, and language tests. The first test that succeeds causes the file type to be printed. Displaying the Contents of the file The cat command lets the cat (contents of the file) out of the bag (file) but the more command does more. The cat command shows the contents of the specified file normally on the screen. If the file is lengthy, it will run so quickly, what you see, in the end, is the last page. The command more is handy, in such situations. It will show one page at a time; if you want to move to the next page or the previous page you have to press f (forward) or b (backward) keys respectively. Strictly speaking the cat and more are filters. They filter the data that pass through them.
  • 3.
    File Commands There isone tee command, which does double the work of the cat command. The tee command is just like the T pipe. This pipe is made up of two tubes. The first part is a horizontal tube and the second part is a vertical tube. If water is allowed to flow through the T pipe, (placed in a horizontal plane) water flows horizontally and vertically simultaneously. In a similar manner the tee command takes the input from the standard input and displays the content on the screen (just like cat command) and stores the same in the file specified, after the tee command. In Linux all files are arranged as a continuous stream of bytes. There is only one standard type of file in Linux,the byte-stream file.The input data stream is called as the standard input and the output stream is called as standard output. If you input the data, the data are converted into the data stream of continous set of bytes. This is called the standard input. Normally the standard input is connected to the key board. The standard output is also data stream of continous set of bytes. Normally the standard output is connected to the printer. You can redirect the standard input to the floppy disk etc.
  • 4.
    File Commands While youdeal with files, you will need frequently to copy the contents of one file into another. Even though you have been introduced to several sophisticated commands by means of which copying of files is made possible, you can do the same in a straightforward manner by the command cp (copy). Syntax $ cp [options] <source file/s> <destination directory/file> The word/words appearing within brackets will be taken as optional. You can include or exclude word /words appearing in the bracket. Here you can either include “options” or exclude them. The word/words appearing within angle brackets (“< >”) should be given compulsorily and actual names should be substituted while the actual command is issued. Now you want to copy the contents of the file1 into file6. The command is $ cp file1 file6 The file1 is the source file (that is data emanate from file1) and file6 is the destination file (that is data go to file6). The above command will not affect the contents of the file1. If file6 already exists its contents will be overwritten by the contents of file1. The cp command copies the contents of source file after creating destination file. If the destination file already exists then the existing file is destroyed then a new file with same name is created.
  • 5.
    File Commands Removing Files Todelete files or directories the rm command is used. This is superior to rmdir. Example: $ rm file1 file2 Now file1 and file2 are removed from your current directory. If the file/s is /are not in the current directory then the complete path name has to be given. You have already seen the command rmdir, is not of any help if the directory is not empty. But rm can be employed in such conditions with the –r or –R (for recursion) option to remove the directory. Example: $ rm -r alpha1 The above command removes alpha1 directory along with its subdirectories. You can use –i -v with the usual meanings. There is one more option –f, you will be in a better position if you do not make use of it.
  • 6.
    File Commands Wildcard entriesand filename arguments If you have partial information about the names of files, the Linux provides special characters *, ?, [ ] (comma is not included in the list) which will help you to find out the exact name(s). if you want to list out the files which start with ch or end with .c, the special character * will be helpful to you. The special character * stands for any number of charactersn $ rm * This command is a very dangerous command, which will wipe out all the files. The question mark,?, matches only a single incomplete character in filenames. Edit Text and Commands. Before pressing the Enter key you can edit the command line with the help of left arrow (or ctrl + B ) , right arrow ( or crtl + F ). Back space (ctrl + H ) and Delete key are used to erase the character as usual. Ctrl + U deletes the entire line. You can enter more than one command in the same line but you should separate them with a semicolon ( ; ). You can also enter only one command in several lines by typing a backslash in each line.
  • 7.
    File Commands Moving andRenaming the Files. The mv (move) command is used for 1. to move a file or directory from one location to another. 2. to change the name of a file or a directory. Note: 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> Viewing the System Date and Time You can view the system date and time by giving the command date after $ prompt. Example: $ date Wed July 07 11:41:12 EST 2004 There are several options that can be used to format the date and time before displaying them. The options are specified within double-quotes, and within the quotes, they must begin with a +symbol
  • 8.
  • 9.