date
int64
1,220B
1,719B
question_description
stringlengths
28
29.9k
accepted_answer
stringlengths
12
26.4k
question_title
stringlengths
14
159
1,387,878,201,000
How is install different from a simple copy, cp or dd? I just compiled a little utility and want to add it to /usr/sbin so it becomes available via my PATH variable. Why use one vs the other?
To "install" a binary compiled from source the best-practice would be to put it under the directory: /usr/local/bin On some systems that path is already in your PATH variable, if not you can add it by adapting the PATH variable in one of your profile configuration files ~/.bashrc ~/.profile PATH=${PATH}:/usr/local/b...
How is install different from cp? [duplicate]
1,387,878,201,000
I have a huge file tree. Some files have same name but in different case, e.g., some_code.c and Some_Code.c. So when I'm trying to copy it to an NTFS/FAT filesystem, it asks me about whether I want it to replace the file or skip it. Is there any way to automatically rename such files, for example, by adding  (1) to th...
Many GNU tools such as cp, mv and tar support creating backup files when the target exists. That is, when copying foo to bar, if there is already a file called bar, the existing bar will be renamed, and after the copy bar will contain the contents of foo. By default, bar is renamed to bar~, but the behavior can be mod...
Copy files with renaming
1,387,878,201,000
I have moved (mv) a pretty large directory on my NAS (Linux based), but had to interrupt the procedure. Not being a regular Linux user, I though I could just continue and merge the rest later in. mv /oldisk/a /newdisk Procedure is halfway done, so rest of /oldisk/a still exists, and /newdisk/a with the already copied...
rsync --verbose --archive --dry-run /oldisk/a/ /newdisk/a/ The --dry-run (or -n) will do a dry run, showing you what it would do without actually doing anything. If it looks ok, run the rsync without the -n option. This will be a copy, not a move, which isn't quite what you're doing, but is safer. The --archive (or -a...
Best way to continue stopped move (mv) by merging directories?
1,387,878,201,000
So I have a repo with some of my config files and I'm trying to create a makefile to install them in the homedir. The problem I have is that when I run the following command straight in bash install -m 755 -d ~/path/to/dotfilesDir/ ~/ seemingly nothing happens while install -m 755 ~/path/to/dotfilesDir/{file1,file2,....
From a look at the man page, it seems that install will not do what you want. Indeed, the Synopsis section indicates a usage of the form: install [OPTION]... -d DIRECTORY... and later on, the man page says: -d, --directory treat all arguments as directory names; create all components of the s...
Problem with install command to copy a whole directory
1,387,878,201,000
I'm doing this sync locally on Ubuntu 12.04. The files are generally small text files (code). I want to copy (preserving mtime stamp) from source directory to target but I only want to copy if the file in target already exists and is older than the one in source. So I am only copying files that are newer in source, bu...
I believe you can use rsync to do this. The key observation would be in needing to use the --existing and --update switches. --existing skip creating new files on receiver -u, --update skip files that are newer on the receiver A command like this would do it: $ rsync -avz --upd...
Best way to sync files - copy only EXISTING files and only if NEWER than target
1,387,878,201,000
I'm trying to upload some big files (around 10GB) with a slow upload speed (200kb/s) on a often disconnected SSH connection (due to poor network conditions). I'm trying to use scp, but if there is a best way over SSH, I'm ok with it. What is the best way to do it ? I've tried to split it up in several parts using spli...
Use rsync with the --partial option rsync -av --partial sourcedir user@desthost:/destinationdir The --partial will keep partially transferred files. When you resume the rsync transfer after a ssh broken connection, partially transferred files will start resuming from the point where the ssh connection was lost, and a...
Transfer a file over a unstable SSH connection
1,387,878,201,000
This is a very basic question I am just quite new to bash and couldn't figure out how to do this. Googling unfortunately didn't get me anywhere. My goal is to connect with sftp to a server, upload a file, and then disconnect. I have the following script: UpdateJar.sh #!/bin/bash sftp -oPort=23 [email protected]:/home...
You can change your script to pass commands in a here-document, e.g., #!/bin/bash sftp -oPort=23 [email protected]:/home/kalenpw/TestWorld/plugins <<EOF put /home/kalenpw/.m2/repository/com/Khalidor/TestPlugin/0.0.1-SNAPSHOT/TestPlugin-0.0.1-SNAPSHOT.jar exit EOF The << marker followed by the name (EOF) tells the...
Execute command in sftp connection through script
1,387,878,201,000
I'd like to copy a content of directory 1 to directory 2.  However, I'd like to only copy files (and not directories) from my directory 1.  How can I do that? cp dir1/* dir2/* then I still have the directories issue. Also, all my files don't have any extension, so *.* won't do the trick.
cp dir1/* dir2 cp will not copy directories unless explicitly told to do so (with --recursive for example, see man cp). Note 1: cp will most likely exit with a non-zero status, but the files will have been copied anyway. This may be an issue when chaining commands based on exit codes:&&, ||, if cp -r dir1/* dir2; the...
Copy only regular files from one directory to another
1,387,878,201,000
I drag and drop a folder into another by mistake in FileZilla. ~/big_folder ~/some_other_folder The folder got moved is a very huge one. It includes hundreds of thousands of files (node_modules, small image files, a lot of folders) What is so weird is that after I release my mouse, the moving is done. The folder "big...
If a directory is moved within the same filesystem (the same partition), then all that is needed is to rename the file path of the directory. No data apart from the directory entry for the directory itself has to be altered. When copying directories, the data for each and every file needs to be duplicated. This invo...
Why is mv so much faster than cp? How do I recover from an incorrect mv command?
1,387,878,201,000
I'm on a macbook running Lion. In Terminal I'm connected to my schools server with ssh. I navigated to a folder on the server and have a file I want to copy to my local machine, but I don't know what the IP address of my local machine is. How can I get it? I'm in the folder on the server, and I want to copy read.txt o...
You don't need to know your own host's IP address in order to copy files to it. Simply use scp to copy the file from the remote host: $ scp [email protected]:path/to/read.txt ~/path/to/newRead.txt If you want to copy to your local host from your remote host, get your own IP address with ifconfig and issue the followi...
How can I get the address of my local machine?
1,387,878,201,000
You've got three folders: folder current, which contains your current files folder old, which contains an older version of the same files folder difference, which is just an empty folder How do you compare old with current and copy the files which are different (or entirely new) in current to difference? I have sea...
I am not sure whether you can do it with any existing linux commands such as rsync or diff. But in my case I had to write my own script using Python, as python has the "filecmp" module for file comparison. I have posted the whole script and usage in my personal site - http://linuxfreelancer.com/ It usage is simple - g...
How do you compare two folders and copy the difference to a third folder?
1,387,878,201,000
I am investigating the behavior of a binary on Oracle Linux 9 (XFS filesystem). This binary, when called by a process, creates a directory under /tmp and copies some files to it. This directory gets a randomized name each time the process runs (a keyword + a GUID). Immediately after, it deletes the directory. I want t...
I found this shell script that uses inotify-tools, and it did exactly what I was looking for (author: https://unix.stackexchange.com/a/265995/536771): #!/bin/sh TMP_DIR=/tmp CLONE_DIR=/tmp/clone mkdir -p $CLONE_DIR wait_dir() { inotifywait -mr --format='%w%f' -e create "$1" 2>/dev/null | while read file; do ec...
How can I copy a /tmp/ directory that is created & deleted by a process?
1,387,878,201,000
Some file copying programs like rsync and curl have the ability to resume failed transfers/copies. Noting that there can be many causes of these failures, in some cases the program can do "cleanup" some cases the program can't. When these programs resume, they seem to just calculate the size of the file/data that wa...
For clarity's sake - the real mechanics is more complicated to give even better security - you can imagine the write-to-disk operation like this: application writes bytes (1) the kernel (and/or the file system IOSS) buffers them once the buffer is full, it gets flushed to the file system: the block is allocated (2)...
How do programs that can resume failed file transfers know where to start appending data?
1,387,878,201,000
I'm not very familiar with all the tricks of grep/find/awk/xargs quite yet. I have some files matching a particular pattern, say *.xxx. These files are in random places throughout a certain directory. How can I find all such files, and move them to a folder in my home directory on Unix (that may not exist yet)?
mkdir ~/dst find source -name "*.xxx" -exec mv -i {} -t ~/dst \;
How can you move (or copy) all files of a certain type to a directory in Unix?
1,387,878,201,000
What are the consequences for a ext4 filesystem when I terminate a copying cp command by typing Ctrl + C while it is running? Does the filesystem get corrupted? Is the partition's space occupied by the incomplete copied file still usable after deleting it? And, most importantly, is terminating a cp process a safe thin...
This is safe to do, but naturally you may not have finished the copy. When the cp command is run, it makes syscalls that instruct the kernel to make copies of the file. A syscall, or system call, is a function that an application can use to requests a service from the kernel, such as reading or writing data to the dis...
What happens when I kill 'cp'? Is it safe and does it have any consequences?
1,387,878,201,000
What is the effect of copying a file say fileA.big (900mb) from location B to location C, if during that cp operation, say 35% through the process, fileA.big is appended with new information and grows from 900MB to 930MB? What is the result of the end copy (i.e. fileA.big at location C)? What if the copy is about 70% ...
If fileA.big is grown during the copy, the copy will include the data that was appended. If the file is truncated shorter than where the copy is currently at, the copy will abort right where its at and the destination file will contain what was copied up to the time it aborted.
What happens if a file is modified while you're copying it?
1,387,878,201,000
I have a home file server that I use Ubuntu on. Recently, one of my drives filled up so I got another and threw it in there. I have a very large folder, the directory is about 1.7 T in size and contains a decent amount of files. I used GCP to COPY the files from the old drive to the new one and it seems to have worked...
I’d simply use the diff command: diff -rq --no-dereference /path/to/old/drive/ /path/to/new/drive/ This reads and compares every file in the directory trees and reports any differences. The -r flag compares the directories recursively while the -q flag just prints a message to screen when files differ – as opposed to...
Verifying a large directory after copy from one hard drive to another
1,387,878,201,000
Is there a multi-threaded cp command on Linux? I know how to do this on Windows, but I don't know how this is approached in a Linux environment.
As Celada mentioned, there would be no point to using multiple threads of execution since a copy operation doesn't really use the cpu. As ryekayo mentioned, you can run multiple instances of cp so that you end up with multiple concurrent IO streams, but even this is typically counter-productive. If you are copying f...
Multithreaded cp on linux? [duplicate]
1,387,878,201,000
I have a large directory containing subdirectories and files that I wish to copy recursively. Is there any way to tell cp that it should perform the copy operation in order of file size, so that the smallest files get copied first?
This does the whole job in one go - in all child directories, all in a single stream without any filename problems. It'll copy from smallest to largest every file you have. You will need to mkdir ${DESTINATION} if it doesn't already exist. find . ! -type d -print0 | du -b0 --files0-from=/dev/stdin | sort -zk1,1n | se...
copy smallest files first?
1,387,878,201,000
I want to cp aaa/deep/sea/blob.psd to bbb/deep/sea/blob.psd How do I do the copy if the deep and sea directories don't exist under bbb so that the copy both creates the directories that are needed and copies the file? Right now I get No such file or directory as deep and sea don't exist. I looked thru the man help pag...
Try to use such next function for such situation: copy_wdir() { mkdir -p -- "$(dirname -- "$2")" && cp -- "$1" "$2" ; } and use it as copy_wdir aaa/deep/sea/blob.psd bbb/deep/sea/blob.psd By the way, GNU cp has a --parents option. It's really close to what you want, but not exactly. It will also create aaa director...
How can I copy a file and create the target directories at the same time?
1,387,878,201,000
I want to rsync only certain file types (e.g. .py) and I want to exclude files in some directories (e.g. venv). This is what I have tried: rsync -avz --include='*/' --exclude='venv/' --include='*.py' --exclude='*' /tmp/src/ /tmp/dest/ But it doesn't work. What am I missing? I also followed the answer to this question...
venv/ needs to be excluded before */ is included: rsync -avz --exclude='venv/' --include='*/' --include='*.py' --exclude='*' /tmp/src/ /tmp/dest/ The subtlety is that rsync processes rules in order and the first matching rule wins. So, if --include='*/' is before --exclude='venv/', then the directory venv/ is includ...
Rsync, include only certain files types excluding some directories
1,387,878,201,000
My computer has one 500GB drive. I want to move 400GB of data from /unencrypted to /encrypted. Both directories are on the same partition, but /encrypted is handled by ecryptfs, so mv /uncrypted/* /encrypted would: Copy all files to destination Then remove them from source ...which I can't afford, because it require...
If you have rsync (remove --dry-run to do it for real): rsync --dry-run --remove-source-files -avHAX /unencrypted/ /encrypted Otherwise, using bash4+ and GNU stat: #!/bin/bash set -e shopt -s nullglob globstar for from in /unencrypted/**/*; do to="${from/\/un//}" if [[ -d "$from" ]]; then echo mkdi...
How to move a directory, file by file? (instead of "copy then remove")
1,387,878,201,000
I'm playing with btrfs, which allows cp --reflink to copy-on-write. Other programs, such as lxc-clone, may use this feature as well. My question is, how to tell if a file is a CoW of another? Like for hardlink, I can tell from the inode number.
Good question. Looks like there aren't currently any easy high-level ways to tell. One problem is that a file may only share part of the data via Copy-on-Write. This is called a physical extent, and some or all of the physical extents may be shared between CoW files. There is nothing analogous to an inode which, when ...
How to verify a file copy is reflink/CoW?
1,387,878,201,000
I've got two issues with my script that copies files and adds a timestamp to the name. cp -ra /home/bpacheco/Test1 /home/bpacheco/Test2-$(date +"%m-%d-%y-%T") The above adds Test2 as the filename, but I want it to keep the original source file's file name which in this example is named Test. cp -ra /home/bpacheco/Tes...
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...
Copy a file and append a timestamp
1,387,878,201,000
Instead of using the following command: cp {source file} {dest file} I want to be able to copy a file into the clipboard, and paste it somewhere else, in another directory. something like this: /usr/local/dir1# cp {source file} /usr/local/dir1# cd /usr/local/dir2 /usr/local/dir2# paste Is it possible?
I think you should do something like the GUI applications do. My idea for doing this is to write two functions for Copy and Paste, where Copy writes path of files to be copied to a temporary file and Paste reads those paths and simply calls cp command. My implementation (to be put in .bashrc file) is like below: funct...
Copy and paste a file/directory from command line
1,387,878,201,000
I have no experience with btrfs, but it's advertised to be able to de-duplicate files. In my application, I'd need to duplicate whole directory trees. From what I learned, btrfs only de-duplicates in some post scan, not immediately. Even just using cp doesn't seem to trigger any de-duplication (at least, df shows an i...
There are two options: cp --reflink=always cp --reflink=auto The second is almost always preferable to the first. Using auto means it will fallback to doing a true copy if the file system doesn't support reflinking (for instance, ext4 or copying to an NFS share). With the first option, I'm pretty sure it will outrig...
How to duplicate a file without copying its data with btrfs?
1,387,878,201,000
I want to copy the attributes (ownership, group, ACL, extended attributes, etc.) of one directory to another but not the directory contents itself. This does not work: cp -v --attributes-only A B cp: omitting directory `A' Note: It does not have to be cp.
After quite a bit of trial and error on the commandline, I think I've found the answer. But it isn't a cp-related answer. rsync -ptgo -A -X -d --no-recursive --exclude=* first-dir/ second-dir This does: -p, --perms preserve permissions -t, --times preserve modification times -o, --owne...
How to clone/copy all file/directory attributes onto different file/directory?
1,513,855,139,000
I have to move some files from one filesystem to another under Ubuntu. However, it is very important that the files never exist as partial or incomplete files at the destination, at least not under the correct file name. So far, my only solution is to write a script that takes each file, copies it to a temporary name ...
rsync copies to temporary filenames (e.g. see Rsync temporary file extension and rsync - does it create a temp file during transfer?) unless you use the --inplace option. It renames them only after the file has been transferred successfully. rsync also deletes any destination files that were only partially transferr...
Approximating atomic move across file systems?
1,513,855,139,000
I'm writing a script to publish a webapp. While copying files, I must replace a placeholder current_date in a file with the current date. I would start with something like this to define the date string date=`date +%Y%m%d` The copy and replace part is where I don't know how to start.
Use sed. Here is an example: sed "s/current_date/`date +%Y%m%d`/" infile > copyfile
Copy file while replacing text in it
1,513,855,139,000
I want to copy and rename multiple c source files in a directory. I can copy like this: $ cp *.c $OTHERDIR But I want to give a prefix to all the file names: file.c --> old#file.c How can I do this in 1 step?
a for loop: for f in *.c; do cp -- "$f" "$OTHERDIR/old#$f"; done I often add the -v option to cp to allow me to watch the progress.
How to copy and add prefix to file names in one step?
1,513,855,139,000
I am totally new to Unix. I am writting a script which will copy files from a Windows shared folder to Unix. In Windows, when I type \\Servername.com\testfolder in Run command I am able to see testfolder. The directory testfolder is a shared folder through the whole network. Now I want to copy some files from that te...
From your UNIX server you need to mount the Windows share using the procedure laid out in this link. Basically you create a directory on your UNIX machine that is called the mount point. You then use the mount command to mount the Windows share on that mount point. Then when you go to the directory that you have cre...
Copy file from Windows shared folder to Unix
1,513,855,139,000
consider the following example: /source /source/folder1 /source/folder2 /source/folder3 /destination /destination/folder2 /destination/folder3 /destination/folder3/mytestfolder1 /destination/folder4 /destination/folder4/mytestfolder1 /destination/folder4/mytestfolder2 I want to sync source to...
If you use an absolute path in a filter (include/exclude), it's interpreted starting from the root of the synchronization. You aren't excluding a directory in the source, or a excluding a directory in the destination, you're excluding a directory in the tree to synchronize. Thus: rsync -av --delete --progress --exclu...
how do I exclude a specific folder on the destination when using rsync?
1,513,855,139,000
How would I copy (archive style where date isn't changed) all the files in a backup directory to the user's directory while renaming each file to remove the random string portion from the name (i.e., -2b0fd460_1426b77b1ee_-7b8e)? cp from: /backup/path/data/Erp.2014.02.16_16.57.03-2b0fd460_1426b77b1ee_-7b8e.etf to: /h...
pax can do this all at once. You could do: cd /backup/path/data && pax -wrs'/-.*$/.etf/' Erp*etf /home/user/data pax preserves times by default, but can add -pe to preserve everything (best done as root) or -pp to preserve permissions , eg: cd /backup/path/data && pax -wrs'/-.*$/.etf/' -pe Erp*etf /home/user/data Ot...
how to rename files while copying?
1,513,855,139,000
I have a problem with the timestamps of files copied from my PC or laptop to USB drives: the last modification time of the original file and that of the copied file are different. Therefore, synchronizing files between my PC and my USB drive is quite cumbersome. A step by step description I copy an arbitrary file fro...
The problem with the timestamp seconds changing comes from the fact that a VFAT (yes, even FAT32) filesystem stores the modification time with only 2-second resolution. Apparently, as long as the filesystem is mounted, the filesystem driver caches timestamps accurate to 1-second resolution (probably to satisfy POSIX ...
Timestamps of files copied to USB drive
1,513,855,139,000
I have a text file containing a list of directories with its absolute path $ cat DirectoriesToCopy.txt /data/Dir1 /data/Dir2 I want to use rsync to copy all these directories preserving its absolute path to another location. I tried the following rsync command, but it doesn't work rsync -avr --include-from=Director...
Use the following command: rsync -av --include-from=DirectoriesToCopy.txt --include /data/ --exclude='/data/*' --exclude='/*/' / /media/MyDestination/ You need to include /data/ explicitly, you could also have added that to the list in the file. Then exclude all other directories (order is important with includes/exc...
rsync a list of directories with absolute path in text file
1,513,855,139,000
Besides the explanations from the man pages and --help information, in which way do the commands dd, cp and rsync differ when used to copy files? In which context is each of these superior to the others, for some definition of 'superior', so that it should get preference of use?
They are completely different animals that better fit on different file or device manipulation cases: dd This command was created as a "copy and convert" utility, originally intended for converting files between the ASCII, little-endian, byte-stream world of DEC computers and the EBCDIC, big-endian, appearing at t...
What is the difference between `dd`, `cp` and `rsync`? [closed]
1,513,855,139,000
I recently did a clean install of Linux Mint 17.3 with Cinnamon on my machine. Before the clean install, if I right clicked on a file or folder in nemo, the menu would have a 'create shortcut' option. Now after the clean install, that option isn't there. I've gone through the nemo preferences and I can't find any opti...
When you right click the file or folder in Nemo, there will be a + sign at the top. Clicking that will expand the menu and give you the options you want. For what it's worth, I found this functionality at this link: https://forums.linuxmint.com/viewtopic.php?t=212256
Right click menu in Nemo missing 'create shortcut' and 'copy/move to'
1,513,855,139,000
I have files created into my home directory with only user read permission (r-- --- ---). I want to copy this file to another directory /etc/test/ which has the folder permission of 744 (rwx r-- r--). I need to allow for the file I am copying to inherit the permission of the folder it is copied in because so far when ...
Permissions are generally not propagated by the directory that files are being copied into, rather new permissions are controlled by the user's umask. However when you copy a file from one location to another it's a bit of a special case where the user's umask is essentially ignored and the existing permissions on the...
File inheriting permission of directory it is copied in?
1,513,855,139,000
We have multiple deployment of an application on servers such as app00, app01 and so on. I need to copy a single log file from all these servers onto my local mac so I can perform some grepping and cutting. I used csshX for viewing this file but I cannot find an equivalent for scp. I basically want two things: Abilit...
This is trivial to do with a little script. For example: for server in app0 app1 app4 app5 appN; do scp user@$server:/path/to/log/file /local/path/to/"$server"_file done The above will copy the file from each of the servers sequentially and name it SERVERNAME_file. So, the file from app0 will be app0_file etc. Yo...
How do I copy a file from multiple servers to my local system?
1,513,855,139,000
To my understanding, for manipulating files there is only the sys_write syscall in Linux, which overwrites the file content (or extends it, if at the end). Why are there no syscalls for inserting or deleting content in files in Linux? As all current file systems do not require the file to be stored in a continuous mem...
On recent Linux systems that is actually possible, but with block (4096 most of the time), not byte granularity, and only on some filesystems (ext4 and xfs). Quoting from the fallocate(2) manpage: int fallocate(int fd, int mode, off_t offset, off_t len); [...] Collapsing file space Specifying the FALLOC_FL_COLLAPSE_R...
Why are there no file insertion syscalls
1,513,855,139,000
I have a directory on an nfs mount, which on the server is at /home/myname/.rubies Root cannot access this directory: [mitchell.usher@server ~]$ stat /home/mitchell.usher/.rubies File: `/home/mitchell.usher/.rubies' Size: 4096 Blocks: 8 IO Block: 32768 directory Device: 15h/21d Inode: 245910 ...
You can use tar as a buffer process cd .rubies tar cf - ruby-2.1.3 | ( cd /opt && sudo tar xvfp - ) The first tar runs as you and so can read your home directory; the second tar runs under sudo and so can write to /opt.
How to copy a directory which root can't access to a directory that only root can access?
1,513,855,139,000
I have millions of files with the following nomenclature on a Linux machine: 1559704165_a1ac6f55fef555ee.jpg The first 10 digits are timestamp and the ones followed by a _ are specific ids. I want to move all the files matching specific filename ids to a different folder. I tried this on the directory with files fin...
You should use: find . -maxdepth 1 -type f -name '??????????_a1ac*.jpg' \ -exec mv -t destination "{}" + So maxdepth 1 means that you want to search in current directory no subdirectories. type f means find only files. name '??????????_a1ac*.jpg' is a pattern that matches with file you are searching. mv -t destinati...
Moving millions of files to a different directory with specfic name patterns
1,513,855,139,000
Recently because of some problem, I lost all my server files and requested the hosting team to provide me my files from a backup. They will provide me a link from which I have to download a compressed file and upload it again on server. Is there any way to download that file directly onto the server? I have full acces...
You may use the wget utility. It has a really simple syntax, and all what do you need is to: wget http://link.to.file and it will be stored in the same directory where do you run wget. If you'd like to store a downloaded file somewhere else, you may use -P option, e.g. wget -P /path/to/store http://link.to.file
download file from Internet to server using SSH
1,513,855,139,000
I have a binary that creates some files in /tmp/*some folder* and runs them. This same binary deletes these files right after running them. Is there any way to intercept these files? I can't make the folder read-only, because the binary needs write permissions. I just need a way to either copy the files when they are...
You can use the inotifywait command from inotify-tools in a script to create hard links of files created in /tmp/some_folder. For example, hard link all created files from /tmp/some_folder to /tmp/some_folder_bak: #!/bin/sh ORIG_DIR=/tmp/some_folder CLONE_DIR=/tmp/some_folder_bak mkdir -p $CLONE_DIR inotifywait -m...
Watch /tmp for file creation and prevent deletion of files? [duplicate]
1,513,855,139,000
I have an Asustor NAS that runs on Linux; I don't know what distro they use. I'm able to log in it using SSH and use all Shell commands. Internal Volume uses ext2, and external USB HDs use NTFS. When I try to use cp command to copy any file around, that file's date metadata is changed to current datetime. In example, ...
If you use man cp to read the manual page for the copy command you'll find the -p and --preserve flags. -p same as --preserve=mode,ownership,timestamps and --preserve[=ATTR_LIST] preserve the specified attributes (default: mode,ownership,timestamps), if possible additional attributes: context, links, xattr, all W...
cp losing file's metadata
1,513,855,139,000
I installed Linux on another computer and I want to move my /home directory to that computer. I want to back up that directory with any file permission, symlinks etc. How should I do it? Are there any parameters for tar gzip?
If you mean you want to include the files that the symlinks point to, use -h. tar -chzf foo.tar.gz directory/ Permissions and ownership are preserved by default. If you just want to include the symlinks as symlinks, leave out -h. Small -z is for gzip. This is all spelled out in man tar; you can search for terms (suc...
Symlinks and permissions in backup archives
1,513,855,139,000
I have a top folder with many sub-folders. It's named "a". There are many .png and .jpg files in there. I'd like to recursively copy "a" into a new folder "b", but only copy the .png and .jpg files. How do I achieve that?
find a \( -name "*.png" -or -name "*.jpg" \) -exec cp {} b \;
Copy only certain file types from a folder structure to another
1,513,855,139,000
How to resume securely and reliably process of copying file $A into backup location $B done with pv "$A" > "$B" or cat "$A" > "$B" ? (let's assume file $A is very big, e.g. LVM2 snapshot file) Is it achievable with dd ? Preffered: bash or python (preferably python3) solutions. Example scenario: pv "$A" > "$B" interrup...
Yes you can use dd to skip the blocks. A="file1" B="file2" BLOCKSIZE=512 # default bs for dd size_b=$(stat -c "%s" "$B") skip_blocks=$((size_b / BLOCKSIZE)) dd if="$A" of="$B" skip=$skip_blocks seek=$skip_blocks bs=$BLOCKSIZE The important parameters here are skip as well as seek: skip: skip BLOCKS ibs-sized blo...
Resume interrupted copying process
1,513,855,139,000
I need to recursively copy a folder from a Ubuntu remote server where I have ssh access. I don't want to follow symbolic links, nor to copy permissions/owner/group, because my client system (Ubuntu too) doesn't have the same users as the server. This rsync solution could be the best one. But the server does not have r...
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 re...
Copy from remote server which doesn't have rsync
1,513,855,139,000
While moving a big chunk of data between two external USB drives, I notice my laptop is slowed down. It was my understanding that the files are not written to any intermediate location (such as /tmp or similar) unless there is a shortage of free RAM. Am I wrong?
If you have a copy such as this, or its GUI equivalent, cp -a /media/external/disk1/. /media/external/disk2/ the data is read from the first disk's filesystem and written directly to the second. There is no intermediate write to another storage location. If you are seeing slow speeds it may be that the two disks are ...
When moving files between two external drives, are they temporarily written to the internal hdd of the computer?
1,513,855,139,000
For a simple transfer of /home to another disk i use cp -a that seems to me an extremely slow way. Should like know a more efficient way to complete the task. I have /home mounted as logical volume, but the target disk is not an LVM system
Try tar, pax, cpio, with something buffering. (cd /home && bsdtar cf - .) | pv -trab -B 500M | (cd /dest && bsdtar xpSf -) I suggest bsdtar instead of tar because at least on some Linux distributions tar is GNU tar which contrary to bsdtar (from libarchive) doesn't handle preserving extended attributes or ACLs or...
faster alternative to cp -a
1,513,855,139,000
When I import pictures from my camera in Shotwell, it also imports the video clips. This is somewhat annoying, as I would like to store my videos in another folder. I've tried to write a bash command to do this, but have not had success. I need a command that meets the following requirements: Locate all files in a di...
You can use find to find all files in a directory tree that match (or don't match) some particular tests, and then to do something with them. For this particular problem, you could use: find -type f ! \( -iname '*.png' -o -iname '*.gif' -o -iname '*.jpg' -o -iname '*.xcf' \) -exec echo mv {} /new/path \; This limits ...
Bash copy all files that don't match the given extensions
1,513,855,139,000
I want to duplicate a directory on an FTP server I'm connected to from my Mac via the command-line Let's say I have file. I want to have files2 with all of file's subdirectories and files, in the same directory as the original. What would be the simplest way to achieve this? EDIT: With mget and mput you could download...
What you have is not a unix command line, what you have is an FTP session. FTP is designed primarily to upload and download files, it's not designed for general file management, and it doesn't let you run arbitrary commands on the server. In particular, as far as I know, there is no way to trigger a file copy on the s...
Easiest way to duplicate directory over FTP
1,513,855,139,000
Using Bash So let's say I have a bunch of files randomly placed in a parent directory ~/src, I want to grab all the files matching a certain suffix and move (or copy) them to a ~/dist directory. Let's assume for this purpose that all filenames have this naming convention: <filename_prefix>.<filename_suffix> I found o...
It would be a hell to tell find what to do in this case. Better use the shell: for i in **/*.{xrt,ini,moo}; do FILE=$(basename "$i") DIR=~/dst/${FILE%.*} echo mkdir -p -- "$DIR" echo mv -i -t "$DIR" -- "$i" done Use shopt -s globstar to make the ** glob work (or use zsh!). And remove the echos later if the co...
How can you move (or copy) all files to a directory with the same filename prefix?
1,513,855,139,000
I need to copy one very large file (3TB) on the same machine from one external drive to another. This might take (because of low bandwidth) many days. So I want to be prepared when I have to interrupt the copying and resume it after, say, a restart. From what I've read I can use rsync --append for this (with rsync v...
Do I use rsync --append for all invocations? Yes, you would use it each time (the first time there is nothing to append, so it's a no-op; the second and subsequent times it's actioned). But do not use --append at all unless you can guarantee that the source is unchanged from the previous run (if any), because it tur...
Is rsync --append able to resume an interrupted copy process without reading all the copied data?
1,513,855,139,000
So I'm trying to share files between the Samsung Galaxy S5 with Android and my Debian9/KDE machine using MTP instead of KDE Connect. The problem is that I keep getting: The process for the mtp protocol died unexpectedly. When trying to copy over files. It also often says No Storages found. Maybe you need to unlock ...
Install the jmtpfs package apt install jmtpfs Edit your /etc/fuse.conf as follows # Allow non-root users to specify the allow_other or allow_root mount options. user_allow_other Create an udev rule. Use lsusb or mtp-detect to get the ID of your device nano /etc/udev/rules.d/51-android.rules with the following line...
How to get the Samsung Galaxy S5 to work with MTP on Debian 9?
1,513,855,139,000
Let's say I have a large file (8GB) called example.log on ZFS. I do cp example.log example.bak to make a copy. Then I add or modify a few bytes in original file. What will happen? Will ZFS copy the entire 8GB file or only the blocks that changed (and all the chain of inodes pointing from the file descriptor to that bl...
As far as I could tell, FreeBSD ZFS does not support copy-on-write using cp; the native cp does not seem to have an option for such lightweight copies, and trying GNU cp with --reflink errors out on the ZFS system I tried with error message "cp: failed to clone 'example.bak' from 'example.log': Operation not supported...
How does ZFS copy on write work for large files
1,513,855,139,000
I have directory loaded with thousands of sub directories: /home/tmp/ 1 12 123 1234 2345 234 3456 345 34 Each subdirectory in turn has hundreds of subdirectories that I want to rsync if the first level subdirectory matches... Wh...
What you proposed should actually work: rsync -rzvvhP remotehost:/home/tmp/1\* /home/tmp/ (You can get away with not quoting the * in most circumstances, as the pattern remotehost:/home/tmp/1\* is unlikely to match any file so it will be left alone with most shell setups.) Your attempt with --exclude='*' failed becau...
rsync all directories that start with a specific digit
1,513,855,139,000
I have two folders: ORIGINAL/ ORIGINAL_AND_MY_CHANGES/ My friend has a copy of ORIGINAL/. I would like to generate MY_CHANGES.tgz -- it should contain only new/changed files from ORIGINAL_AND_MY_CHANGES/ comparing to ORIGINAL/. So my friend can unpack it into his copy of ORIGINAL/ and get ORIGINAL_AND_MY_CHANGES/. Ho...
With rsync What you're doing is essentially an incremental backup: your friend (your backup) already has the original files, and you want to make an archive containing the files you've changed from that original. Rsync has features for incremental backups. cd ORIGINAL_AND_MY_CHANGED rsync -a -c --compare-dest=../ORIGI...
How do I save changed files?
1,513,855,139,000
POSIX filenames may contain all characters except /, but some filesystems reserve characters like ?<>\\:*|". Using pax, I can copy files while replacing these reserved characters: $ pax -rw -s '/[?<>\\:*|\"]/_/gp' /source /target But pax lacks an --delete option like rsync and rsync cannot substitute characters. I'm ...
You can make a view of the FAT filesystem with POSIX semantics, including supporting file names with any character other than / or a null byte. POSIXovl is a relatively recent FUSE filesystem for this. mkdir backup-fat mount.posixovl -S /media/sdb1 backup-fat rsync -au /source backup-fat/target Characters in file nam...
What is the best way to synchronize files to a VFAT partition?
1,513,855,139,000
$ cp --no-preserve=mode --parents /sys/power/state /tmp/test/ $ cp --no-preserve=mode --parents /sys/bus/cpu/drivers_autoprobe /tmp/test/ The second of the two lines will fail with cp: cannot make directory ‘/tmp/test/sys/bus’: Permission denied And the reason is that /tmp/test/sys is created without write permissio...
In case you are using GNU coreutils. This is a bug which is fixed in version 8.26. https://lists.gnu.org/archive/html/bug-coreutils/2016-08/msg00016.html So the alternative tool would be an up-to-date coreutils, or for example rsync which is able to do that even with preserving permissions: $ rsync -a --relative /sys...
Why does cp --no-preserve=mode preserves the mode? Alternative tools available?
1,513,855,139,000
How would I go about to copy files over a very unstable internet connection? Sometimes, the connection is lost, other times the IP of one machine or the other machine is changed, sometimes both, though dynamic DNS will catch it. Which tool or command would you suggest? I've heard that rsync is pretty nifty in copying ...
OK, I have found the solution in my case. I am indeed using the suggested while loop. It now looks like this: while ! \ rsync -aiizP --append --stats . -e ssh [email protected]:./path/rfiles ; \ do now=$(date +"%T") ; echo · Error at $now · ; sleep 5 ; done Without the while loop, I would have to manually start the r...
The most *robust* remote file copy?
1,513,855,139,000
I'm looking for some sort of a command that I can use, to copy/append multiple files into one; but without shell redirection (I'd like to try it in call_usermodehelper, see similar issue in call_usermodehelper / call_usermodehelperpipe usage - Stack Overflow). I know I could otherwise use: cat file1 file2 > file.merge...
You can do: sed -n wfile.merge file1 file2 Or: awk '{print > "file.merge"}' file1 file2 Or: sh -c 'cat file1 file2 > file.merge' (note that depending on the implementation, the first two may not work properly with binary files).
Copy multiple files into one (append, merge) in single invocation without shell redirection?
1,334,477,754,000
I am trying to find the simplest way to upload a file using ssh and after that run a command on the remote machine within the same ssh session for some post-processing, so that I don't need to login again. The upload should, if possible, show some progress indicator. So far I looked into scp and rsync, and both are n...
You might want the ControlMaster mechanism in ssh.
Upload file over ssh and execute command on the remote machine
1,334,477,754,000
When moving or copying files as root I often want to set the ownership for those files based on the owner of the directory I am moving the files to. Before I go off and write a script that parses the rsync output for all the files that were copied over and then goes through those setting chown on each file, is there a...
Using rsync: rsync -ai --chown=user1 tmp/ftp/new-assests/ ~user1/tmp/ This would copy the directory to the given location and at the same time change the ownership of the files to user1, if permitted. The general form of the argument to --chown is USER:GROUP, but you may also use just USER to set a particular user as...
Setting ownership when copying or syncing files
1,334,477,754,000
I'm looking for java code to copy files to a remote linux system. I have tried Runtime.getRuntime().exec() function by passing an scp command, but each time I run the program it is asking for the remote system password. I'd like to avoid that. I looked at the Jsch library -- using this I can login to a remote system...
Copying a file from one host to another requires a daemon on the remote host, implementing some application-level file transmission protocol. This is a requirement no matter from which language you are going to talk to that remote daemon. Your options for Linux systems are: SSH. This requires a SSH daemon (say openss...
Java code to copy files from one linux machine to another linux machine
1,334,477,754,000
Is it possible to paste the selected filename into the copy popup, so when I hit F5 this filename will be in the 'to' section, so I can adjust it? For example: I want to copy /home/piotr/testFile.log to /home/piotr/testFile2.log. I open both panels in the same directory and hit F5, but the 'to' value is: /home/piotr ...
Use Shift-F5 instead (or Shift-F6 for renaming) – the dialog will have the to field filled with current file's name (without the path). Sadly those combinations not work in certain circumstances. No idea if it depends on MC build, terminal or some used library. So I also added this in ~/.mc/menu as an alternative: 5 ...
Insert selected filename while copying in Midnight Commander
1,334,477,754,000
I't trying to move around 4.5 million files (size ranges from 100 - 1000 bytes) from one partition to other. The total size of the folder is ~2.4 GB First I tried to zip it and move the zipped file to the new location. It is able to paste only ~800k files and shows "out of space" error. Next I tried the mv command and...
I have found the reason for the error (found it on a different forum). The error was due to the hashing algorithm used by ext4 which is enabled by "dir_index" parameter. There were too many hashing collisions for me so I disabled it by the following command: tune2fs -O "^dir_index" /dev/sdb3 The downside is that my p...
Moving millions of small files results in "out of space" error
1,334,477,754,000
I have some files on my laptop which I want to copy them on a remote cluster. To this end, I use PuTTy to SSH the remote cluster. Then to copy files, I use PuTTy terminal and after logging to the remote system, I write the below instruction, scp -r ~/Desktop/AFU/ username@host:~/SVM aiming copy all files in folder ...
The scp command you're trying to run is not only wrong, but won't work anyway because it presumes your laptop is running a SSH server. To do what you want, there's a much simpler way: use WinSCP on your laptop to connect to the remote cluster (it works similarly to PuTTY), then upload the files you want -- in your ca...
Copying files from my (windows) computer to a remote system over ssh [closed]
1,334,477,754,000
I have a folder with more than 30 sub directories and I want to get the list of the files which was modified after a specified date(say sep 8 which is the real case) and to be copied with the same tree structure with only the modified files in that folder I have say 30 dir from that I have the list of the files I nee...
Assuming you have your desired files in a text file, you could do something like while IFS= read -r file; do echo mkdir -p ${file%/*}; cp /source/"$file" /target/${file%/*}/${file##*/}; done < files.txt That will read each line of your list, extract the directory and the file name, create the directory an...
Clone directory tree structure and copy files to the corresponding directories modified after a specific date
1,334,477,754,000
cp --reflink=auto shows following output for MacOS: cp: illegal option -- - Is copy-on-write or deduplication supported for HFS? How can I COW huge files with HFS?
Apple's new APFS filesystem supports copy-on-write; CoW is automatically enabled in Finder copy operations where available, and when using cp -c on the command line. Unfortunately, cp -c is equivalent to cp --reflink=always (not auto), and will fail when copy-on-write is not possible with cp: somefile: clonefile faile...
cp --reflink=auto for MacOS X
1,334,477,754,000
I need to copy all files and directory from source let's say /var/www/html/test/ to destination /var/www/html/test2/. Destination can already have extra files and folders which i need to remove after copying the files from source. I cannot delete everything from destination before copying it. UPDATE I tried following...
#!/bin/bash SOURCE="/var/www/html/test/" DESTINATION="/var/www/html/test2/" cp -pRu "$SOURCE*" "$DESTINATION" HITSDIR=`find $DESTINATION -type d | sed -e 's|'$DESTINATION'\(.*\)|\1|g'` for i in $HITSDIR; do if [ -e $SOURCE$i ]; then echo Yes $SOURCE$i exists else echo Nope delete $DESTINATION$i. #rm -r $DESTINATIO...
Copy whole folder from source to destination and remove extra files or folder from destination
1,334,477,754,000
I want to copy a directory into another directory. For example, cp -r dir1 dir2 copies the contents of dir1 into dir2. I want to copy dir1 itself into dir2 so that if I ls dir2 it will output dir1 and not whatever was inside of dir1.
Just do as you did: cp -r dir1 dir2 and you will have dir1 (with its content as well) inside dir2. Try if you don't believe ;-). The command that would copy content of dir1 into dir2 is: cp -r dir1/* dir2
Copy directory not just the contents
1,334,477,754,000
I often need to move files between two Linux computers via USB. I use gparted to format the USB's. When I formatted the USB to use FAT32, the USB was unable to copy symlinks, so I had to recreate the symlinks on the other computer after copying the files. When I formatted the USB to use EXT3, I created a lost+found di...
What I do is to store tarballs on the USB drive (formatted as VFAT). I'm wary of reformatting USB drives, they are build/optimized for VFAT so to level wear, and I'm afraid it will die much sooner with other filesystems. Besides, formatting another way will make it useless for ThatOtherSystem...
What filesystem should be used when transferring files between Linux systems?
1,334,477,754,000
Is there a way to do this: "How can I copy a subset of files from a directory while preserving the folder structure?", but without using rsync? Is it possible to be done using only cp, find and grep? I have very limited bash shell (i.e. its a git shell under windows :( ), so rsync is not an option. I know I can get cy...
You can use tar or cpio or pax (if any of these is available) to copy certain files, creating target directories as necessary. With GNU tar, to copy all regular files called *.txt or README.* underneath the current directory to the same hierarchy under ../destination: find . -type f \( -name '*.txt' -o -name 'README.*...
How to copy only matching files, preserving subdirectories
1,334,477,754,000
How would it be possible to copy all new contents from one directory to another so that only new files are copied from the source directory (both directories have the same naming tree). For example, here is the layout of directory A: /dirA a.php b.txt subdirA1/ readme.txt co...
rsync was designed exactly to solve this problem: [$]> rsync -av --ignore-existing dirA/ dirB/
How to copy files from one directory to another so that only new files are copied? [duplicate]
1,334,477,754,000
I'm trying to write a Makefile to install the content of my folder into another on the system. I would like to keep the same directory structure, like this. localfolder ├── a └── b ├── c    └── d    ├── e       └── f I tried different options, but it does nothing $ install -d localfolder /...
For those who wants a solution, here you go: the install command doesn't work recursivly. So I wrote a shell script that does the trick. The first argument is the folder you want to copy, and the second is the target directory #!/bin/sh # Program to use the command install recursivly in a folder magic_func() { e...
Install the content of a folder into another
1,334,477,754,000
I have machine on which the files are uploaded by ftp. From this machine I would like to run cronjob and scp/rsync (simply copy them) to different machine in the same network. The problem is I don't want to copy files which are not coplete (still during transfer) Is there a possibility to check whether a file is comp...
You can use lsyncd: Lsyncd watches a local directory trees event monitor interface (inotify or fsevents). It aggregates and combines events for a few seconds and then spawns one (or more) process(es) to synchronize the changes. By default this is rsync. You can specify the time out after which a file has chang...
Operations only on complete files [duplicate]
1,334,477,754,000
I'd like to copy a firmware update file to my Canon 7D camera, connected via USB. After it was auto-mounted by thunar + thunar-volman + gvfs-gphoto2 I tried the following: $ cp eos7d-v205-win/7D000205.FIR /run/user/1000/gvfs/gphoto2\:host\=%5Busb%3A001%2C012%5D/ $ echo $? 0 $ ls /run/user/1000/gvfs/gphoto2\:host\=%5Bu...
I'm not sure you will like this answer, but, in my experience too, using PTP has always caused a high WTF/min. Presumably the camera itself restricts writing in the root folder, or something equally sensical. I would suggest getting your hands on a CompactFlash reader, mounting the filesystem directly, and using that ...
How to copy files *to* a camera?
1,334,477,754,000
Please excuse me if this is too basic and you're tempted to throw an RTFM at me. I want to prevent users from copying certain files while granting them read access to the same files. I thought this was impossible until I came across this example in the SELinux Wiki: allow firefox_t user_home_t : file { read write }; ...
I think it's important to note that the cat isn't the problem in my comment above, but shell redirection. Are you trying to restrict copying of binaries or text files? If it's binaries, then I believe you can work something out with rbash (see http://blog.bodhizazen.net/linux/how-to-restrict-access-with-rbash/). Howev...
SELinux: Can I disable copying of certain files?
1,334,477,754,000
I have two folders on two different servers. I want to sync files between A and B, however, I only want to copy files that don't already exist in folder B because these files are huge. I don't care about updating files. I simply wants a copy of each in folder B. How do I do this on Linux? (I suppose it'd be nice to ...
rsync is able to do this. rsync --ignore-existing <src> <dest> You can perform also various kinds of updates. Just have a look at the man page.
How do I only copy files to a remote folder on another server that don't already exist in the folder... from the command line in linux?
1,334,477,754,000
In a directory, I have hundreds of sub-directories. Each sub-directory has hundreds of jpg pictures. If the folder is called "ABC_DEF", the files inside the folder will be called "ABC_DEF-001.jpg", "ABC_DEF-002.jpg", so on and so forth. For example: ---Main Directory ------Sub-Directory ABC_DEF ----------ABC_DEF-001...
Why find when all files are in directories of the same depth? cd -- "$DIR" && cp -- */*-001.jpg /destination/path
Shell Script: Copy first file from multiple folders into one single folder
1,334,477,754,000
I am trying to copy a large folder structure between machines. I want to maintain the ownership/rights during the copy as it is not reasonable to 'fix' the privs afterwards. Therefore, I am using the following command to tar the file with privs intact and transfer the data to the destination machine. The same users ex...
As root, set up a named pipe: # mkfifo /tmp/fifo # chmod o+w /tmp/fifo Then, transfer your data as me: $ tar cfzp - foldertocopy | ssh me@machine "cat > /tmp/fifo" But read it as root: # tar -xfzp /tmp/fifo
Copying large tree from one machine to another, maintaining ownership
1,334,477,754,000
While manually copying the file the following works, as below: userx@x:~$ cp -rv /opt/test-bak/* /opt/test/ '/opt/test-bak/file1' -> '/opt/test/file1' '/opt/test-bak/file2' -> '/opt/test/file2' '/opt/test-bak/file3' -> '/opt/test/file3' '/opt/test-bak/subdir1/subfile1' -> '/opt/test/subdir1/subfile1' '/opt/test-bak/su...
When using filename globbing patterns on the command line, it's the shell that expands the globbing patterns to filenames that match them, creating a list of pathnames that is then passed on to the utility that you are calling (cp here). The command that you specify with ExecStart in your service file will not run in ...
systemd and copy (/bin/cp): no such file or directory
1,334,477,754,000
I have a very large video file on a USB external hard disk. It is about 13GB. I can play the video directly, and it seems there's no problem. But if I try to copy the file to other places, I got a strange error and the USB device is disconnected automatically, then connect back again. I tried copying from KDE, using c...
You could try your luck with ddrescue. It's usually used for whole disks or partitions, but it also works with single files. It keeps a logfile for retries. ddrescue /source/your_video.avi /target/your_copy.avi /target/your_copy.logfile If the disc vanishes in this process, just remount it and start the command again...
How to copy a very large video file with error in it?
1,334,477,754,000
I'm doing a file transfer using sftp. Using the get -r folder command, I'm surprised about the order that the program is downloading the content. It looks like it would be selecting the files it needs to download randomly. I can't believe that this is actually the case and I'm asking myself what's going on behind the ...
When you list the directory contents with the ls command, it will sort the listing into alphanumeric order according to current locale's sorting rules by default. It is easy to assume that this is the "natural order" of things within the filesystem - but this isn't true. Most filesystems don't sort their directories i...
In what order does sftp fetch files when using "get -r folder"?
1,334,477,754,000
I'm finding myself in a terminal more and more often these days as I learn to do certain types of things quicker or more conveniently. However, when it comes to copying a large amount of data (i.e. hundreds of gigabytes) from one HDD to another, I always revert to the GUI (Nautilus or Finder in my case; the file syste...
I don't really see a difference between copying many files and other tasks, usually what makes the command line more attractive is simple tasks which are trivial enough for you to do on the command line, so that using the GUI would be a waste of time (faster to type a few characters than click in menus, if you know w...
Terminal command vs. GUI drag & drop when copying large no. of files: Any tangible benefit?
1,334,477,754,000
I'm taking some early forays into setting up a basic LAMP box. It's my first time setting up the software I'll use as opposed to just being handed a working environment, so go easy on me :) I have installed Apache, and the corresponding htdocs folder has permissions of drwxr-xr-x. I can copy from remote to local fine,...
There are many ways to skin this cat. Here are some for you to consider: The htdocs tree almost certainly doesn't have to be owned by root. What matters is that it be readable by the Apache user. Depending on the *ix system in question, that may be apache, www-data, or something else. The default file mode you give a...
Permissions "problem" using SCP to copy to root owned folder from local
1,334,477,754,000
I have two servers (A and B) and my local machine. I'm trying to transfer a file from server A to server B. From server A: scp ./backup.tar [email protected]:/home/public/ Permission denied, please try again. Permission denied, please try again. Permission denied (publickey, password). lost connection From server B: ...
This looks like there is a problem with ssh configuration on the servers - you cannot ssh from any of them (probably for security reasons). You can try Stephane's suggestion to do the transfer from your local machine (scp [email protected]:/home/public/backup.tar [email protected]:/home/public/). This should out rule ...
"Permission denied, try again" while transferring files with scp
1,334,477,754,000
Every once in a while, I find the need to do: cp /really/long/path/to/file.txt /totally/different/long/path/to/copy.txt Since I use autojump, getting to the directories is very fast and easy. However, I'm at a loss when it comes to copying from one directory to the other without having to type out at least one of the...
The below works in bash. I haven't tried it in zsh. Try: echo ~- # Just to make sure you know what the "last directory" is Then: cp file.txt ~-/copy.txt Also see: More examples of use of ~- (and its interaction with pushd and popd) Is it possible to name a part of a command to reuse it in the same command later ...
How to cp in two steps
1,334,477,754,000
I use the following command to synchronize two folders : rsync -avhiu --progress --stats folder1/ folder2/ But unfortunately I have a bunch of file which differ only by their time stamps and rsync does the transfer of the whole file only to modify the time ... The man page of rsync says the following : sending onl...
The -W option is implied if you use rsync without copying to/from a remote system (i.e. only between two local folders): -W, --whole-file With this option rsync’s delta-transfer algorithm is not used and the whole file is sent as-is instead. The transfer may be faster if this option i...
rsync update only timestamp
1,334,477,754,000
Many times I find GNOME file copy GUI tool (Nautilus) irritating when it stops working. It happens when: I cancel the copy or move I try to copy to blue tooth exchange folder to my friends laptop(when he forgets to permit the operation or if the file is big) some other times, it just hangs while copying So I obvious...
As far as I know, there is no way to rescue Nautilus (file manager for GNOME) when it hangs. You are left only with the option of killing it, so go to the command line and run: killall nautilus After that, it should automatically restart, and then you can try again. This is just a bug in it. Try avoid parallel copyin...
How to quit GNOME file copy GUI after it hangs
1,334,477,754,000
For application specific reasons, I need to copy an entire parent directory into a subdirectory. E.g., cp -r ../ tmp/ The problem with this is that it gets stuck in an infinite loop, recursively copying the contents of tmp/ over and over again. There are a number of ways around this, like tarring the directory and un...
If you start from the parent directory, you can do this with find and GNU cp. Assuming the directory you're in currently (the one containing tmp) is called folder, and that tmp is empty, you'd run cd .. find . -path ./folder/tmp -prune -o -type f -exec cp --parents -t folder/tmp {} + This asks find to list everything...
Copying a Parent Directory into a Subdirectory Without an Infinite Loop
1,334,477,754,000
I'm trying to write a script to copy files recursively from a particular folder except files A.extn, B/*.extn and C/* where B and C are directories and extn is just some generic extension. This is what I have: #!/usr/local/bin/zsh setopt EXTENDED_GLOB TMPDIR=/tmp/test cp -pR $(dirname $0)/**~(*.foo/*|*/bar.txt|*.abc|...
You are correct that the pattern is expanded before cp is run, so is unknown to that command. You may be able to accomplish what you want by using the --parents option to cp rather than -R. That will only copy the files which match your pattern, but will use the full path name as supplied rather than only the trailin...
Modifying zsh globbing patterns to use with cp
1,334,477,754,000
If I have input folder files_input that has subfilders like 01-2015, 02-2015, 03-2015 etc and all these subfolders have other subfolders. Each subfolder has only one file called index.html. How can I copy all these index.html files into one folder called files_output so that they end up like separate files in the sam...
As you're a zsh user: $ tree files_input files_input |-- 01_2015 | |-- subfolder-1 | | `-- index.html | |-- subfolder-2 | | `-- index.html | |-- subfolder-3 | | `-- index.html | |-- subfolder-4 | | `-- index.html | `-- subfolder-5 | `-- index.html |-- 02_2015 | |-- subfolder-1 | | ...
Recursive copy files with rename
1,334,477,754,000
I have few big folders "cosmo_sim_9", "cosmo_sim_10".... in one of my external hard disk, and a old copy of this on another external hard disk. I want to Synchronize old directories with the new one(recursively), but without overwriting already existing files(for saving time). How can I do this? My os is Fedora 20.
use rsync: rsync -a --ignore-existing cosmo_sim_9 /dest/disk/cosmo_sim_9 --ignore-existing will cause it to skip existing files on the destination, -a will make it recursive, preserving if possible permission/ownership/group/timestamp/links/special devices. you can do it for all directories by using a bash for loop: ...
How To Synchronize Directories in two different external hard disks?
1,334,477,754,000
I am new to these commands. I am trying to gzip a local folder and unzip the same on the remote server. The thing is, gzipping and unzip must happen on the fly. I tried many and one of the closest I believe is this: tar cf dist.tar ~/Documents/projects/myproject/dist/ | ssh [email protected]:~/public_html/ "tar zx ~/D...
If you have rsync then use that instead, as it makes use of existing files to allow it to transfer only differences (that is, parts of files that are different): rsync -az ~/Documents/projects/myproject/dist/ [email protected]:public_html/ Add the --delete flag to to completely overwrite the target directory tree eac...
gzip compress a local folder and extract it to remote server
1,336,040,124,000
I have this situation $ ls -la -rw-r--r-- 1 user user 123 Mar 5 19:32 file-a -rwx---rwx 1 user user 987 Mar 5 19:32 file-b I would like to overwrite file-b with file-a but I would like to preserver all permissions and ownership of file-b. This does not work, because it uses permissions of file-a cp file-a file-b # ...
A simple command to copy a file without copying the mode is dd if=file-a of=file-b but then you get dd’s verbose status message written to stderr.  You can suppress that by running the command in a shell and adding 2> /dev/null, but then you’re back to square 1.  If you have GNU dd, you can do dd if=file-a of=file-b ...
Overwrite file preserving target permissions without shell invocation
1,336,040,124,000
I have a folder like this: ./folder-a/index.html ./folder-b/index.html ./folder-c/subdir/index.html ./new-content/folder-a/index.html ./new-content/folder-b/index.html ./new-content/folder-c/subdir/index.html The new-content folder contains an on-going updated stuff that I update. When I want to update my content I a...
From man cp (the GNU version, found on Linux and Cygwin) --backup[=CONTROL] make a backup of each existing destination file -b like --backup but does not accept an argument Example touch 1 2 cp -bv 2 1 ‘2’ -> ‘1’ (backup: ‘1~’) Note that this does not check for existing backup files, i.e. if 1~ exists it will b...
How to backup all the files that I'm copying before being overwritten?
1,336,040,124,000
Here's the problem I'm attempting to solve: Let's say I have a directory "A", containing some files as well as some other directories. I want to copy all the files directly under directory A to directory B. I want to recursively copy all the folders inside folder A to folder C. What is the shortest and less platfo...
Probably something like this find A -type f -maxdepth 1 -exec cp {} B/ \; And find A -type d -maxdepth 1 -mindepth 1 -exec cp -r {} C/ \; Where -type is a flag, determining the type you're looking for (file or directory), - maxdepth how deep into directory, and -exec for executing a command on the result.
Copying files based on a condition