The Official *nix Thread

Inane baanter or words of wisdom - you decide...
Post Reply
User avatar
Dungeon-Dave
Baaaaaa!
Baaaaaa!
Posts: 3925
Joined: Thu Aug 04, 2005 12:01 pm 0
Location: UK
Contact:

Re: The Official *nix Thread

Post by Dungeon-Dave »

RageMatrix wrote:What am I doing wrong here?
.. apart from not using LVM + ext4?

D&RFC...
User avatar
RageMatrix
Baaaaaaa!
Baaaaaaa!
Posts: 5515
Joined: Fri May 10, 2002 12:52 pm 0
XBL Gamertag: Jon256
Location: East Sussex

Re: The Official *nix Thread

Post by RageMatrix »

Dungeon-Dave wrote:
RageMatrix wrote:What am I doing wrong here?
.. apart from not using LVM + ext4?

D&RFC...
Okay, I'll bite :D What's wrong with what I've got going already? I've now got my /home directory on a separate drive (much easier to shift over to the new drive than I thought it would be) and all seems to be running okay and the rest of the filesystem is ext3. What's the benefits of ext4? I'm unlikely to have filesizes of 16 terabytes or need to access 1 exabyte volumes or anything. Reduced fragmentation might be a plus I suppose. Most of the benefits of ext4 seem to be fixing little things in ext3 that I'm unlikely to need.
XBox Gamertag: Jon256
Wii Code: 4849 1090 9042 6725
"Wrapped in metal, wrapped in ivy"
The Official UNIX/Linux Thread
User avatar
Dungeon-Dave
Baaaaaa!
Baaaaaa!
Posts: 3925
Joined: Thu Aug 04, 2005 12:01 pm 0
Location: UK
Contact:

Re: The Official *nix Thread

Post by Dungeon-Dave »

Nah, I was doing my usual piss-taking to see if you'd bite...! :lol:

TBH - if it suits your needs, then there's really no reason to change it. EXT4 contains some newer algs which didn't find their way into EXT3, so is more efficient. One of the "new tricks" is the ability to do online partition resizing, although this DID find its way into later EXT3 tools so is not Reiser/EXT4-exclusive.

As for the LVM thang... ISTR that you were interested in it at one time and I'd done a guide (or was that another forum) so wondered if you'd taken the plunge yet. One major advantage of LVM is the ability to migrate partitions between disks online (move data as it's still in use) so you can happily swap HDs in and out, leapfrogging to larger storage whilst allowing your data to float and expand into whatever space is available at the time.
User avatar
RageMatrix
Baaaaaaa!
Baaaaaaa!
Posts: 5515
Joined: Fri May 10, 2002 12:52 pm 0
XBL Gamertag: Jon256
Location: East Sussex

Re: The Official *nix Thread

Post by RageMatrix »

Heh :D

Well, LVM is on my list of things to learn but TBH, I was going to use it for what I've already done anyway - moving /home to the new disk. I'm sure you can do more with it than that so I'll look into it in due course. I'm learning about the GRUB bootloader right now :)
XBox Gamertag: Jon256
Wii Code: 4849 1090 9042 6725
"Wrapped in metal, wrapped in ivy"
The Official UNIX/Linux Thread
User avatar
defsdoor
Baaaaaa!
Baaaaaa!
Posts: 3909
Joined: Fri Jan 30, 2004 12:26 am 0
Location: Sunny Beduff

Re: The Official *nix Thread

Post by defsdoor »

Learn software raid. Installing it on a live system is great for the nerves :)
User avatar
RageMatrix
Baaaaaaa!
Baaaaaaa!
Posts: 5515
Joined: Fri May 10, 2002 12:52 pm 0
XBL Gamertag: Jon256
Location: East Sussex

Re: The Official *nix Thread

Post by RageMatrix »

Gah - does sed do something special with whitespace in regexs?

For example, a file (file.txt) contains a list of paths with spaces in the directory names such as:-

Code: Select all

/home/directory/my documents/my file.txt
and I'm want to escape the spaces so that the output ends up like: -

Code: Select all

/home/directory/my\ documents/my\ file.txt
so that Linux won't shit itself. The following regex...

Code: Select all

for filename in $(cat ~/file.txt | sed -e 's/ /\\/g')
do
        echo "$filename"
done
...outputs this: -

Code: Select all

/home/directory/my\documents/my\file.txt
So I figured if I just added a space after the '\' in the sed substitution, I should get what I want like so: -

Code: Select all

for filename in $(cat ~/file.txt | sed -e 's/ /\\ /g')
do
        echo "$filename"
done
Instead the output I get is: -

Code: Select all

/home/directory/my\
documents/my\
file.txt
What the hell? Since when did a space become a newline character?
XBox Gamertag: Jon256
Wii Code: 4849 1090 9042 6725
"Wrapped in metal, wrapped in ivy"
The Official UNIX/Linux Thread
User avatar
xav
Baaaaaa!
Baaaaaa!
Posts: 2455
Joined: Thu Jun 06, 2002 5:32 pm 0
Location: Bucks, UK
Contact:

Re: The Official *nix Thread

Post by xav »

RageMatrix wrote:Gah - does sed do something special with whitespace in regexs?
I'm not sure that it's sed to blame.
RageMatrix wrote:What the hell? Since when did a space become a newline character?
It's not a newline character, but it is the default bash "field separator". Your bit of sed outputs a series of strings with spaces in, so I think the for loop is looping over each part of the string - much like doing "for i in a b c d".

You can temporarily change the bash input field separator by setting it to something else (nothing at all, in this case):

Code: Select all

(IFS=; for filename in $(cat ~/file.txt | sed 's/ /\ /g'); do echo  $filename; done)
BTW, the "cat" is a bit redundant, given that sed outputs the strings as they are changed, so you can probably get away with this:

Code: Select all

(IFS=; for filename in $(sed 's/ /\ /g' ~/file.txt); do echo  $filename; done)
Co-creator of The Greys, Monsters, Inked & Elvie webcomics
• Web Site • Twitter • Patreon •
User avatar
RageMatrix
Baaaaaaa!
Baaaaaaa!
Posts: 5515
Joined: Fri May 10, 2002 12:52 pm 0
XBL Gamertag: Jon256
Location: East Sussex

Re: The Official *nix Thread

Post by RageMatrix »

Thanks xav, that worked a treat. Didn't know about that env. variable.
XBox Gamertag: Jon256
Wii Code: 4849 1090 9042 6725
"Wrapped in metal, wrapped in ivy"
The Official UNIX/Linux Thread
User avatar
defsdoor
Baaaaaa!
Baaaaaa!
Posts: 3909
Joined: Fri Jan 30, 2004 12:26 am 0
Location: Sunny Beduff

Re: The Official *nix Thread

Post by defsdoor »

Be careful changing the IFS - always change it back.

Where I used to work we once killed all our customers systems after a software release. The guy the wrote the script that applied it and cleaned up etc.. mucked about with IFS - setting it to .

He forgot to change it back in the script, which subsequently did cd .. followed by rm -rf *

So the shell saw this as cd - taking the script to the user's home directory - which was the root of our application and nicely deleted it completely. Took me a while to see what was happening. On the odd occasion that I do change IFS (usually reading CSV files) I always do -

Code: Select all

OFS="$IFS"
 IFS=","
 while read COL1 COL2 COL3
 do
  IFS="$OFS"
  # do something with my data
  IFS=","
 done
 IFS="$OFS"
In your example though I wouldn't use for, I would do this -

Code: Select all

sed -e 's/ /\\ /g' < file.txt |
while read FILENAME
do
 echo "$FILENAME"
done
I rarely use for - usually only when looping over $*
User avatar
xav
Baaaaaa!
Baaaaaa!
Posts: 2455
Joined: Thu Jun 06, 2002 5:32 pm 0
Location: Bucks, UK
Contact:

Re: The Official *nix Thread

Post by xav »

I take your point about the possible need to change it within the body of the loop - but as for changing it back afterwards, that's why the example I gave was wrapped in brackets, so that it would run in a sub-shell and not leave any lasting changes to the parent shell's variables.
Co-creator of The Greys, Monsters, Inked & Elvie webcomics
• Web Site • Twitter • Patreon •
User avatar
tufty
Sheepie Whore
Sheepie Whore
Posts: 12524
Joined: Fri Jan 07, 2005 4:52 pm 0
Location: French Alps

Re: The Official *nix Thread

Post by tufty »

Okay, got an issue.

My netra lost a hard drive due to power spikes, of course it was the boot volume...

So, I have a shiny new 73gb drive in a spud, and a shiny new freebsd install image on my mac, and I want to netboot the installer on the netra to get it up and running. this used to be pretty easy, modulo the odd bit of buggering about with netinfo, but it doesn't appear to be working any more - indeed, it's failing at the rarpd stage.

Here's the setup:

netra is set to do a "boot net" from openboot.
ethernet cable strung across between the mac and the netra

On the mac, I have /private/tftpboot symlinked to /tftpboot, and the freebsd loader symlinked to the relevant ip address encoded as uppercase hex within that.
/etc/ethers has a mapping from the netra's MAC to its IP
/etc/hosts maps the ip to a hostname
tftpd is enabled

I run rarpd from a commandline, `sudo rarpd -d en0` and tell the netra to boot - rarp sees sees incoming rarp packets, but for some reason won't reply to them.

WTF am I doing wrong?

Simon
"massive retard™", "full of shit™", "tiny bitch™", "retarted™", "a bit of a one trick pony™", "petty™", "simple minded idealistic twat™", "miserable humourless fucker™"
User avatar
Dungeon-Dave
Baaaaaa!
Baaaaaa!
Posts: 3925
Joined: Thu Aug 04, 2005 12:01 pm 0
Location: UK
Contact:

Re: The Official *nix Thread

Post by Dungeon-Dave »

User avatar
RageMatrix
Baaaaaaa!
Baaaaaaa!
Posts: 5515
Joined: Fri May 10, 2002 12:52 pm 0
XBL Gamertag: Jon256
Location: East Sussex

Re: The Official *nix Thread

Post by RageMatrix »

Hey-hey,

I've got a nested directory structure with files and directories with spaces in them. How can I recursively change the names of the files and directories to remove the spaces and replace then with "-" instead? I've got a feeling I can do this with sed or something but for the life of me I can't get it to work. Any help please?

Ta.
XBox Gamertag: Jon256
Wii Code: 4849 1090 9042 6725
"Wrapped in metal, wrapped in ivy"
The Official UNIX/Linux Thread
User avatar
Dungeon-Dave
Baaaaaa!
Baaaaaa!
Posts: 3925
Joined: Thu Aug 04, 2005 12:01 pm 0
Location: UK
Contact:

Re: The Official *nix Thread

Post by Dungeon-Dave »

I could probably hack something together in perl; that'd be the easiest for me, I think.

(But that's a Programming forum thread).
User avatar
koogy
Baaa!
Baaa!
Posts: 475
Joined: Thu Aug 31, 2006 11:16 am 0

Re: The Official *nix Thread

Post by koogy »

couldn't get it into one line so am using a temp file. first line gets a list of files (from current directory) and stores them. second line reads a line at a time and replaces all spaces with underscores.

Code: Select all

find . -maxdepth 1 -name "* *" > acd
while read line; do echo mv "$line" ${line// /_}; done < acd
repeat changing the maxdepth until you've done the whole tree

oh, the above will just echo the commands and not execute them. remove the 'echo' to do the actual move.

couldn't work out how to use two {}s in a find exec and not how to do the ${line// /_} thing that does the actual substitution using {}.
Post Reply