I thought it might be fun to have a thread where we can discuss the little things that we use Linux to do that might otherwise be impracticable or otherwise needlessly difficult.
I'll go first.
This morning I was given a bunch of data on three dozen DVDs. He wanted me to copy all of the .zip files within a very deep system of subdirectories, found amid other types of files, then combine them into one large archive. He said it would probably take me several hours to track 'em all down. Little did he know!
I needed just a few short commands to do the job and somebody who, unlike me, actually knows what they're doing could probably do it even easier.
essentially I ran:
Which, for those unfamiliar with such things is going to list all files in /cdrom, then search those results for .zip. It's going to then write the locations of those files to a text file on my desktop.
I popped open the file to see that it had indeed found a bunch of archives.
It then occurred to me that I could turn this into a little script. I went back to the command line and used sed:
This line uses sed, the Stream EDitor to search for /cdrom, the beginning of every path in the file, and replace it with mv /cdrom. All the of the backslashes are there to tell it to ignore the slashes and spaces which would confuse things. this is called escaping characters. I'll do the same sort of substitution for the end:
This replaces .zip with .zip ~/Desktop/zipfiles thus completing the move command. Now I just chmod +x mvscript2.sh and execute it and let the computer worry about navigating the nasty directories.
Since I had a lot of DVDs to go through I plopped all the commands I used into a single script which I ran after each disk automounted. In it I also ha Easy as pie and it let me get back to what's really important, playing networked dopewars.
I'm sure that if I had to do all this on Windows it would have taken hours.
So how about it, lads? Have you done anything cool with Linux lately to save you time, effort, or make you feel like some sort of demi-god, capable of solving all the world's problems with only a few keystrokes?
I'll go first.
This morning I was given a bunch of data on three dozen DVDs. He wanted me to copy all of the .zip files within a very deep system of subdirectories, found amid other types of files, then combine them into one large archive. He said it would probably take me several hours to track 'em all down. Little did he know!
I needed just a few short commands to do the job and somebody who, unlike me, actually knows what they're doing could probably do it even easier.
essentially I ran:
Code:
find /cdrom/* | grep ".zip" > ~/Desktop/zipfiles.txt
I popped open the file to see that it had indeed found a bunch of archives.
It then occurred to me that I could turn this into a little script. I went back to the command line and used sed:
Code:
sed 's/\/cdrom/mv\ \/cdrom/g' zipfiles.txt > mvscript.sh
Code:
sed 's/.zip/.zip\ ~\/Desktop\/zipfiles/g' zipfiles.txt > mvscript2.sh
Since I had a lot of DVDs to go through I plopped all the commands I used into a single script which I ran after each disk automounted. In it I also ha Easy as pie and it let me get back to what's really important, playing networked dopewars.
I'm sure that if I had to do all this on Windows it would have taken hours.
So how about it, lads? Have you done anything cool with Linux lately to save you time, effort, or make you feel like some sort of demi-god, capable of solving all the world's problems with only a few keystrokes?