ECHO COMMAND
FILE OPERATIONS USING ECHO COMMAND IN UNIX
- In this tutorial, you can learn and practice the various file operations like file creation, copying, merging, listing files, etc,. using echo command in linux with examples.
echo command
- Echo is a one of the popular linux command which is used for file creation, displaying message, files and folders, file copying, files merging, text appending to files, etc,.
Practical Usages of echo command
- File Creation
- Text Appending to File
- File Copying
- Files Merging
- Listing files
- Listing specific files
- Listing only directories
1. File Creation using echo command
- File can be created using echo command in linux / unix. Use the below syntax to create a new file.
- This is done by using the output redirection operator >
Syntax
Example
2. Text Appending to File using echo command
- Text can be appended to file using echo command along with output redirection append operator >>
- Use the below syntax to create a new file.
Syntax
Example
3. File Copying using echo command
- File can be copied to another file using echo command with command substitution method and output redirection operator >
- Command Substitution is a process of the getting the output of built-in command to a variable. This is performed using $(command) or `command`
- Here the output of input file can be obtained using command substitution and these output will be redirected to target file using the output redirection operator >
Syntax
Example
4. Files Merging using echo command
- This is done by using the same style of file copying
- So multiple files can be merged into single file using command substitution along with output redirection operator >
Syntax
Example
- In the above screenshot, contents of two text files are merged into third file which is called as jf.txt
5. Listing Only Files using echo
- We can display list of files in the current directory using echo command
- It is an alternative to ls command
- Use the below syntax to display the list of files
Syntax
Example
6. Listing Only Specific Files using echo
- We can display only specific types of files in the current directory using echo command
- This is done by using * symbol with file extensions. The file extension can be general text files, code files, image files
- Use the below syntax to display the list of files
Syntax
Example
7. Listing Only Directories using echo command
- We can display only directories using echo command
- This is done by using the special pattern */. Here the symbol / restricts only directories instead of files
- Use the below syntax to display the list of files
Syntax
Example