Need Bash command to list text file backwards. (Solved?)

Using applications, configuring, problems
Post Reply
Message
Author
User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#16 Post by sunburnt »

Just so the files in each dir. were deleted before the dirs. it'd work.

But as I stated, there's a problem with this, preexisting empty dirs.
This code structure would delete them without tracking preexisting dirs.

At this point I opted to do the test while writing the installed files list.
Once the test split the dirs. & files I just decided to make both dirs. & files lists.
So the new code deletes the files list first & the dirs. list second.

GuestToo
Puppy Master
Posts: 4083
Joined: Wed 04 May 2005, 18:11

#17 Post by GuestToo »

i honestly don't know what you are talking about

if you have a list of files and/or dirs in a text file that you want deleted, my script will do just that ... it will delete every dir and file in the list ... it is not necessary to sort the list first, it is not necessary to delete the files first, it is not necessay to separate the list of dirs from the list of files ... my script will simply check each item in the list, and if it is a dir it will delete the dir and every file and subfolder in the dir, if it is a file it will delete the file, if it is not a valid file or dir, it will ignore it

if you want some files deleted and some not deleted, and/or you want some dirs deleted and some dirs not deleted, it can not do that (it would need to know which ones you did not want to delete)

my script simply deletes every item in the list ... nothing more, nothing less

Bruce B

#18 Post by Bruce B »

bobn9lvu wrote:
Bruce B wrote:Maybe I'm missing something, if so forgive me is so. Wouldn't the following command accomplish your purpose?

find|sort -r

or

find|sort -r>fileout.txt
it would?
i thought that the dirs in this case would not be put 1st or last, but in alphabetical order dispersed amoungst the files?????

bob :?
Here's from you first post

My app.: sfsinstaller deletes files installed to a Full-HD install.
To do this it makes a list of all the files contained in the installed SFS file.
The list is made with "find" & the dirs. are listed first, but they must be deleted last.

So... A simple fix is to read the file list backwards.

[cut]

Anyone know how to read a test file backwards or make a new one in 1 or 2 commands?
You're the one who said, "A simple fix is to read the file list backwards."

sort -r does exactly that.

Below, I've highlighted the directories in bold, they come last, by directory group. Note, in this example, the child directory and file listings come before the parent's.

./.jwm/themes/themeslist
./.jwm/themes/jwm-puppy-xp
./.jwm/themes/jwm-peach
./.jwm/themes/jwm-original
./.jwm/themes/jwm-default
./.jwm/themes/jwm-blueX
./.jwm/themes
./.jwmrc-tray
./.jwmrc-previous
./.jwmrc
./.jwm/jwmrc-personal2
./.jwm/jwmrc-personal
./.jwm

GuestToo
Puppy Master
Posts: 4083
Joined: Wed 04 May 2005, 18:11

#19 Post by GuestToo »

The list is made with "find" & the dirs. are listed first, but they must be deleted last.
this is what i don't understand ... why do you want to delete the files first? ... my script just deletes each item in the list

if the item is a dir, it deletes the dir and all files and subdirs, using rm -rf

if the item is a file, it deletes the file, using rm -f

(the -f in each case is not really necessary, but someone might have aliased rm to rm -i)

if the item is not a dir and is not a file, it ignores it

i honestly don't see the problem

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#20 Post by sunburnt »

GuestToo; The app. is the sfsInstaller for Full-HD installs of Puppy.
It mounts the SFS file & copies it's contense to / & makes an "install" file of the contense.

This is the command to make the "install" file "(sfsName).inst":

Code: Select all

find $sfsMNT |sed "s#^$sfsMNT##" > ${instFILES}/${sfsNAME}.inst
So to uninstall the app., only the files put in are deleted & only the nonpreexisting dirs.
There's also code to backup preexisting files & restore them during uninstall.

So copy is done "cp -a ....", but deleting is done one file at a time & then dirs.
So just deleting from a full dir. list would delete preexisting dirs. if they were empty.
But preexisting dirs. wouldn't be deleted if there were dirs. or files left in them.
There's code to check for preexisting dirs. & files, dirs. aren't added to the list.
Preexisting files are renamed to (FileName)_BAK-0 for backup / restore.

The Puppy Full-HD install should be exactly the way it was before the SFS was installed.
This dir. by file type of tracking's the only way I can see to assure that happens.
If preexisting dirs. aren't in the install file, & "rm -rf" isn't used, your codes good.

Bruce B; Yes the reverse list is like 2 lists, & like it, it needs filering of preexisting dir./file.
As long as the code had to ID dirs., I figured just make separate lists.


### P.S. ... If anyone wants to look at the app., I'll gladly post it for all to critique.

Post Reply