Hi Linux power users, I was wandering how you do search for files

@Akito
Thanks, I am sure I will, at some point, beat my head against a wall, and try a bash script, just for the fun or agony. Could you recommend a book for bash learning?

No, I don’t know of any good guiding book. There are instead a couple of reference style resources, which you can use a cheat sheet when playing around with it.

https://bash.cyberciti.biz/guide/Main_Page

There were a couple of other ones, too, but I cannot find them, right now.

Just try to do something in Bash. If you are stuck, read into a resource or search on DuckDuckGo.

Then, proceed with that until you are stuck again.

Rinse & repeat.

2 Likes

You are missing the point that it is possible to program a general purpose algorithm, that can be used over and over to solve many real world problems. For example there are general purpose functions for solving linear programming problems.
It is OK to program such an algorithm in math notation. To use symbols relevant to one application only would reduce its generality.

A shell script is just all the commands you would have typed at the command line, collected together into a file.

I learned bash scripting, after knowing ksh for a few years on Solaris UNIX, they’re not vastly different from one another, i.e. a shell script in ksh should run unmodified in bash, just maybe change the shebang at the top - but generally not the other way around - e.g. a bash shell script that uses various bash features (e.g. $(command) instead of “backticks”, bash’s builtin “sets” or “ranges” e.g. "for i in {1…25} will definitely fail in KSH AFAIK - I’ve never tried).

For a few years, I was so used to ksh, I used to install pdksh on Linux so I could use stuff I knew in ksh… But - seriously BASH craps all over what came before… I’ve yet to try scripting in ZSH (my preferred interactive shell).

I learned by having problems to solve, or repetitive tasks that bored the crap outta me…

I also understood programming as I’d done some Basic on TRS-80, some Pascal and Assembler at Uni…

If you have an a problem you need to solve, that could be automated, try bash…

There are some bash features I can’t always remember, so I ended up plagiarising my own shell scripts when I can’t remember something - like field separators “IFS=$(blah blah)” I can never remember the exact syntax so have took at an old shell script…

╭─datripp@loge.local ~/bin  ‹main*›
╰─➤  grep IFS *.bash                                                                                              2 ↵
F**K-off-fonts.bash:IFS=' ' read -ra aFonts <<< "$fonts"
applefuquit-perm.bash:IFS=$(echo -en "\n\b")
colory-fuquery.bash:IFS=$(echo -en "\n\b")
enforcer.bash:# export IFS=$'\n'
figgit.bash:IFS=$(echo -en "\n\b")
fixsssd.bash:IFS=$(echo -en "\n\b")
fixupper.bash:# IFS=$(echo -en "\n\b")
fixupper.bash:IFS=$'\n'
flac-2-mp3.bash:IFS=$(echo -en "\n\b")
force10.bash:# export IFS=$'\n'
imgclipit.bash:IFS=$'\n'
inst-restart.bash:export IFS=$(echo -en "\n\b")
lastbit.bash:IFS=$'\n'
mcf**k2mp3.bash:IFS=$(echo -en "\n\b")
mon-xfer.bash:IFS=$'\n'
old_sumuzurs.bash:IFS=$(echo -en "\n\b")
purvue.bash:IFS=$(echo -en "\n\b")
rolling-perm.bash:IFS=$(echo -en "\n\b")
shitlist.bash:export IFS=$'\n'
shitqu-cuec*nt.bash:export IFS=$(echo -en "\n\b")
shonko.bash:IFS=$(echo -en "\n\b")
shonkysohn.bash:IFS=$(echo -en "\n\b")
space-list.bash:export IFS=$'\n'
spud.bash:IFS=$(echo -en "\n\b")
spudchuq.bash:IFS=$(echo -en "\n\b")
sumuzurs.bash:# IFS=$(echo -en "\n\b")
sumuzurs.bash:IFS=';'
sumuzurs.bash:	# IFS=$'\n'
uter-2-cue.bash:IFS=$(echo -en "\n\b")
wma2mp3.bash:# Need to change IFS or files with filenames containing spaces will not
wma2mp3.bash:IFS=$'\n'
wrap.bash:# IFS=$(echo -en "\n\b")

That’s what I did. I wanted to learn a little about bash scripts, but I needed a goal. So I decided to write a script. I ended up writing the game called Master Mind. Instead of guessing 4 colors, I changed it to guessing 4 numbers in the proper order in the range of 1 thru 6. Giving fed back as to any correct number and position.


As I ran into a problem coding, I would do searches with google looking for examples. I even posted here on this forum some questions. Still don’t know a lot about bash, but it turned out to be fun writing the script.

2 Likes

The Platonic view is that math entities are real … more real than the
‘real world’ things they are sometimes used to represent
So the -‘circle concept’ is more real than any approximate circles which we make or find naturally.

Berkley ( yes BSD has a philosophical ancestor) went even further , saying that ‘natural’ things do not exist at all, unless perceived by someone.

That’s one interpretation of what he considered real.

Yes. But that does not mean, the perception is made from the right view.

There are a number of prominent mathmaticians who declared themselves Platonists. An example that comes to mind is Roger Penrose.

There a probably as many interpretations of Plato as there are interpreters. He is difficult to read. You are talking about the kindergarten of human thought… it is bound to be stumbling and obscure and even child-like.

That said, his theory of Forms is one of the most fascinating pieces of philosophy

Yes. But that does not mean, the perception is made from the right view.

I dont understand ‘right view’… There is only one view I know…mine.
Everything outside of that is reports of other peoples views. I dont see where ‘right’ comes into it. It is about whether things exist ‘only in the mind’ or physically .

1 Like

Exactly. You already got a huge point about it. I also must emphasise, that “right view” does not imply “wrong view”.
“Right view” is just the most distraction-less & “pure” (another word, that needs an interpretation) view. However, other views are not “wrong”, they are only open to improvement.

In a way you are correct, but, as stated earlier already as well, “physical” is relative to perceivers. Without a perceiver, “physical” is not as “real” as almost everyone on earth understands it.

At the same time, everything is viewed differently by different people. After all, to my knowledge, there isn’t even proof, that every human sees colour the same way. If I see green, is it the same colour in your brain that you consider green? We only agree, that it’s the same colour, but we do not know, whether we are actually receiving the same colour inside our brains.
All the colour-blind members here can tell us stories about that, even more so.

Therefore, the “right view” is the view that enables you to see “what is true” as in “what is related to reality”, by making you “see” (another metaphor) what is there, without all the human crowdedness, that is simply introduced by the fact, that you are just a human with all its implications.

There are a lot of mistakes in the English language. For example, it is said “we came into this world” & “they have passed away”. Which is just a lie people continued to repeat for too much time.
In actuality, “we come from this world” & “we go from this world, to this world”.

The particles that make us up have always been there, since the beginning of the universe, if there was one.

We are more than the sum of our particles.
Tbere are emergent properties in any particle collection.
It is the way the particle assembly is organised that constitutes what we are
Our particles come and go dynaically, during our life. The Ca atoms in my bone are not the same ones as when I was young. The organisation is the only permanent thing. Our particles are just borrowed from the environment, to which they eventually return…

2 Likes

oh god thanks everybody for all the answers, I’m loving nnn right now!

Aikito writes:

The average home user should know, that find should not be used anymore, due to the reasons I depicted earlier.

I agree that find can be frustrating if (say) you’re searching an 8 TB disk for one file. But it’s a fantastic command for many other uses, as long as you understand its limitations. Here are some examples:

  • Finding all log files that are older than 1 year and deleting them (using find -mtime -delete in /var/log).
  • Locating files that are newer or older than a given file (using find -newer)
  • Piping the results of find to xargs to run arbitrary commands on a set a files. (My personal favorite.)

To speed up find for everyday use, run a nightly cron job, find $HOME -print > $HOME/.ALLFILES, and then you can simply grep through $HOME/.ALLFILES to locate files, which is 100x faster than find. (This tip is in my O’Reilly book Efficient Linux at the Command Line.) Or run locate as someone else suggested.

3 Likes

100% - as mentioned earlier - Linux / UNIX is my job, and despite some of find’s “limitations” and also different features depending on version - it’s still powerful…

Per @dbauthor 's post - for me - 9x / 10 - a disk full, or approaching capacity, it’s going to be something located in /var/…

cd /var

find . -type f -mtime -1 -size +1G

to get a hint - what it might be, then maybe find some other alternate filesystem that’s not getting full and plonk those larger files there :

find . -type f -mtime -1 -size +1G -exec mv {} /mnt/bigdir/. \;

I’d never use “-delete” - like that though, given it may not be in all versions of find (e.g. Red Hat 5, Debian 4, Solaris 10) - and I need to see what it mind first anyway. And if I remember correctly, not even “-size +1G” works in Solaris, in Solaris you have to put your mathemetician hat on and figure out what’s big in 512 byte chunks, so I MB is 2 x 512 bytes, so if I’m looking for something over 1 GB, I’m wanting to search for “-size +2048000” or that ballpark, but then I also remembered I think Solaris you can also specify “C”, for “characters”, or bytes, not 512 byte “disk segments”… Meh! Nighmare fuel just thinking about it - I used to love Solaris, but I can’t wait till it’s NO LONGER :smiley: :

YARN | For fuck's sake, die, will ya? Give me that thing. | The Crow (1994) Crime | Video clips by quotes | 9606c11c | 紗

The imminent death of Solaris can’t come too soon for me…


I just recalled one of the HIDEOUS limitations of the find command - e.g. if I want to find some stuff in $PWD, except for folder1,2,3 et cetera… How do I do that? Either the bullshit highly unintuitive “prune” operation - seriously - who thunk this sadistic shit up?

See this does sweet FA :

╭─x@titan ~/ResilioSync/Music  
╰─➤  find . -type d -prune -o  -path ".sync"                                                                                                       
.

See - my Resilio Sync hosted music is in ~/ResilioSync/Music/ - but - if I want to get a true picture how much data it’s using, I need to somehow exclude ~/ResilioSync/Music/.sync folder - 'cause that’s where it plonks stuff that’s been deleted or renamed or whatever (for up to 30 days)… Now - that’s handy (getting back “stuff”) - but - what happens if I want to know how much DISK is being used by stuff that’s NOT in that “.sync” folder? So there’s maybe “not” as well? Prune doesn’t seem to do anything so :

╭─x@titan ~/ResilioSync/Music  
╰─➤  find . -type d -not -path ".sync" -exec du -sh {} \; | sort -h

But I’d be wrong - 'cause :

╭─x@titan ~/ResilioSync/Music  
╰─➤  find . -type d -not -path ".sync" -exec du -sh {} \; | sort -h
4.0K	./.sync/Archive/Moby/1999-Play-FLAC
4.0K	./.sync/Archive/VON-HAUSSwolff-Anna/2013-Ceremony-FLAC
4.0K	./.sync/Archive/VON-HAUSSwolff-Anna/2015-TheMiraculous-FLAC
4.0K	./.sync/Streams
8.0K	./PlanetOfThe8s
8.0K	./.sync/Archive/Moby
12K	./.sync/Archive/VON-HAUSSwolff-Anna
... snip snip ... 
3.5G	./Clash
3.9G	./Neurosis
4.1G	./Rammstein
4.3G	./WaitsTom
90G	.

As you can see - I asked it to NOT traverses to “.sync” but it FUCKING DID ANYWAY! What’s the point of it?

I have a “workaround” that doesn’t involve figuring out the obtuse vagaries of such arcane CLI black magic - I don’t keep an “undelete” copy on my Pi4 so I can go there :

╭─x@beere253 ~/ResilioSync/Music  
╰─➤  du -sk .
93260664

So - it turns out - the first answer (using find) was possibly correct, but I couldn’t trust it completely as the PIECE OF CRAP still traversed the “.sync” folder I EXPLICITILY told it to ignore!


DAMN! I just noticed that half of the music I’ve uploaded into my ~/ResilioSync/Music/ folder is NOT getting transferred to my phone when I run my shell script that uses adb-sync to mirror the Music on my phone, and the ResilioSync/Music share - why?

BECAUSE SOME MORON thought it would be a good idea to use a FUCKING “pipe” (“|”) symbol in a filename! WHAT MORON DID THAT - there’s a special place in hell for them anyway…

I might have to dig out the pile of scripts I wrote a few years back to clean up filename POLLUTION off a NetApp that had accumulated over years… I blame mostly Mac users, but not always… some bright spark though prefixing folders with a space, two spaces, three spaces, was some kinda version control…

I’ve already got it looking for “?” in filenames (who even does that idiotic thing?)… I think I’ll have to tailor it to cover every possible scenario, because there’s an AWFUL LOT OF IDIOTS OUT THERE!