0

I have a .txt file that has a list of folders I would like to move from one directory to another. I have seen many posts on this, but none have worked. Mostly because those are using GNU versions of mv and xargs. I found this post that is doing what I want but only in Linux. Currently, we are using the latest version of TrueNAS Core which is running FreeBSD version 12.2-RELEASE-p3

I tried using the code below, the folder names in the file have letters, numbers, spaces, (, and ):

while IFS= read -r file; do 
    mv Projects/"$file" Archives/PROJECT\ ARCHIVE\ 2020; 
done < Projects/Archive_List_test.txt

It gives me this output:

 to Archives/PROJECT ARCHIVE 2020/folder1: No such file or directory
: No such file or directoryE 2020/folder2

folder1 and folder2 are the folder names that are in the list. For my test, I only have 2 folders, but I actually need to move over about 360 folders

Thank you for your time.

5
  • that overlap between the error message and filename indicates a carriage-return issue, see e.g. : unix.stackexchange.com/q/134695/170373 and askubuntu.com/questions/372672/… Commented Apr 2, 2021 at 16:07
  • Try quotes around "Archives/PROJECT\ ARCHIVE\ 2020" - notice you're not trying a drectory name "E", i.e,. one the "E" in on the filenames is creating the error "directoryE". Commented Apr 2, 2021 at 18:52
  • @CinaedSimson It looks like it gives me the same error. Commented Apr 2, 2021 at 19:57
  • Okay, but you shouldn't put a slash and qutes. Where is the "read" command coming from? And are you sure the errors aren't coming from the "Projects/Archive_List_test.txt"? Commented Apr 2, 2021 at 21:27
  • Note that on Unix, BSD--and Linux, too--they are "directories" and not the Windows concept of "folders" which is not the same thing. Commented Apr 3, 2021 at 11:01

1 Answer 1

0

The script below seems to be working as expected. Let's test the folders below

admin@truenas:~/tmp $ ls -la
total 32
drwxr-xr-x  4 admin  admin    6 Apr  2 14:15 .
drwxr-xr-x  4 admin  admin   12 Apr  2 14:06 ..
-rw-r--r--  1 admin  admin   16 Apr  2 14:18 Archive_List_test.txt
drwxr-xr-x  3 admin  admin    3 Apr  2 14:07 Archives
drwxr-xr-x  4 admin  admin    4 Apr  2 14:19 Projects
-rwxr-xr-x  1 admin  admin  130 Apr  2 14:17 script.sh
admin@truenas:~/tmp $ ls -la Archives/PROJECT\ ARCHIVE\ 2020 
total 1
drwxr-xr-x  2 admin  admin  2 Apr  2 14:15 .
drwxr-xr-x  3 admin  admin  3 Apr  2 14:07 ..
admin@truenas:~/tmp $ ls -la Projects/
total 14
drwxr-xr-x  4 admin  admin  4 Apr  2 14:19 .
drwxr-xr-x  4 admin  admin  6 Apr  2 14:15 ..
drwxr-xr-x  2 admin  admin  2 Apr  2 14:19 folder 1
drwxr-xr-x  2 admin  admin  2 Apr  2 14:19 folder 2
admin@truenas:~/tmp $ cat Archive_List_test.txt 
folder 1
folder 2

This script moves the folders, listed in file Archive_List_test.txt, from the directory Projects/ to the directory Archives/PROJECT\ ARCHIVE\ 2020/

admin@truenas:~/tmp $ cat script.sh 
#!/bin/sh
while IFS= read -r file; do 
    mv "Projects/${file}" Archives/PROJECT\ ARCHIVE\ 2020/; 
done <Archive_List_test.txt
admin@truenas:~/tmp $ ./script.sh 
admin@truenas:~/tmp $ ls -la Projects/
total 13
drwxr-xr-x  2 admin  admin  2 Apr  2 14:30 .
drwxr-xr-x  4 admin  admin  6 Apr  2 14:15 ..
admin@truenas:~/tmp $ ls -la Archives/PROJECT\ ARCHIVE\ 2020 
total 2
drwxr-xr-x  4 admin  admin  4 Apr  2 14:30 .
drwxr-xr-x  3 admin  admin  3 Apr  2 14:07 ..
drwxr-xr-x  2 admin  admin  2 Apr  2 14:19 folder 1
drwxr-xr-x  2 admin  admin  2 Apr  2 14:19 folder 2
3
  • Thank you for responding! When I test out what you have I get the same error. Could it be because instead of folder1 and 2 it is actually like 13 folder test 1 and 14 folder (test) 2. Could those spaces be what is making it not be able to find the correct folders? Commented Apr 2, 2021 at 21:44
  • You're welcome! Quote the source, e.g. "Projects/${file}". I've updated the answer. Commented Apr 2, 2021 at 21:52
  • unfortunately, it is not working for me. When I cat my Archive_List_test.txt file, at the end of it I am getting a random #. That is not in my file with the list of folders. Might I need to strip off some special characters or something? Commented Apr 2, 2021 at 22:18

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.