Democratic Underground Latest Greatest Lobby Journals Search Options Help Login
Google

Unix newbie question

Printer-friendly format Printer-friendly format
Printer-friendly format Email this thread to a friend
Printer-friendly format Bookmark this thread
Home » Discuss » DU Groups » Computers & Internet » Open Source and Free Software Group Donate to DU
 
realisticphish Donating Member (1000+ posts) Send PM | Profile | Ignore Wed Apr-06-05 10:46 PM
Original message
Unix newbie question
i'm using OSX, and have started learning unix via terminal. I have discovered some hidden files that apparently got downloaded inadvertantly through a p2p. they are just images, but i want to delete them. the problem is, they have multi-word names, with spaces, and have parentheses. How do I delete these?

i know, stupid stuff, but i'm teaching myself, and the book i'm using doesnt help in this respect

Thanks!
Refresh | 0 Recommendations Printer Friendly | Permalink | Reply | Top
FormerDittoHead Donating Member (1000+ posts) Send PM | Profile | Ignore Thu Apr-07-05 01:35 PM
Response to Original message
1. escape!
Edited on Thu Apr-07-05 01:36 PM by FormerRushFan
the "\" is an escape character indicating what follows is a special character

"\ " = space.

the name of the file has spaces.jpg
=
the\ name\ of\ the\ file\ has\ spaces.jpg

doesn't OSX support filename "tab completion"?
Printer Friendly | Permalink | Reply | Top
 
Commie Pinko Dirtbag Donating Member (1000+ posts) Send PM | Profile | Ignore Thu Apr-07-05 03:52 PM
Response to Reply #1
2. Other way: double quotes
rm "the name of the file has spaces.jpg"
Printer Friendly | Permalink | Reply | Top
 
realisticphish Donating Member (1000+ posts) Send PM | Profile | Ignore Fri Apr-08-05 05:42 PM
Response to Reply #2
6. i tried that
(that's what the book said), but it didn't work. I don't know if it was because it was a hidden file or what
Printer Friendly | Permalink | Reply | Top
 
realisticphish Donating Member (1000+ posts) Send PM | Profile | Ignore Fri Apr-08-05 05:41 PM
Response to Reply #1
5. it does
i just figured out why it didn't work...i wasnt capitalizing the first letter :dunce:

i got it removed via the rm *--- method, then realized what i hadn't done

thanks for the help!
Printer Friendly | Permalink | Reply | Top
 
salvorhardin Donating Member (1000+ posts) Send PM | Profile | Ignore Fri Apr-08-05 12:02 PM
Response to Original message
3. Another way to do it
Edited on Fri Apr-08-05 12:03 PM by salvorhardin
is to use wildcards.

For instance, if you want to remove every JPEG file in your current directory.
rm *jpg


...or if you want to remove every file that begins with 'PHOTO'
rm PHOTO*

If you want a solid introduction to what you can do via the shell, here's an excellent tutorial.
http://www.tldp.org/LDP/abs/html
Printer Friendly | Permalink | Reply | Top
 
realisticphish Donating Member (1000+ posts) Send PM | Profile | Ignore Fri Apr-08-05 05:38 PM
Response to Reply #3
4. i did it!
i used the rm *--- method. i just can't figure out why none of the other methods worked

thanks for the tutorial, that;ll be a great help
Printer Friendly | Permalink | Reply | Top
 
salvorhardin Donating Member (1000+ posts) Send PM | Profile | Ignore Sat Apr-09-05 12:15 PM
Response to Reply #4
8. Cool
Just be careful of rm -rf *

...I accidentally wiped out a customer's entire website that way. :-)
Printer Friendly | Permalink | Reply | Top
 
trotsky Donating Member (1000+ posts) Send PM | Profile | Ignore Fri Apr-15-05 04:08 PM
Response to Reply #4
9. A useful "flag" for that command:
rm -i *---

The "-i" makes it interactive, so it will present you with a prompt for every file asking if you're sure you want to delete THAT one. A nice way to double-check - it's really easy to do a lot of damage with "rm" and "*".
Printer Friendly | Permalink | Reply | Top
 
qnr Donating Member (1000+ posts) Send PM | Profile | Ignore Fri Apr-08-05 11:48 PM
Response to Original message
7. For future use, here is a script that will replace spaces in a filename
with underscores.

#!/bin/bash
# blank-rename.sh
#
# Substitutes underscores for blanks in all the filenames in a directory.

ONE=1 # For getting singular/plural right (see below)
number=0 # Keeps track of how many files actually renamed.
FOUND=0 # Successful return value.

for filename in * # Traverse all files in directory
do
echo "$filename" | grep -q " " # Check whether filename
if < $? -eq $FOUND > #+ contains space(s).
then
fname=$filename # Strip off path.
n=`echo $fname | sed -e "s/ /_/g"` # Substitute underscore for blank.
mv "$fname" "$n" # Do the actual renaming.
let "number += 1"
fi
done

if < "$number" -eq "$ONE" > # For correct grammar.
then
echo "$number file renamed."
else
echo "$number files renamed."
fi

exit 0


Printer Friendly | Permalink | Reply | Top
 
MazeRat7 Donating Member (1000+ posts) Send PM | Profile | Ignore Sat Apr-16-05 09:46 PM
Response to Original message
10. Just type the first few characters of the filename then hit tab....
It will "auto complete" the filename for you inserting the necessary escape characters. (provided you gave it enough unique characters for the shell to figure it out) Multiple tab's will show you a list of choices.

I assume this works with the mac terminal, I know it works when I SSH into a mac.

Enjoy,
MZr7
Printer Friendly | Permalink | Reply | Top
 
DU AdBot (1000+ posts) Click to send private message to this author Click to view 
this author's profile Click to add 
this author to your buddy list Click to add 
this author to your Ignore list Tue Apr 30th 2024, 06:18 PM
Response to Original message
Advertisements [?]
 Top

Home » Discuss » DU Groups » Computers & Internet » Open Source and Free Software Group Donate to DU

Powered by DCForum+ Version 1.1 Copyright 1997-2002 DCScripts.com
Software has been extensively modified by the DU administrators


Important Notices: By participating on this discussion board, visitors agree to abide by the rules outlined on our Rules page. Messages posted on the Democratic Underground Discussion Forums are the opinions of the individuals who post them, and do not necessarily represent the opinions of Democratic Underground, LLC.

Home  |  Discussion Forums  |  Journals |  Store  |  Donate

About DU  |  Contact Us  |  Privacy Policy

Got a message for Democratic Underground? Click here to send us a message.

© 2001 - 2011 Democratic Underground, LLC