1. Using cat
Command
The cat
command can be used to create and view files, but cannot be used to edit existing content.
Create a File
cat > file1
- (>) redirects output into the file.
- Use Ctrl + D to save and exit.
Append to a File
cat >> file1
- (>>) appends new data to the file without modifying existing content.
- Note:
cat
is not a text editor. -
cat
>> file1 { >> use to add new data without changing existing data}
Concatenate Files
cat file1 file2 > file3
- Combines contents of file1 and file2 into file3.
-
tac
command is used to reverse the content of the file. - In
cat
we cannot create multiple files at once whereas in touch we can.
cat file1 > file2
- Copy Content from One File to Another
2 Using Touch Command
touch <filename>
- create empty file (Main purpose is Time Stamping)
- stat command to see the stat (access stamp, modify stamp, change/update stamp)
3 using Vi/Vim (editor)
Modes in VI Editor
- Normal Mode (default) – Used for navigation and command execution.
- Insert Mode – Used for text editing (press i to enter, Esc to exit).
- Command Mode – Used for saving, quitting, and searching (press : in Normal mode).
vi <filename>
-
i
– Insert before cursor -
Esc
- to escape from insert mode -
:wq
- to save and exit -
:wq!
- to forcefully saving and exiting. -
:q!
- Quit without saving
4 Nano (editor)
-
nano
is a simpler command-line text editor. It is user-friendly and suitable for beginners.
Top comments (0)