In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article is about how to append text content to the end of a file in Linux. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Append text using the > > operator
The operator redirects the output to a file, which is created if the file does not exist, but if it does, the output is appended to the end of the file.
For example, you can use the echo command to append text to the end of the file, as shown in the figure.
# echo "/ mnt / pg_master / wal_archives 10.20.20.5 (rw,sync,no_root_squash)" > / etc / exports#echo "/ mnt / pg_master / wal_archives 10.20.20.5 (rw,sync,no_root_squash)" > > / etc / exports
Alternatively, you can use the printf command (don't forget to add the next line with\ ncharacters).
# printf "/ mnt / pg_master / wal_archives 10.20.20.5 (rw,sync,no_root_squash)\ n" > / etc / exports#printf "/ mnt / pg_master / wal_archives 10.20.20.5 (rw,sync,no_root_squash)\ n" > / etc / exports
You can also use the cat command to connect text from one or more files and append it to another file.
In the following example, other file system shares to be added to the / etc / exports configuration file are added to a text file named shares.txt.
# cat / etc/exports# cat shares.txt# cat shares.txt > > / etc/exports# cat / etc/exports# cat / etc/exports# cat shares.txt# cat shares.txt > > / etc/exports# cat / etc/exports
In addition, you can use the following documents here to append the configuration text to the end of the file, as shown below.
# cat / etc/exports# cat > > / etc/exports / mnt/nfs_all 10.20.20.5 (rw,sync) > EOF# cat / etc/exports# cat / etc/exports# cat > > / etc/exports / mnt/nfs_all 10.20.20.5 (rw,sync) > EOF# cat / etc/exports
Note: do not mistake the > redirection operator for > >; using > for an existing file will delete the contents of the file and then overwrite it, which may result in data loss.
Use the tee command to append text
The tee command copies text from standard input and pastes / writes it to standard output and files. You can use its-a flag to append text to the end of the file, as shown below.
# echo "/ mnt/pg_master/wal_archives 10.20.20.5 (rw,sync,no_root_squash)" | tee-a / etc/exports OR # cat shares.txt | tee-a / etc/exports# echo "/ mnt/pg_master/wal_archives 10.20.20.5 (rw,sync No_root_squash) "| tee-a / etc/exportsOR# cat shares.txt | tee-a / etc/exports# echo" / mnt/pg_master/wal_archives 10.20.20.5 (rw,sync,no_root_squash) "| tee-a / etc/exportsOR# cat shares.txt | tee-a / etc/exports# echo" / mnt/pg_master/wal_archives 10.20.20.5 (rw,sync) No_root_squash) "| tee-a / etc/exportsOR# cat shares.txt | tee-a / etc/export |
You can also use here documents with the tee command.
# cat / mnt/nfs_all 10.20.20.5 (rw,sync) EOF# cat / mnt/nfs_all 10.20.20.5 (rw,sync) EOF
Thank you for reading! On "how to append the text content to the end of the file in Linux" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, you can share it out for more people to see it!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.