Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
#!/bin/sh
SD="/var/spool/storage/SD_DISK/"
ARRANGED_FOLDER="/var/spool/storage/SD_DISK/videos_by_day"
for i in $(find "$SD" -type f); do
DAY=$(echo "$i" | cut -d'/' -f10 | cut -d'_' -f1 | sort | uniq)
if [ ! -d "/$ARRANGED_FOLDER/$DAY" ]; then
mkdir -p /"$ARRANGED_FOLDER"/"$DAY"
fi
cd "$ARRANGED_FOLDER"/"$DAY"
if ! ln -sfn "$i"; then
echo "[-] Error: Could not create symbolic links"
fi
done
I'd like to jump and not create symbolic links of any xml files. How can I do that? Please help me a bit
When I rerun the script, it starts to create all symbolic links again.
Could someone tell me how can I jump, and not recreate symbolic links which are already created,
and only create when there is a new mkv file which dowsn't have a symlink yet.
I'm worried a bit about that there would be to much write on the SD card.
rethinking this. You just want to link movies to a different directory created each time you run this?
in other words:
Each time you run this is WILL be on a different batch of files picking out all of the movies, creating a separate dir for each movie file by its own file name then linking that file into that same dir?
I was given a hint. That I should only make symlinks of only those files that doesn't have yet.
But that means a comparisson.
readlink is available on the product's embedded linux.
here I can make a list of those symlinks that have an original file
for j in $(find "$ARRANGED_FOLDER" -type f -name "*.mkv"); do
readlink $j
done
Ho could I make a list and create symlinks only of those that doesn't have yet.
I've read readlink man page and now I know it's not going to solve this. Thanks.
I'll check parameter expansion
I dont understand other syntaxes, could I achieve the same result with my thought?
now the code looks like this:
Code:
#!/bin/sh
echo "[+] Creating symbolic links ..."
SD="/var/spool/storage/SD_DISK/"
ARRANGED_FOLDER="$SD/videos_by_day"
while read i
do
DAY=$(echo "$i" | cut -d'/' -f10 | cut -d'_' -f1 | sort | uniq)
if [ ! -d "/$ARRANGED_FOLDER/$DAY" ]; then
mkdir -p /"$ARRANGED_FOLDER"/"$DAY"
fi
cd "$ARRANGED_FOLDER"/"$DAY" || exit 1
if [ here I need a way to check if there is a link already created ]
fi
elif ! ln -sfn "$i"; then
echo "[-] Error: Could not create symbolic links"
fi
done << (find "$SD" -type f -name "*.mkv")
if [[ ! "$DailyFiles"/"$ckfile" ]] && ln -sfn $FILENAME "$DailyFiles"/"$ckfile"
I beg to differ - YO. A link to a file shows what in the other directory it is link into? A file. As if it is already there. Hench the reason for soft links.
looks like he is only doing "links to" therefore no real fancy checks need to be done here.
All you have to so is look for that file first which is actually a link from another file. So if it is not there then create just a link to it within that same directory. done.
think about it. the only thing wrong is that code is the 'if' part. Motor reflects, or "force of habit" as some say it. I am use to doing complete if statements just not them ones. but the logic works and so does that code after removing the 'if' and adding the '-f'
is that "suppose" to give you a file name? because it comes up empty when I run it. just run this simple version with a path you give it to search. any path will work it is not changing any data.
Code:
#!/bin/bash
working_dir="/home/userx/test"
while read i
do
DAY=$(echo "$i" | cut -d'/' -f10 | cut -d'_' -f1 | sort | uniq)
echo "$DAY"
done < <(find "$working_dir" -type f -name "*.*")
gives me empty results. if you are just looking for the file name then that code I wrote that you do not understand gives you that. a file name to check
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.