Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Them: typically ls sticks with its normal behavior unless you've been clever with aliases
- You: Can you resend your lest replies. I had to close chat for a sec
- Them: Sure. ls sticks with its normal behavior unless you've been clever with aliases
- Them: try changing "ls" to "\ls" (starting with a backslash) or "/bin/ls" (fully qualifying the path)
- Them: in a more permanent sense, you can switch from "ls" to "find" (find /your/path -name *.TERM)
- You: Okay give me just a min. Thanks for this help. I really appreciate it.
- Them: You're welcome. I'm glad to help, and also glad to flex my bash debugging skills. This otherwise might bite me too someday :)
- You: So we both get to learn. I just started scripting a couple weeks ago haha. Anyways. I ran then command like this
- You: #/bin/ls -F /var/tmp/screens/S-mobile/*.TERM | sort -t. -k1 -n | tail -n +2 | xargs -r rm
- You: I still get the same result.
- You: I'm going to try it with find now.
- You: I am running from root prompt now.
- You: It seems to work fine when I do it from standard prompt.
- You: Btw I am writing this for an iPhone lol
- You: find seems to have done the trick
- You: Let me test a lil more and make sure it's consistent
- You: Hell yeah! Seems the script can't accidentally create anymore screens. Your a life saver bro.
- Them: Oh sorry, stepped away for a sec
- Them: Glad to help though!
- You: I'm still checking but yeah it seems to work great. It seems find also helps a lot in situations like these. Glad you could help me.
- You: I'll probably hit you up if that's okay with more questions like the one I posted.
- Them: It's tricky--ls is usually sufficient but find is a little better with scripting.
- Them: I'd be glad to chime in if I see any more of your questions on SO
- You: What are the differences between the two commands. I've seen people use both to achieve the same results. I typically like ls tho.
- Them: ls is a little more-suited for users
- Them: find is a little more-suited for scripts--more options, more predictable output
- Them: (ls output is predictable too, but as you can tell, adjustments and hacks happen)
- You: I guess I'll start using find for my scripts then. I've had some issues with ls in the past as well. Would you like the see the script as a whole?
- Them: Sure, I guess. I'll update the script as listed, noting that find works.
- You: Cool. I just wanna see what a pro thinks of it and if I am doing things properly.
- Them: Oh, I'm no pro scripter. I don't write BASH for a living. :)
- You: Well you got more than me skills than me. I just know what I want to do. That's how I am able to find my answers. http://pastebin.com/sNBaKq6c
- Them: For what it's worth, know that you're abusing find the way you have it
- You: How so?
- You: I'm probably abusing a lot of things lmao
- Them: find typically takes a path and then some expressions to narrow it down. it then returns a set of files
- Them: unless i'm misunderstanding something, your shell would expand the fully qualified path you have
- Them: so by the time find sees it, it looks like "find /path/to/a /path/to/b /path/to/c"
- Them: which is okay i guess, it's just not giving find anything to do
- Them: it's like pulling out a big expensive sharp knife and then a bag of pre-sliced cheese... the job's already done :)
- You: Could it cause slowing in the script. I remember using find on another part of the script and it cause it slow to a crawl>
- You: & it's taking me a min the comprehend what you mean. I learn by trial and error, so in my eyes if it works it works. ;-)
- Them: possibly. i've never found "find" to be slow enough that i've had to benchmark it
- You: let me test and see how things get listed.
- You: yeah so when I rund find like theis
- You: # find /var/temp/screens/S-mobile it outputs
- You: /var/temp/screens/S-mobile/
- You: /var/temp/Screens/S-mobile/12459.TERM
- You: /var/temp/screens/S-mobile/13261.ttys01.Geofferey's-iPhone
- You: is that what you mean
- You: Cause it list like that.
- You: I like my big sharp expensive knife it works lol
- Them: well
- Them: i'm just saying that "xargs echo /path/to/*.TERM" would do the same thing
- You: How is find still slicing my cheese?
- Them: your shell is slicing your cheese
- Them: it's performing argument expansion against your wildcard
- Them: i think
- You: oh I see. so I could ditch the find part completely?
- Them: for the sake of demonstration, type "echo /*" ... echo has no idea about filename expansion, but your shell does
- Them: you could use either "find" or filename expansion...it's redundant to use both, is all i'm saying
- You: I'm getting a bit confused now. what part of the code is the file name expansion?
- Them: the asterisk in "*.TERM"
- You: the wildcard
- Them: yeah. read 3.4.9 on http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_03_04.html
- You: So I can remove the wild card
- You: I think I'm gonna have you BASHing your head lol
- Them: Read my updated answer, that one uses find the way you'll typically see it
- Them: http://stackoverflow.com/a/17846459/1426891
- You: They both have the same output so I don't see the difference still.
- You: How about giving me an example on a different direcotry that would contain more files
- You: Here
- Them: Not saying the output would be any different, just saying that you were doing the same thing in two places.
- Them: I gotta bounce. Glad we got the script working :)
- Them: Have a good $TIME_UNIT !
- You: Alright man. Thanks for all the help. I really appreciate it and I will take what you said into account and do some more research & use the find command the way you specified.
- Them: good luck on your project. cheers!
- Start a new chat.
- original thread: http://stackoverflow.com/questions/17846433/remove-files-base-on-integer-name/17846459#17846459
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement