Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
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.
Hey There, I need your help
i have a list of files created by ls /dir/ > list
Now I want to delete files from this list, some like boza=`less list`;rm $list But the files from list comes as one block. the variable $boza is file1 file2 file3 and i receive the message File name too long
How to tell less or other that I want to receive files from list line by line, not as one line all
Thanks
Well, if I have understood you, you want remove ALL the files of a directory, don't you? (rm /dir/* would do the job). Options A), B) and C) would do the job too. But it's too easy, so I think you don't want that exactly. Perhaps you want to edit the file (that you got with the ls command) and remove files you don't want to be removed.
FIRST: BE AWARE AND DON'T DELETE IMPORTANT FILES. BACKUP THEM BEFORE THE TESTS.
you have several ways to do that:
a)
Code:
# This code would remove all the files of /dir directory.
# Same and slower than rm /dir/*
for FILE in `ls /dir/`
do
rm $FILE
done
b)
Code:
ls /dir/ > list
# edit list file and remove the lines of files you don't
# want to be removed.
for FILE in `cat list`
do
rm $FILE
done
c)
Code:
find /dir -exec echo rm {} > delete.sh
# Edit delete.sh script and remove all the lines that would
# remove files you don't want to be removed.
chmod +x delete.sh
./delete.sh
I hope this can help you... or at least you got the idea.
bye.
T he files in "list are sum links, generated by cp -s /dir1/* /dir2/
The sum links are in my apache dir the real files are somewhere in my hd.
I'll paste the script to understand my idea
boza=`less /tmp/links`
if
[ -L "$boza" ];
then
rm /var/www/htdocs/videos/"$boza";
ls /data/videos/ > /tmp/links
cp -s /data/videos/* /var/www/htdocs/videos/
else
exit
fi
in this script variable $boza comes as one block...
I think I have understood you but I'm not sure at all :
Try to explain yourself in your own words. Don't explain me what your code does (I know it). Try to explain what you would like your code to do and don't speak about code.
I've understood you want to do this:
"I want to remove the symbolic links of /var/www/htdocs/videos/, but only those that are pointing to /data/video files because I have another symbolic links in that directory that are pointing to another directories and files. Then I want to create again symbolics links in /var/www/htdocs/videos/ pointing to all the /data/video files, and keep a file with these files to know later which files were copied (like symbolic links) to /var/www/htdocs/videos/, so if I remove files in /data/video I will not get broken links in /var/www/htdocs/videos/".
If this is what you want to do then this code would do the job:
Code:
#!/bin/bash
#
# variables:
FILE_LINKS=/tmp/links
DATA_VIDEOS=/data/videos
# delete all files present in the $FILE_LINKS file,
# but only if they are symbolic links:
if [ -r $FILE_LINKS ]
then
for BOZA in `cat $FILE_LINKS`
do
FILE=/var/www/htdocs/videos/${BOZA}
if [ -L $FILE ]
then
rm $FILE
fi
done
fi
# Recreate the $FILE_LINKS file with the actual
# contents of $DATA_VIDEOS and create symbolic
# links of all the stuff in /var/www/htdocs/videos/ :
cd ${DATA_VIDEOS}
ls -1 * > ${FILE_LINKS}
cp -s ${DATA_VIDEOS}/* /var/www/htdocs/videos/
cd -
exit
Yes, you understand me wright
The "rm" does not work.
I add "do" before "FILE=/var/www/htdocs/videos/${BOZA}" ...
The problem is when cat read the file. The output is file1file2file3file4file5 and rm try to remove "rm file1file2file3file4file5" not "rm file1" "rm file2" "rm file3"...
I found the answer with your help Goala.
this is the script:
Code:
sh /tmp/delete.sh
rm /tmp/delete.sh
cp -s /data/videos/* /var/www/htdocs/videos/
cd /var/www/htdocs
for boza in *;
do
echo rm \"/var/www/htdocs/videos/"$boza"\" >> /tmp/delete.sh
done
cd -
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.