this post was submitted on 20 Feb 2024
-1 points (46.2% liked)
Linux
2347 readers
12 users here now
Shit, just linux.
Use this community for anything related to linux for now, if it gets too huge maybe there will be some sort of meme/gaming/shitpost spinoff. Currently though… go nuts
founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
When I run into situations like this, I use the commands that work to write out a script. Eg, in your case the wildcard isn't working with the mv command, so do something like this:
ls -1 *.jpg | awk '{print "mv ""$1"" /mnt/example/Pictures"}' > /tmp/movefiles.sh
Then check the movefiles.sh and make sure it has all of the commands and files properly stated, make that executable, and then run that.
ls | grep | mv
would work, except the StackOverflow discussion also highlights how parsing ls can have the same issues.I am moving thousands of files at once. If I have to check each one, it's still wrong.
The pragmatic answer turns out to be
./*
instead of*
.I saw that answer and was just offering another option. I am sure xargs might work, but you would need to test as you need a destination passed on each line. Back to my way, I have used it for a lot more than just the move command. I think I used it to do a chmod once where I wanted to check and make sure before I committed to actually running the command(s). You could also use find and the -exec option, which I think was also mentioned here.
Edit: also, you wouldn't need to check each one, just the first few and last few to make sure the syntax is correct. Maybe do a wc -l to make sure it's got the right number of entries and then let it run.