Is there an scp variant of mv command? [closed] - linux

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I am writing a script that will move files from a local system to a remote system. It must do so through an encrypted channel like ssh. What is the best way to do this? I can perform this in two steps like:
scp *.jpg user#ip:
rm *.jpg
But, that is not an atomic process (like mv is for a local filesystem). If the copy fails I will no longer have the local copies either. How can I script this to make sure the local files only get removed if the copy succeeds?

You could use rsync with --remove-source-files:
rsync -avz --remove-source-files /local/dir/*.jpg user#ip:/remote/dir

An other solution, for launch in one time
scp /path/src/*.jpg user#host:/path/dst/ && rm /path/src/*.jpg

Related

Copy files into Folders based on Year [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 3 years ago.
Improve this question
I need to be able to copy photos from a source folder into year folders based on the modification date of the file.
I am looking for a bash script on linux to do this
rsync wil not help you. You need bash and some linux commands:
Bash script:
file=myimage.jpeg
modtime=$(stat --printf=%Y $file)
year=$(date -d #$modtime +%Y)
mkdir -p "$year"
cp "$file" "$year"
Remarks
Rsync is good to copy files but not for the sorting task
The above example uses file modification time because file creation time is not available on some file systems
If you want to do the above for multiple files, use a bash for loop

how to deal with file without a name in linux? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 6 years ago.
Improve this question
I'm a green hand to linux using the vmware called Parallels on my mac and the edition I use is CentOS7.When I use the ls -al command, I found some files don't have name as follow in surprise:
I just want to know as these files are seemingly generated at a same time, what are they? how to delete them?
On *nix system every file has an atrribute called i-node. You can find with command
ls -i
when you have i=node number you can delete file by
find . -inum 782263 -exec rm -i {} \;
You could use any other commands not only rm.
more details you can find here
http://www.cyberciti.biz/tips/delete-remove-files-with-inode-number.html
As the d in drwxr-xr-x states, those are folders (or at least the filesystem thinks they are). You may use Midnight Commander to delete them. You may already have it installed on your machine, try to run mc to see if it's there.

What is the easiest way to create a script that runs on the next reboot only? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
I am looking to create a script that executes on the next reboot only (not each reboot).
For example, I have script test.sh:
cd /tmp
touch toto.txt
What is the easiest way to execute this script only on the next reboot?
By easiest I mean : minimal number of commands, and independent of the linux OS/Version (if possible).
After several searches I found I can use the init.d system. But I think that's not the best way, because my script must run only once.
Add something like
LOCKFILE=/var/lock/test_sh_done
if [ ! -f ${LOCKFILE} ]; then
touch ${LOCKFILE}
/path/to/test.sh
fi
to /etc/rc.local, and make sure that /etc/rc.local has the execute bit set. If you want to run it again at the next reboot, just delete the LOCKFILE.

Is it possible to create more than one directory on a same command? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I took an examination last week and there was a question asking to create three directories by using one command ; then there was a question asking to delete those directories on a same command. Is that possible ?
You should read man mkdir and man rm
mkdir -pv myfolder/{a..z}/{1..10}
creates 261 folders (myfolder/a/1, myfolder/a/2.... myfolder/z/10)
rm -rf myfolder/
removes them all
Yes this is possible.
Check here and here
Removing directories in one command is also possible. Check here

Replace all files except one with rsync [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
I'm currently using rsync as follows
rsync -az --delete ...
What option can I use with rsync to replace all destination files that already exist except for one specific file that should not be replaced if already exists? Sure, if the file doesn't exist at the destination, it should be put there.
I don't know whether it is possible in one invocation, but you could call rsync twice:
rsync ... --ignore-existing file dest
Now the file is put there if it didn't exist before.
rsync ... --exclude file src dest
Now all the other files are handled as usual, except for the one excluded file.

Resources