Best Industrial Training in C,C++,PHP,Dot Net,Java in Jalandhar

Tuesday, 17 September 2013

Basic commands to manage files

Linux and Unix are managed through a series of text files. Linux administrators do not normally use graphical editors to manage these configuration files. Editors such as WordPerfect, OpenOffice.org Writer, Microsoft Word normally either save files in a binary format or add tags. Unless text files are preserved in their original format, without tags, changes that are made can render a Linux system unbootable.
In RHCE certification you have to perform several tasks on command line. In this article I would some basic commands to create / edit /delete files on Linux system.

How to create and read files on command line in RHEL Linux

Everything in Linux can be reduced to a file.

cat

The most basic command for reading and creating files is cat. The cat filename command scrolls the text within the filename file. It also works with multiple filenames; it concatenates the filenames that you might list as one continuous output to your screen. You can redirect the output to the filename of your choice.
To Create a file
cat command create file example
Use ctrl+d to save file
To read the contain of file
cat command to read file
To extend the contain of file use >> with cat command
cat command append example
While extending contents from cat command take care of > . User single > to create new file and >> to extend the contents. If you have used single > to extended the content if would overwrite the existing content of file without any warning.
cat command overwrite example

How to create directories on command line in RHEL Linux

Directories are special types of files that serve as containers for other files.

mkdir

Basic command to create new directory.
mkdir command
To create directory tree use -p
mkdir command with p switch

How to delete files / directories on command line in RHEL Linux

To remove directory use rmdir command
rmdir command
To delete file use rm command
rm command
rmdir command would not delete a directory which contain data inside it
To delete a directory which contain data inside it use rm command with –rf option
rm with rf switch

No comments:

Post a Comment