a combination of the two answers above might work.
step 1.
find oldLocation -type f -exec mv {} newLocation \; #find and copy all files.
step 2.
rm -frv oldLocation
You might want to reword your questions, it's not very clear what the behavior you want is.
This is a typical use case for shell globbing (pathname expansion):
/home/user012/Desktop/folder2Start/*/
Here i have used */
which will match any file (*
) under /home/user012/Desktop/folder2Start/
, that is a directory (trailing /
).
If you want to operate on these later, better put the result of expansion in an array (works in a similar manner to Python list
, both are 0-indexed too):
directories=( /home/user012/Desktop/folder2Start/*/ )
then you can reference the array and it's elements using usual array manipulation operators.
OTOH, if you want the list, use echo
/printf
/ls
-- whatever suits you the best:
printf '%s\n' /home/user012/Desktop/folder2Start/*/
echo /home/user012/Desktop/folder2Start/*/
ls -ld /home/user012/Desktop/folder2Start/*/
for any directory name with embedded newline, lookout for tailing /
as name ending marker.
Best Answer
You can do this on command line, using the -R switch (recursive) and then piping the output to a file thus:
this will make a file called filename1 in the current directory, containing a full directory listing of the current directory and all of the sub-directories under it.
You can list directories other than the current one by specifying the full path eg:
will list everything in and under /var and put the results in a file in the current directory called filename2. This works on directories owned by another user including root as long as you have read access for the directories.
You can also list directories you don't have access to such as /root with the use of the sudo command. eg:
Would list everything in /root, putting the results in a file called filename3 in the current directory. Since most Ubuntu systems have nothing in this directory filename3 will not contain anything, but it would work if it did.