Sample Header Ad - 728x90

Unix & Linux Stack Exchange

Q&A for users of Linux, FreeBSD and other Unix-like operating systems

Latest Questions

1 votes
0 answers
748 views
Using server-side copy on a SMB share
According to the [SMB docs][1] server-side copy should work on recent versions of SMB via `cp --reflink` When trying this with a server running smbd 4.15 (via [crazy-max/docker-samba][2]) and a share mounted with `mount -t cifs -o uid=1000,gid=1000,vers=3.1.1 //host/share/ /share`, I always get `Ope...
According to the SMB docs server-side copy should work on recent versions of SMB via cp --reflink When trying this with a server running smbd 4.15 (via crazy-max/docker-samba ) and a share mounted with mount -t cifs -o uid=1000,gid=1000,vers=3.1.1 //host/share/ /share, I always get Operation not supported for cp --reflink /share/test /share/test2. The versions on the client machine are:
~$ mount.cifs --version
mount.cifs version: 6.9
~$ uname -r
5.4.0-125-generic
Why is it not working? Any ideas? Thanks!
frsc (111 rep)
Aug 30, 2022, 02:17 PM • Last activity: Jun 16, 2025, 03:30 PM
352 votes
18 answers
608949 views
Is it possible to see cp speed and percent copied?
I'm having problems when copying large files using nautilus (it gets stuck). I need to copy, using `cp`. I would like to know if there are any parameters that shows the % copied and also the transfer speed.
I'm having problems when copying large files using nautilus (it gets stuck). I need to copy, using cp. I would like to know if there are any parameters that shows the % copied and also the transfer speed.
user27807
Feb 17, 2013, 01:23 PM • Last activity: Apr 2, 2025, 02:21 PM
565 votes
6 answers
2655694 views
How to copy a file from a remote server to a local machine?
In my terminal shell, I ssh'ed into a remote server, and I `cd` to the directory I want. Now in this directory, there is a file called `table` that I want to copy to my local machine `/home/me/Desktop`. How can I do this? I tried `scp table /home/me/Desktop` but it gave an error about no such file o...
In my terminal shell, I ssh'ed into a remote server, and I cd to the directory I want. Now in this directory, there is a file called table that I want to copy to my local machine /home/me/Desktop. How can I do this? I tried scp table /home/me/Desktop but it gave an error about no such file or directory. Does anyone know how to do this?
omega (6147 rep)
Mar 5, 2015, 02:30 AM • Last activity: Apr 2, 2025, 11:34 AM
0 votes
2 answers
489 views
Cron to find exec cp and redirect output with time / date per line?
I try to setup a `cron` task to run a set of basic shell commands. I need to look to any files created on the last day, then copy to another folder and generate a log stating, line by line, the date and the time of the file copy operation. The two shell commands run separately but need to create one...
I try to setup a cron task to run a set of basic shell commands. I need to look to any files created on the last day, then copy to another folder and generate a log stating, line by line, the date and the time of the file copy operation. The two shell commands run separately but need to create one and schedule via cron. When I try to increase the first command (find) cron does not execute the task and gives errors. If I run manually, it works. find /dir/ -type f -mtime -1 -exec cp -v -a --parents "{}" /dir2/ \; >> /dir2/LogsCopiaDBs_$(date +%d-%m-%Y).txt exec &> >(while read line; do echo "$(date +'%h %d %Hh%Mm%Ss') $line" >> /dir2/LogsCopiaDBs.txt; done;) Any idea ?
Edson S Freitas (1 rep)
Nov 13, 2015, 02:25 PM • Last activity: Mar 17, 2025, 07:28 AM
3 votes
1 answers
187 views
exec cp failes from script, yet works when issued directly
I have a script that copies SQL backups to a windows server. Here's the line from /etc/fstab: //my.win.box/share$ /winshare cifs credentials=/etc/credfile,dom=mydomain,uid=0,gid=0,file_mode=0600,dir_mode=0700 0 0 Here's the backup script: backup.sh: # copy zipped sql exports to /winshare/db find /ba...
I have a script that copies SQL backups to a windows server. Here's the line from /etc/fstab: //my.win.box/share$ /winshare cifs credentials=/etc/credfile,dom=mydomain,uid=0,gid=0,file_mode=0600,dir_mode=0700 0 0 Here's the backup script: backup.sh: # copy zipped sql exports to /winshare/db find /backups/sql/*sql.gz -mtime +1 -exec cp {} /winshare/db \; Logged in with root privileges (in this case, as root) $ ./backup.sh cp: cannot create regular file `/winshare/db/mydb_20130301.sql.gz': Permission denied Yet if I issue the command from a prompt, rather than through the script: $ find /backups/sql/*sql.gz -mtime +1 -exec cp {} /winshare/db \; The file(s) are copied as expected. Again, logged in as root here. What could be causing the in-script command to fail, yet the identical command to work from console?
a coder (3343 rep)
Apr 23, 2013, 07:55 PM • Last activity: Mar 14, 2025, 03:38 PM
1 votes
3 answers
73 views
Duplicate and rename files with matching names but different extensions in bash?
Is there some *simple* way to duplicate both `.cpp` and `.h` files (or any multitude of extensions) simultaneously in `bash`, instead of: ```sh cp foo.cpp bar.cpp cp foo.h bar.h ``` I'm not looking for shell script answers or complicated `find` syntax or anything like that; I'm just wondering if the...
Is there some *simple* way to duplicate both .cpp and .h files (or any multitude of extensions) simultaneously in bash, instead of:
cp foo.cpp bar.cpp
cp foo.h bar.h
I'm not looking for shell script answers or complicated find syntax or anything like that; I'm just wondering if there's something maybe built into bash that does this in a simple way.
BrandonL (180 rep)
Feb 27, 2025, 05:46 PM • Last activity: Mar 8, 2025, 08:53 AM
6 votes
1 answers
619 views
tar not preserving symlinks
How to create an archive containing links and the linked files. I have some shared libraries of which I want to create an archive. This is what I tried mkdir dest #abc.so is a link file which points to abc.so.1 #abc.so.1 is a link file which points to abc.so.1.1 #abc.so.1.1 is the actual file cp /us...
How to create an archive containing links and the linked files. I have some shared libraries of which I want to create an archive. This is what I tried mkdir dest #abc.so is a link file which points to abc.so.1 #abc.so.1 is a link file which points to abc.so.1.1 #abc.so.1.1 is the actual file cp /usr/local/lib/abc.so* dest/ tar -czvf dest.tar.gz -C dest/ . But the resulting dest.tar.gz file lists links and linked files with same size and no l file type for links in the output of tar -tvf dest.tar.gz.
Harry (165 rep)
Mar 3, 2025, 10:08 AM • Last activity: Mar 3, 2025, 12:11 PM
4 votes
2 answers
7347 views
What precisely does cp -b (--backup) actually do?
Before you hit me with the obvious, I know, the backup option makes a backup of a file. But the thing is, the `cp` command in general backs up a file. One could argue a copy of a file is a backup. So more precisely, my question is this: what does the `-b` option do that the `cp` command doesn't do a...
Before you hit me with the obvious, I know, the backup option makes a backup of a file. But the thing is, the cp command in general backs up a file. One could argue a copy of a file is a backup. So more precisely, my question is this: what does the -b option do that the cp command doesn't do already? The cp(1) man page gives the following description of the --backup option: > make a backup of each existing destination file This definition isn't very useful, basically saying "the backup option makes a backup". This gives no indication as to what -b adds to the cp I know -b puts some suffix at the end of the name of the new file. But is there anything else it does? Or is that it? Is a -b backup just a cp command that adds something to the end of the filename? P.S. Do you typically use -b when making backups in your daily work? Or do you just stick to -a?
backslash enn (43 rep)
Feb 1, 2023, 05:44 PM • Last activity: Mar 1, 2025, 02:51 PM
4 votes
2 answers
10276 views
cp options --no-clobber vs. --update
I want to copy a single file if (and only if) the destination does not exist. The source file changes rarely, maybe once a month. The destination almost never exists. Are there any differences between the `-n` and `-u` options? (Or both!) `cp` is being called directly from `crond`. No other`cp` opti...
I want to copy a single file if (and only if) the destination does not exist. The source file changes rarely, maybe once a month. The destination almost never exists. Are there any differences between the -n and -u options? (Or both!) cp is being called directly from crond. No othercp options are used. The same cron job is called on several machines at the same time, reading from the same source and writing to the same destination (both on a shared GFS global file system). The destination file will be moved shortly thereafter by another process, so the only time it could exist is during the race when the cron job executes simultaneously on several nodes. Which would be more efficient? : * cp -n source dest * cp -u source dest * cp -nu source dest * cp -pu source dest I'm currently leaning towards the simple -n alternative.
MattBianco (3806 rep)
May 4, 2015, 11:14 AM • Last activity: Feb 22, 2025, 08:18 AM
0 votes
1 answers
145 views
why doesn't cp automatically copy directories recursively?
Why does `cp` need `-r` flag to copy "recursively"? Why doesn't `cp` automatically copy directories recursively? Would that make more sense? Is there some documentation that explains this decision? Why do I have to add this flag for `cp` to do what it should do by default?
Why does cp need -r flag to copy "recursively"? Why doesn't cp automatically copy directories recursively? Would that make more sense? Is there some documentation that explains this decision? Why do I have to add this flag for cp to do what it should do by default?
how to bash (9 rep)
Feb 11, 2025, 02:55 PM • Last activity: Feb 21, 2025, 04:18 PM
4 votes
1 answers
5962 views
How rsync decides which files needs to be updated?
Right now I have these commands: my_dir="$HOME/foo/bar"; rm -rf "$my_dir/WebstormProjects/"; rsync -r --exclude=".git" --exclude="node_modules" "$HOME/WebstormProjects/" "$my_dir/WebstormProjects/" instead of removing everything in `"$my_dir/WebstormProjects/"` and then copying over, I am looking to...
Right now I have these commands: my_dir="$HOME/foo/bar"; rm -rf "$my_dir/WebstormProjects/"; rsync -r --exclude=".git" --exclude="node_modules" "$HOME/WebstormProjects/" "$my_dir/WebstormProjects/" instead of removing everything in "$my_dir/WebstormProjects/" and then copying over, I am looking to use rsync such that it will only overwrite files in "$my_dir/WebstormProjects/" if the files in "$HOME/WebstormProjects/" are newer. So something like this: my_dir="$HOME/foo/bar"; rsync -r --newer --exclude=".git" --exclude="node_modules" "$HOME/WebstormProjects/" "$my_dir/WebstormProjects/" **is it possible to copy files only if they are newer than the destination files?** I did some reading: https://www.tecmint.com/sync-new-changed-modified-files-rsync-linux/ it says: > By default, rsync only copies new or changed files from a source to > destination... I assume it does this by comparing relative file paths? Files with the same path/name are considered to be the same?
Alexander Mills (10734 rep)
Aug 13, 2018, 10:35 PM • Last activity: Feb 4, 2025, 11:53 AM
1 votes
3 answers
2613 views
What is the equivalent to "cp --backup=numbered" in alpine linux?
I'm porting a script from ubuntu to alpine linux 3.4 (docker image). I can't seem to find a way to do "cp --backup=numbered" in alpine. Is there any way to install a more complete "cp"? Thanks
I'm porting a script from ubuntu to alpine linux 3.4 (docker image). I can't seem to find a way to do "cp --backup=numbered" in alpine. Is there any way to install a more complete "cp"? Thanks
JoaoCC (771 rep)
Dec 12, 2016, 07:36 PM • Last activity: Jan 29, 2025, 08:46 AM
6 votes
4 answers
792 views
Copy the n-largest files from a certain directory to the current one
I am trying to copy five largest files from a certain directory to my `pwd`. Using `cp specific/directory$(ls -S specific/directory | head -n) ./` copies the first file and then proceeds to produce `cannot stat` errors for the rest of the files in the list. Why is the pipe working for the first item...
I am trying to copy five largest files from a certain directory to my pwd. Using cp specific/directory$(ls -S specific/directory | head -n) ./ copies the first file and then proceeds to produce cannot stat errors for the rest of the files in the list. Why is the pipe working for the first item and failing for the rest?
Sudoh (297 rep)
May 1, 2023, 05:31 PM • Last activity: Jan 26, 2025, 05:13 PM
21 votes
2 answers
42478 views
How to view progress with sshpass and scp in linux?
In my Linux terminal, I am using this command sshpass -p "pass" scp -r me8@host.ca:/cmshome/me/file /home/me/Desktop to download a file with a password in it. Without the sshpass, I can see the download progress, but with it, it is just blank until it finishes and I can't see it. Is there a way I ca...
In my Linux terminal, I am using this command sshpass -p "pass" scp -r me8@host.ca:/cmshome/me/file /home/me/Desktop to download a file with a password in it. Without the sshpass, I can see the download progress, but with it, it is just blank until it finishes and I can't see it. Is there a way I can see it with sshpass?
omega (6147 rep)
Mar 5, 2015, 03:17 AM • Last activity: Jan 25, 2025, 07:52 AM
5 votes
4 answers
1318 views
I want to copy files that do not have a number in their name
[![These are all the files][1]][1] [1]: https://i.sstatic.net/Z4sKB.png I want to use cp command using file globing to copy all those files that do not have a numeric value. The copied files should not include 12a, ghf3 and s2d. I tried using `cp [!0-9] *[!0-9] *[!0-9] destination/`
These are all the files I want to use cp command using file globing to copy all those files that do not have a numeric value. The copied files should not include 12a, ghf3 and s2d. I tried using cp [!0-9] *[!0-9] *[!0-9] destination/
Raghav Arora (51 rep)
Jun 16, 2023, 08:40 AM • Last activity: Jan 5, 2025, 11:56 AM
1 votes
1 answers
2281 views
Sync two Directories without rsync
I know what you are thinking right now "**Just use rsync**" but unfortunately this system does not have rsync, and I would like to come up with another solution. **The Setup**: 1. The source Server has a Upload folder containing 140 000+ Files *(No Sub Directories)* 2. The destination Server needs t...
I know what you are thinking right now "**Just use rsync**" but unfortunately this system does not have rsync, and I would like to come up with another solution. **The Setup**: 1. The source Server has a Upload folder containing 140 000+ Files *(No Sub Directories)* 2. The destination Server needs the Upload folder containing 140 000+ Files Let's call it Migrating with only Post-It Notes... Now to complicate matters, Server 1 keeps getting new files every day, due to new Uploads or Thumbnails being generated, so that idea in your head right now "**just copy the file from 1 to 2**" will not work, as once I am done with the Copy of about 20+GB I can start again, as there is already new file on the source Server... **My Solution Idea** - Copy the complete folder from source to destination - Find the latest create date in the destination Server and use as starting point on the source Server - Copy all files since the last create date from the source to the destination (delta) - Setup a cron to do this as often as possible. **My Problem** `find /uploads/* -mtime -1 bash: /bin/find: Argument list too long ` Now before I start writing a bash script loop , I was wondering if there is someone out there that could suggest another way of doing this without a bash script... good old low level CLI.
Adesso (155 rep)
Aug 31, 2016, 11:35 AM • Last activity: Dec 20, 2024, 11:03 AM
4 votes
4 answers
14742 views
Move or copy without overwrite and check success
**Problem:** I'm looking for a way to rename or copy a file without overwriting the destination file, if it exists, and then check the success of the move or copy operation. I'm seeking a method that will work with the BSD versions of mv/cp installed on MacOS/Unix, and also the GNU coreutils version...
**Problem:** I'm looking for a way to rename or copy a file without overwriting the destination file, if it exists, and then check the success of the move or copy operation. I'm seeking a method that will work with the BSD versions of mv/cp installed on MacOS/Unix, and also the GNU coreutils versions I have on Linux. **Solution attempt:** In all versions of mv/cp, I can prevent overwriting the destination file with the -n flag: mv -n file1 file2 cp -n file1 file2 Similar questions suggest testing the success of mv and cp using the exit status, which is 0 if successful and >0 if an error occurred. However, for both versions of mv/cp, the exit code is 0 when the destination file already exists and the -n flag is used. The only other option I can think of is to also use the -v flag, and look at the output of the command: mv -nv file1 file2 cp -nv file1 file2 However, the GNU and BSD versions of mv/cp behave differently when the -nv flags are used and file2 already exists: the GNU versions of mv/cp return nothing, whereas the BSD versions return file2 not overwritten. Our previous method was to check whether the destination file exists first, then do the mv/cp operation. Believe it or not, this caused problems because the destination file would sometimes get created by another process between the time that the check was performed and the mv/cp operation was executed. Is there a way to accomplish this task that works with both BSD and GNU versions of mv/cp? Alternatively, is there are way to do this using Python 2? I couldn't find a way to do this using os.rename()
srcerer (141 rep)
Jan 25, 2019, 06:46 PM • Last activity: Nov 25, 2024, 01:26 AM
2 votes
1 answers
132 views
cp 'same file' error when using -L with find and xarg
I'm trying to replace symlinks in my current directory with the files they point to. I thought I understood 'cp' and the '-L' argument, but apparently not. Here's the command I am using find ./ -maxdepth 1 -type l -regex ".*\(pdf\|odp\)" | xargs readlink -f | xargs cp -Lf -t . Here's the error I get...
I'm trying to replace symlinks in my current directory with the files they point to. I thought I understood 'cp' and the '-L' argument, but apparently not. Here's the command I am using find ./ -maxdepth 1 -type l -regex ".*\(pdf\|odp\)" | xargs readlink -f | xargs cp -Lf -t . Here's the error I get cp: '/home/user/dir1/dir2/dir3/file.pdf' and './file.pdf' are the same file What am I missing
mikemtnbikes (241 rep)
Oct 16, 2024, 06:09 PM • Last activity: Oct 17, 2024, 09:06 AM
0 votes
1 answers
68 views
Linux - Copying files from multiple nested folders, with same file names to a single folder
I need help copying a large bunch of files. Let me try to explain the problem here **SOURCE STRUCTURE** is in /home/user/ToddCrimson/Pictures/iPhone-Media/ (It has JPGs, PNGs, MOVs etc, so I will need a script which first moves JPGs, then I change the lookup to MOVs and change the destination folder...
I need help copying a large bunch of files. Let me try to explain the problem here **SOURCE STRUCTURE** is in /home/user/ToddCrimson/Pictures/iPhone-Media/ (It has JPGs, PNGs, MOVs etc, so I will need a script which first moves JPGs, then I change the lookup to MOVs and change the destination folder) 100APPLE IMG_0001.JPG - TimeStamp-A IMG_0002.jpg - TimeStamp-B IMG_0003.jpg - TimeStamp-C IMG_0004.MOV - TimeStamp-G 101APPLE IMG_0001.jpg - TimeStamp-D IMG_0002.jpg - TimeStamp-E IMG_0003.jpg - TimeStamp-F IMG_0004.MOV - TimeStamp-H 102APPLE IMG_0001.jpg - TimeStamp-X IMG_0002.jpg - TimeStamp-Y IMG_0003.jpg - TimeStamp-Z IMG_0004.MOV - TimeStamp-I xxxAPPLE **DESTINATION STRUCTURE** is in /home/user/ToddCrimson/Pictures/ (I'd run the script each for JPG, for PNG, for MOV etc etc, but preserving the original timestamps) All_JPG Pic-00000001.jpg - TimeStamp-A Pic-00000002.jpg - TimeStamp-B Pic-00000003.jpg - TimeStamp-C Pic-00000004.jpg - TimeStamp-D Pic-00000005.jpg - TimeStamp-E Pic-00000006.jpg - TimeStamp-F - - - - Pic-21897563.jpg - TimeStamp-Z All_MOV Mov-00000001.MOV - TimeStamp-G Mov-00000002.MOV - TimeStamp-H - - - Mov-32188462.MOV - TimeStamp-XX I've tried various combinations of RSYNC and CP, but seemingly keep failing. Any help with an **exact command** that I can run? I'd like to Copy all thousands of JPGs. Have them all sequential names, or atleast unique names, but must preserve the original timestamp. I'm on Debian 12. Can do it over Terminal or if a GUI program exists?
Todd Crimson (1 rep)
Oct 7, 2024, 05:05 PM • Last activity: Oct 7, 2024, 07:05 PM
44 votes
3 answers
186095 views
How to copy directories via ssh
I am connected with `ssh` and I want to copy a directory from my *local* to our *remote* server; how can I do that? I have read several post using `scp` but that doesn't worked for me. Some posts suggested using `rsync` but in my case I just want to copy one directory.
I am connected with ssh and I want to copy a directory from my *local* to our *remote* server; how can I do that? I have read several post using scp but that doesn't worked for me. Some posts suggested using rsync but in my case I just want to copy one directory.
hrk (443 rep)
Jul 2, 2017, 05:18 PM • Last activity: Sep 29, 2024, 05:22 AM
Showing page 1 of 20 total questions