cat :- read/write/apend a file
rm :- Delete a file
cp :- Copy a file from source to destination directory
mv :- Move or rename a file from source to destination directory
vi,nano :- These are the Text editors to create or modify a file
touch :- Create an empty file
1. To Read or display the content of a file
$ cat <<filename>>
## To read file1
$ cat file1
2. To Read or display the content of multiple files
# To print content of file1 then file2
$ cat file1 file2
# To print content of all txt files
$ cat *.txt
3. To view the file content with line number
$ cat -n file1
4. To create a new file ( after finishing writing in file press Enter and then CTRL + C)
$ cat > file1
5. To Copy the content of a file to another file
# to copy content of file1 to file2
$ cat file1 > file2
# To merge content of multiple files file1,file2.file3 into file4
$ cat file1 file2 file3 > file4
6. To Append the content of a file to another file
# to append the content of file1 to file2
$ cat file1 >> file2
7. To Append new content to a file ( after finishing writing in file press Enter and then CTRL + C)
$ cat >> file1
Examples ( Assume all the directories in below examples exists)
Create an empty file (App01.txt) under /tmp/test/testingTypes/unitTest directory
touch /tmp/test/testingTypes/unitTest/App01.txt
Create 2 more empty filess (App02.txt and App03.txt) under /tmp/test/testingTypes/unitTest directory
cd /tmp/test/testingTypes/unitTest
touch App02.txt App03.txt
Copy App03.txt file to /home/ubuntu directory
cp App03.txt /home/ubuntu/.
Add some data inside /home/ubuntu/App03.txt file and read the contents
cd /home/ubuntu
echo "This is test case 3" >> App03.txt
cat App03.txt
Delete the App03.txt file from /tmp/test/testingTypes/unitTest
rm /tmp/test/testingTypes/unitTest/App03.txt
Move /home/ubuntu/App03.txt to /tmp/test/testingTypes/unitTest
mv App03.txt /tmp/test/testingTypes/unitTest/App03.txt
Open /tmp/test/testingTypes/unitTest/App02.txt in vi editor and add some text into this file(:wq! save and exit and :q! for quit without save)
vi /tmp/test/testingTypes/unitTest/App02.txt
Remove all txt files under /tmp/test/testingTypes/unitTest
rm /tmp/test/testingTypes/unitTest/*.txt
COMMENTS