UNIX Cat All Files In A Directory

Posted on in Categories last updated February 25, 2010

How do I combine all text files in a directory into a single file and ftp that file to another server?

You can use cat command as follows:

cd /dest/dir
cat *.txt > /tmp/output.txt
# now send file using lftp ftp client
lftp -u username,password -e "cd /some/ftp/dir; put /tmp/output.txt; quit;" ftp.nixcraft.in

The following will find every text file in directory:

find /dest/dir -name "*.txt" -print | xargs cat >> /tmp/output1.txt    
# now send file using lftp ftp client
lftp -u username,password -e "cd /some/ftp/dir; put /tmp/output.txt; quit;" ftp.nixcraft.in

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

Leave a Comment