scp’ing Files using a Text File List
If you have a collection of files that you want to transfer to a
remote server and they are a subset of files in the current directory or
scattered among different directories you can create a list of files and
then pipe the list to scp
:
$ cat filelist.txt | xargs -i scp {} user@remote:~/backup/
Archive Only Files In a Directory
If you want to create a tar archive of only the files of a directory and exclude any subdirectories you can use the ls -la
command and pipe the output to awk
. However you need to remove the first 8 fields from the output and leave all of the remaining parts of the line in case there are spaces in the filename. One quick and dirty way of doing that is to set each of the 8 fields to a blank and then use sed
to trim the leading spaces. You can optionally add quotation marks around the filename in your output too.
$ ls -al | awk '$0!~/^d/ {$1=$2=$3=$4=$5=$6=$7=$8=""; printf("%s\"\n", $0)}' | sed 's/^[[:space:]]*/"/' | xargs tar cvf archive-name.tar