File Handling Commands of Linux
- mkdir
Description:
To create a new empty directory or directories.
Syntax:
$ mkdir <option(s)>dir_name(s)
Example:
$ mkdir Sam
- rmdir
Description:
To remove an existing directory or directories from the directory hierarchy.
Syntax:
$ rmdir <option(s)>dir_name(s)
Example:
$ rmdir Sam
- cat
Description:
This command is used to display the contents of the existing file(s), to create a new file or to add the data to the end of the existing file.
Syntax:
$ cat <option(s)>file_name(s)
Example:
$ cat sam.txt
Output:
This command without any options will display the content of the file named "sam.txt".
Options:
There are three versions of this Command.They are:
1.$ cat filename(s)
Desc: This will display the content of the given file(s).
Ex: $ cat sam.txt
2.$ cat >filename
Desc: This will create a new file with the given filename. This will wait for the input after giving the input from the the standard keyboard, you have to press ctrl+d to terminate the input.
Ex: $ cat >sam.txt
3.$ cat >>filename
Desc: This will add the lines at the end of the existing file.
Ex: $ cat >>sam.txt
i)-n option:
Desc: This will give the line numbers to the content of the file.
Ex: $ cat -n sam.txt
ii)-b option:
Desc: This will give the line numbers to the content of the file but ignore the blank lines.
Ex: $ cat -b sam.txt
- mv
Description:
This command is used to rename the files with the new file name.Here this command first creates an empty file with the name given, then copies the contents of the old file to the new empty file and finally it deletes the old file.
Syntax:
$ mv <option(s)> old_filename new_filename
Example:
$ mv sam.txt isad.c
Output:
This command will change the name of the "sam.txt" to "isad.c".
- rm
Description:
This command is used to remove the existing file(s) from directory hierarchy.
Syntax:
$ rm <option(s)> file_name(s)
Example:
$ rm sam.txt
Output:
This command will delete the file "sam.txt" from the hierarchy.
Options:
1. -f (Forcibly Removal):
Desc: This option is used to remove the file even though it is write protected.
Ex: rm -f sam.txt
2. -r (Recursive Removal):
Desc: This option will remove all the files and empty directories even though if the directory is having the files, it will removes the files first then remove the emptied directory.
Ex: rm -r sam.txt
3. -i (Interactive Removal):
Desc: The rm command with -i flag will ask the user before removing the file or directory.
Ex: rm -i sam.txt
Description:
To create a new empty directory or directories.
Syntax:
$ mkdir <option(s)>dir_name(s)
Example:
$ mkdir Sam
To remove an existing directory or directories from the directory hierarchy.
$ rmdir <option(s)>dir_name(s)
Example:
$ rmdir Sam
- cat
Description:
This command is used to display the contents of the existing file(s), to create a new file or to add the data to the end of the existing file.
Syntax:
$ cat <option(s)>file_name(s)
Example:
$ cat sam.txt
Output:
This command without any options will display the content of the file named "sam.txt".
Options:
There are three versions of this Command.They are:
1.$ cat filename(s)
Desc: This will display the content of the given file(s).
Ex: $ cat sam.txt
2.$ cat >filename
Desc: This will create a new file with the given filename. This will wait for the input after giving the input from the the standard keyboard, you have to press ctrl+d to terminate the input.
Ex: $ cat >sam.txt
3.$ cat >>filename
Desc: This will add the lines at the end of the existing file.
Ex: $ cat >>sam.txt
i)-n option:
Desc: This will give the line numbers to the content of the file.
Ex: $ cat -n sam.txt
ii)-b option:
Desc: This will give the line numbers to the content of the file but ignore the blank lines.
Ex: $ cat -b sam.txt
- mv
Description:
This command is used to rename the files with the new file name.Here this command first creates an empty file with the name given, then copies the contents of the old file to the new empty file and finally it deletes the old file.
This command is used to rename the files with the new file name.Here this command first creates an empty file with the name given, then copies the contents of the old file to the new empty file and finally it deletes the old file.
Syntax:
$ mv <option(s)> old_filename new_filename
$ mv <option(s)> old_filename new_filename
Example:
$ mv sam.txt isad.c
$ mv sam.txt isad.c
Output:
This command will change the name of the "sam.txt" to "isad.c".
This command is used to remove the existing file(s) from directory hierarchy.
Syntax:
$ rm <option(s)> file_name(s)
Example:
$ rm sam.txt
Output:
This command will delete the file "sam.txt" from the hierarchy.
Options:
1. -f (Forcibly Removal):
Desc: This option is used to remove the file even though it is write protected.
Ex: rm -f sam.txt
2. -r (Recursive Removal):
Desc: This option will remove all the files and empty directories even though if the directory is having the files, it will removes the files first then remove the emptied directory.
Ex: rm -r sam.txt
3. -i (Interactive Removal):
Desc: The rm command with -i flag will ask the user before removing the file or directory.
Ex: rm -i sam.txt
This command will change the name of the "sam.txt" to "isad.c".
- rm
This command is used to remove the existing file(s) from directory hierarchy.
Syntax:
$ rm <option(s)> file_name(s)
Example:
$ rm sam.txt
Output:
This command will delete the file "sam.txt" from the hierarchy.
Options:
1. -f (Forcibly Removal):
Desc: This option is used to remove the file even though it is write protected.
Ex: rm -f sam.txt
2. -r (Recursive Removal):
Desc: This option will remove all the files and empty directories even though if the directory is having the files, it will removes the files first then remove the emptied directory.
Ex: rm -r sam.txt
3. -i (Interactive Removal):
Desc: The rm command with -i flag will ask the user before removing the file or directory.
Ex: rm -i sam.txt
Comments
Post a Comment