Followers

Linux -FileCommands

 
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

Name

Ansible,6,AWS,1,Azure DevOps,1,Containerization with docker,2,DevOps,2,Docker Quiz,1,Docker Swarm,1,DockerCompose,1,ELK,2,git,2,Jira,1,Kubernetes,1,Kubernetes Quiz,5,SAST DAST Security Testing,1,SonarQube,3,Splunk,2,vagrant kubernetes,1,YAML Basics,1,
ltr
static_page
DevOpsWorld: Linux -FileCommands
Linux -FileCommands
DevOpsWorld
https://www.devopsworld.co.in/p/linux-filecommands.html
https://www.devopsworld.co.in/
https://www.devopsworld.co.in/
https://www.devopsworld.co.in/p/linux-filecommands.html
true
5997357714110665304
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy Table of Content