Tag Info

New answers tagged

11

Use ddrescue, which is designed for this type of scenario. It uses a log file to keep track of the parts of the data that it has successfully copied - or otherwise. As a result you can stop and restart it as many times as necessary, provided that the log file is maintained. See Ddrescue - Data recovery tool


2

Use dd. It can do a lot, but you need the following form: dd if=<source> of=<destination> bs=<block size> count=<blocks> skip=<offset> E.g., to copy the 2nd to the 4th kilobyte from a file, you'd do: dd if=in.dat of=out.dat bs=1K count=2 skip=2 Given the specifics of what you're trying to do, you can also try to add ...


1

If you want to copy all the .txt files in a directory, use a wildcard pattern: cp direct/direct1/*.txt target This copies all the .txt files that are in the directory direct/direct1 to the directory target (which must already exist). You can pass multiple patterns to copy files from multiple directories: cp direct/direct1/*.txt direct/direct2/*.txt ...


2

You can use find to only select the `.txt files from under some directory: find direct/direct? -name "*.txt" this would print out all the files, so you can check you got what you wanted, and not too much is going to be selected. The *.txt has to be quoted, otherwise the shell will try expand this to .txt files in the current directory. As for the ...


1

If you have the permission to use FUSE on your local machine, install the sshfs package. SSHFS lets you access remote files via normal filesystem access: it mounts a directory tree accessed over SFTP. You only need to have SFTP access on the remote side (which is enabled by default with OpenSSH on Ubuntu). Once the remote directory is mounted, you can use ...


2

You can use a tar and ssh combintaion like this: sudo tar cvzf - folder/ | ssh -C user_name@host_name "cd ~/; tar xvzf -"


4

You can use scp -r to copy files recursively between different hosts. Your syntax could be like scp -r user@Ubuntu-Server:/home/myuser ./from_Ubuntu_server Besides, you might be able to upload your local rsync binary using scp to the Ubuntu server and add the --rsync-path=/home/myuser/rsync to your original rsync command to let your client rsync know which ...


1

#!/bin/bash ss=0 for file do cp -fp -- "$file" "${file%.*}_copy.${file##*.}" || ss=$? done exit $ss This fails if file does not have a dot extension part. If you need that to work use Stéphane Chazelas's solution.


1

Since the OP is asking for a bash solution. Here is one that does. #!/bin/bash if [[ ! -f $1 && $(($# != 1)) ]]; then printf '%s\n' "Provide a filename" exit 1 fi inFile="$1" fileExt="${1#*.}" destFile="${1%.*}" cp -- "$inFile" "${destFile}_copy.$fileExt" # As suggested, so the files that start with a dash are not ignored.


-1

cp /example/directory/file.doc /example/directory/file_copy.doc this specifies the file name and will do what you want


4

No need for bash here, any standard sh interpreter implementation will do: #! /bin/sh - ret=0 for file do dir=$(dirname -- "$file") case $dir in (*[!/]*) dir=$dir/ # handle / and // specially esac base=$(basename -- "$file") name=${base%.*} name=${name:-$base} # don't consider .bashrc the extension in /foo/.bashrc ext=${base#"$name"} ...


5

rsync -avz --delete "/home/user/A" "/home/user/B"


0

This is not completely the same as what you ask for, but you could considered using a version-control tool. Tools like Git do everything you ask for, and more, especially if you do not work in folder B directly it could be interesting to take a look at it. you can find some more information on git here


2

One of your problems is that you left out the double quotes around the command substitution, so the output from the date command was split at spaces. See Why does my shell script choke on whitespace or other special characters? This is a valid command: cp -a /home/bpacheco/Test1 "/home/bpacheco/Test2-$(date +"%m-%d-%y-%r")" If you want to append to the ...


0

Look at rsnapshot. I'm pretty sure it will do everything you want, and as a bonus can be expanded to keep files for longer than two months when you get a bigger drive.


2

I don't think this likely has anything to do with the mounting. Are you sure the CR characters are there originally in the file? Assuming they are not, you can use unix2dos to add them, though I haven't actually verified that exists for AIX. You could use sed like sed -i -e 's/\n/\r\n/g' <file> if you don't have unix2dos available. The -i flag ...


1

It doesn’t matter how you mounted the partition. Every byte of every file will be transferred. If your files do not have carriage returns after the transfer, then they didn’t have them before. I don’t know what command to run on AIX to check the encoding of your files, but you could just look at them in a binary editor and see if the lines are terminated ...


0

Some shell: this will be much slower than an awk program. cd /User/MyData for sample in Sample*.fasta; do sample_name=${sample%.fasta} while read name; read data; do name=${name#>} printf ">%s\n%s\n" "$sample_name" "$data" >> "$name.fasta" done < "$sample" done


2

To copy and truncate file names on the fly, you could do: cd /src && LC_ALL=C pax -rws'|\([^/]\{255\}\)[^/]*|\1|g' ./* /dst/ to truncate to 255 byte path components. Note that it may truncate a file name in the middle of a character if there are multi-byte characters in those file names. It will also update the targets of symlinks (though I'm ...


1

I have the following code for you; below it there's an explanation how it works. First go into the working directory (cd /User/MyData/) to run this program: awk ' FNR==1 { sample = FILENAME ; sub(/\.fasta/, "", sample } /^>/ { target = substr($0,2)".fasta" ; next } { print ">" sample > target ; print > target } ' Sample_*.fasta ...


0

Although it would be interesting to know what you've tried so far, here is an example how awk could be used for this job: awk ' FNR == 1 { sub(/\.fasta$/, "", FILENAME) } /^>/ && sub(/^>/, "") { newfile = $0 ".fasta" next } { print ">" FILENAME >> newfile print $0 >> ...



Top 50 recent answers are included