I am trying to setup my plex server to use symlinks rather than host the movie files.
in my storage directory, i have both movies(some in subdirectory of the name and some just in the parent directory) and tvshows, which have subdirectories for each season, which contains the episodes
i would like to create a one-time script to parse the storage directory, and then create a symlink on the plex share directory, a directory for movies and one for tvshows.
I have figured out that using ls -d /dl/**/* to display the full working directory, but I cant figure out how to parse that data out to pass it to a script to create the symlink. Also I am getting errors when I attempt to manipulate, so I assume i will have to do a while read loop of some sort.
I would expect that I have 1-2 thousand files to create symlinks with.
Could anyone point me in a direction of how I should do this?
Scripting is not one of my strengths, i can usually pick apart a simple script to see what it is doing, but i cant seem to just create one from scratch.
Thanks
Band
Moderator's Comments:
edit by bakunin: please use CODE-tags for code, terminal output and data, as required by the rules and like i have edited them into your text. Thank you.
First the explanation why your command failed: wildcards ('*', '?', etc.) are expanded not by the commands you write but by the shell before it calls the commands. Suppose you have 3 files in a directory, fileA, fileB and fileC. If you issue a command like:
The shell will first expand "*" to the names of all files, replace the asterisk with their names and then execute the resulting command line:
Now the commandline only allows for so many parameters to be passed to a command and if there are thousands or even millions of files the list might become quite huge - to big for the commandline. This has happened here and is the reason for ls to complain.
When you want to process such a lot of files you can use one of the following methods, both of which avoid the problem with the expanding wildcards:
First, you can use the fact that ls per default lists all filenames if no parameter is passed. That means ls * and ls do the same thing. Pass the output to a loop in which you work on your files:
This works fine, but only if you want to process every file in a certain directory and you do not want to recurse through many subdirectories. If you want to process files in all subdirectories from some path onwards this method falls short.
For such cases there is the find command. Use it to produce a list of directory entries based on many different attributes (file/dir/link/..., certain ranges of modification dates, ownerships, etc. - see the man page of find for details) and use its -exec clause to process each directory entry found that way.
For instance, the following moves every file with a name starting with "A" to a certain directory. The starting directory is searched recursively so that all its subdirectories are included in the search:
Instead of a simple command like mv you could also provide a script written by yourself to do more complex manipulations. The "{}" will be expanded to a single filename found by find and the script be called with that parameter once for every entry found that way.
---------- Post updated at 07:27 PM ---------- Previous update was at 07:12 PM ----------
so playing around with this, i found that freebsd doesnt like -f
with the above command, i get the following output
Not sure why it thinks it is missing a backtick
It looks like bakunin was missing a double quote (shown in red on the 2nd line in the script below), but a space between the test argument and the closing square bracket is crucial. Try:
I know how to create a symlink but I am getting an error message that the file already exists. Also, my symlink doesn't point from target directory to the path correctly,
Here is an example of the path to my folder structure
path: cd /wkspce/wff/DEV/jobs/DEL
the folder structure is:
... (3 Replies)
i would like to remove a directory and also symlink target inside.
my_directory
-- file1 -> /targetpath/file1
-- file2 -> /targetpath/file2
rm -rf my_directory will not remove symlink target.
rm -rf "`readlink -f file1`" will only remove target if specifying the symlink is specified
... (4 Replies)
Hi All,
Is there any way to create a symlink that will point to last 1000 line of a log file. My symlink will always point to "tail -1000 logfile".
This can be achieved by writing a script and scheduling with high frequency, but I am looking for some other alternatives.
Please let me know... (8 Replies)
Hello. I am working on creating a script to recursively run on my media collection. The goal is to recreate the folder structure, but with slight changes in the folder names based on my rules. The folders will also include the .jpg & .mkv files, renamed according to a similar set of rules.
... (4 Replies)
Hi Forums,
I got a little problem, I made a few modifications to the code of the launch script of a testing server(minecraft) and now updating is broken aswell as the automatic directory creation.
These Lines somehow create an endless symlink that refers to itself and I don't know how to fix... (0 Replies)
Hi all,
I want to create a symlink on a link file, i mean, there is a file which is actually a symlink of some version. Now i want to create one more symlink on that link file.
EX: there is a file:
uat -> version
prod -> version
Now i want to create one more link on these 'uat' and... (1 Reply)
After a few hours of frustration because I didn't understand why my symlinks are destroyed i just found out that sed -i will destroy symlinks.
I searched but i didn't found any good solution for this.
Is there any way to overcome this ? On my ubuntu server sed version is 4.1.5
edit: Sorry... (0 Replies)
hi...
I have a folder<abc> under /root folder. I want to create a symlink such that when i click on folder<abc> under root, should display my home folder (home/krish).
Immediate inputs appreciated..... (1 Reply)
Hi,
I have created symlink under /.
It is /latest Pointing to /home/users/neel_prog_V1.0.
(Note: I have created this symlink so that when version get changed I will need to change only symlink instead of doing changes in /etc/exports.)
I have shared this symlink with NFS. in /etc/exports I... (0 Replies)