Not that Perl isn't invaluable for some tasks, but I find the more I learn about shell commands, the less I find the need to fall back to writing a perl script.
rsync is a wonderful command for synchronizing files. Its primary benefit is that is able to determine what files have changed and copy only those changes.
It works over networks and is very bandwidth efficient (e.g. if you're syncing two 200MB directories, it can tell they are the same w/o uploading 200MB of data). There's options to filter the files to copy, or you can read a list from a file/stdin. There's the particularly "link-dest" option to have rsync make links to existing unchanged files in another directory, allowing space-efficient incremental copies.
rsync has native ssh support, so it can work as a drop-in replacement for scp. Really, any time you find yourself running the same copy command multiple times, you should consider using rsync instead. It can save a lot of time.
as a sysadmin, I found the easiest way to remove accidentally created files with a '-' in the same was to prefix the filename with './' as in: rm./-helloworld
I'm not sure there's even another way to do it.
rm -- -helloworld
"--" is a special option supported by many programs to indicate that all following parameters should not be considered options.
Of course on modern distros the locate command will complain that it's database doesn't exist until you manually enable the service because the command line is supposed to be dead.:(
imho, any unix system that doesn't have the updatedb cronjob enabled is broken.
Hmm, doesn't seem to work here (Ubuntu 8.04). But on a modern Linux system, you can just ls/dev/* to find out what devices are attached, since/dev is dynamically populated. I find blktool handy to find out more about block devices:
$ sudo blktool/dev/sda id scsi-version: 5 vendor-id: ATA product-id: ST3160815AS product-rev: 3.AD device-type: direct-access sectors: 312500000 sector-size: 512
My previous place of employment was a Mac shop, where I discovered the wonderful pbcopy and pbpaste commands. Why they aren't a standard part of every X windows distribution, I'll never know, but they are damned handy.
What they do is allow you to read and write from the cut-and-paste buffer from the command line. "pbpaste" will print the currently copied text to stdout, while "pbcopy" will replace the buffer with stdin.
Fortunately, there are some third-party X equivalents for this, such as xsel or xclip, which can be adapted to work in the same way.
A more 'advanced' version of this are the pushd/popd commands, which allow you to maintain a stack of previous directories. You can then reference entries in the stack as ~0, ~1, ~2 etc.
Reverse lines from a file: tac
That is, in reverse line-order. Not be confused with rev, which reverse the characters within each line.
And, of course, xargs, which is almost infinitely useful.
xargs is great, you can get a lot of mileage on it just from its default use, but add some options and you do some really cool things. My favorite is -P, which tells xargs to spawn parallel processes. For example:
xargs -n 1 -i -P 10 ssh {} remotecmd serverlist
Run "remotecmd" via ssh on all servers in serverlist, running 10 subprocesses at a time.
This is an important difference between unix shells and dos/windows shell. In Unix, the wildcards like "*" are handled by the shell and expanded before the program ever sees the arguments. In DOS/Windows, the expansion must be done by the program itself. This is why every program in unix understand wildcards, while only some do in the MS world.
One great feature of find that many people are unaware of is that you can use -exec as a test, not just as an action. For example, this is equivalent to your command above:
find . -exec grep -q {} \; -print
The "-print" action is only executed if the -exec command returns success.
You can do a lot of handy things with this. Here's a real-world example from earlier today. I wanted to change the mime-type of all the xml files in my svn repository from "application/xml" to "text/xml":
Personally, despite some wonderful new features, I'm going to stick with 8.04 for a bit, at least until they work out the bugs. Of course, I won't ever be prompted to upgrade to 8.10, because 8.04 is a long term support release. Having a look at the release notes, at least one unacceptable (for me) bug is:
On laptops with Intel 3945 or Intel 4965 wireless chipsets and a killswitch for the wireless antenna, starting the system with the killswitch enabled (i.e., with wireless disabled) will prevent re-enabling the wireless by toggling the killswitch. As a workaround, users should boot the system with the killswitch disabled. A future kernel update is expected to address this issue.
No, it's a design error to assume voting machine users will understand the same conventions as normal computer users. There any many people in the US who don't regularly interact with computers. The systems must be designed with the idea that, for many users, this will be one of their first experiences with a computer.
Who hasn't ever had a touchscreen ATM or a touchscreen POS station not register a touch as something unintended? You don't think the ATM is trying to rip you off when it picks "Savings" when you meant "Checking". You just hit cancel and do it again.)
Slight off topic but related alignment issue with non-touchscreen ATMs and POS devices. They usually have labels that line up with the physical buttons next to the screen. The problem is the screen is normally set back about an inch from the buttons. This means that the quality of the alignment between the label and the button depends on the angle you view the screen -- which depends on your height.
From my vantage as a taller person, the labels are often so shifted that they appear to the line up with the next row of buttons, causing me to hit the wrong ones. Very annoying. Occasional ATMs will use color coding as well, which avoids this problem.
Now tell me that those 30 seconds don't convey more via video than could be conveyed through 30 seconds of reading abstract symbols.
Fun fact: YouTube now lets you link to a specific time in a video, by added a time-index anchor at the end of the URL. For example, add #t=2m30 to the link you just posted.
Good question, aside from the headline they make no mention of any record being set! Neither does the blog post they cite. Perhaps the confusion somehow arose from their use of the word twice in other senses.
That or anything that begins:
#!/usr/bin/perl
Not that Perl isn't invaluable for some tasks, but I find the more I learn about shell commands, the less I find the need to fall back to writing a perl script.
Hmm, something on my system apparently kills the process due to all the errors before it actually returns any useful information:
$ sudo blockdev --report /dev/* 2> /dev/null
RO RA SSZ BSZ StartSec Size Device
Killed
Restricting it to disk devices works better:
$ sudo blockdev --report /dev/sd* 2> /dev/null /dev/sda /dev/sda1
RO RA SSZ BSZ StartSec Size Device
rw 256 512 4096 0 312500000
rw 256 512 4096 63 312496317
Rainbow tables.
Given how on-the-ball the openssh folks are, I'd be willing to bet they use a salt.
rsync is a wonderful command for synchronizing files. Its primary benefit is that is able to determine what files have changed and copy only those changes.
It works over networks and is very bandwidth efficient (e.g. if you're syncing two 200MB directories, it can tell they are the same w/o uploading 200MB of data). There's options to filter the files to copy, or you can read a list from a file/stdin. There's the particularly "link-dest" option to have rsync make links to existing unchanged files in another directory, allowing space-efficient incremental copies.
rsync has native ssh support, so it can work as a drop-in replacement for scp. Really, any time you find yourself running the same copy command multiple times, you should consider using rsync instead. It can save a lot of time.
as a sysadmin, I found the easiest way to remove accidentally created files with a '-' in the same was to prefix the filename with './' as in: ./-helloworld
rm
I'm not sure there's even another way to do it.
rm -- -helloworld
"--" is a special option supported by many programs to indicate that all following parameters should not be considered options.
Nice! Reminds me of the good old days of DOS...
copy con filename
Of course on modern distros the locate command will complain that it's database doesn't exist until you manually enable the service because the command line is supposed to be dead. :(
imho, any unix system that doesn't have the updatedb cronjob enabled is broken.
In tcsh (I don't know other shells), you can do directory stack substitution. =0 is current directory, =1 is one up, =2 is two up, and so on.
In bash, it's ~0, ~1, ~2, etc.
Your
is fine for non-GNU UNIX grep.
If you have GNU grep, then
Most systems will GNU grep will also have an rgrep command which is the same as 'grep -r'.
But the find approach allows much more sophisticated searches. Such as:
find . -name \*.xml -not -user root -exec grep -l keyword {} \;
(search all .xml files that aren't owned by root)
Also from ~/.ssh/known_hosts.
Nowadays it's standard to hash entries in the known_hosts file, to avoid giving an intruder a list of interesting hosts.
blockdev --report /dev/* | more
Hmm, doesn't seem to work here (Ubuntu 8.04). But on a modern Linux system, you can just ls /dev/* to find out what devices are attached, since /dev is dynamically populated. I find blktool handy to find out more about block devices:
$ sudo blktool /dev/sda id
scsi-version: 5
vendor-id: ATA
product-id: ST3160815AS
product-rev: 3.AD
device-type: direct-access
sectors: 312500000
sector-size: 512
My previous place of employment was a Mac shop, where I discovered the wonderful pbcopy and pbpaste commands. Why they aren't a standard part of every X windows distribution, I'll never know, but they are damned handy.
What they do is allow you to read and write from the cut-and-paste buffer from the command line. "pbpaste" will print the currently copied text to stdout, while "pbcopy" will replace the buffer with stdin.
Fortunately, there are some third-party X equivalents for this, such as xsel or xclip, which can be adapted to work in the same way.
Rougly equivalent:
pbcopy
xsel -i --clipboard
xclip -in -selection clipboard
pbpaste
xsel -o --clipboard
xclip -o -selection clipboard
You could easily have an entire Ask Slashdot just on ssh, perhaps the greatest unix command ever invented.
One of it's many great uses is creating secure tunnels:
ssh user@remotehost -L123:example.com:456
Open a tunnel on your local machine, port 123, to example.com, port 456, via the remote host
ssh -R lets you go in the opposite direction (tunnel from remote end to local end), but if your application supports SOCKS, it's even easier:
ssh user@remotehost -D8080
Creates a secure tunnel supporting the SOCKS protocol.
Go back to the previous directory:
cd -
A more 'advanced' version of this are the pushd/popd commands, which allow you to maintain a stack of previous directories. You can then reference entries in the stack as ~0, ~1, ~2 etc.
Reverse lines from a file:
tac
That is, in reverse line-order. Not be confused with rev, which reverse the characters within each line.
And, of course, xargs, which is almost infinitely useful.
xargs is great, you can get a lot of mileage on it just from its default use, but add some options and you do some really cool things. My favorite is -P, which tells xargs to spawn parallel processes. For example:
xargs -n 1 -i -P 10 ssh {} remotecmd serverlist
Run "remotecmd" via ssh on all servers in serverlist, running 10 subprocesses at a time.
This is an important difference between unix shells and dos/windows shell. In Unix, the wildcards like "*" are handled by the shell and expanded before the program ever sees the arguments. In DOS/Windows, the expansion must be done by the program itself. This is why every program in unix understand wildcards, while only some do in the MS world.
I sometimes use rev to sort text by the end of the line, not the first. This is often useful when comparing two similar file structures.
For example:
$ wc -l foo/* bar/*
6 foo/dead.letter
86 foo/xorg.conf
6 bar/dead.letter
54 bar/xorg.conf
$ wc -l foo/* bar/* | rev | sort | rev
86 foo/xorg.conf
54 bar/xorg.conf
152 total
6 foo/dead.letter
6 bar/dead.letter
(Yes, I'm aware you can use sort -k to specify the sort key, but this is quicker and easier)
One great feature of find that many people are unaware of is that you can use -exec as a test, not just as an action. For example, this is equivalent to your command above:
find . -exec grep -q {} \; -print
The "-print" action is only executed if the -exec command returns success.
You can do a lot of handy things with this. Here's a real-world example from earlier today. I wanted to change the mime-type of all the xml files in my svn repository from "application/xml" to "text/xml":
find . -name \*.xml -exec sh -c "svn propget svn:mime-type {} | grep -q application/xml" \; -exec svn propset svn:mime-type text/xml {} \;
Personally, despite some wonderful new features, I'm going to stick with 8.04 for a bit, at least until they work out the bugs. Of course, I won't ever be prompted to upgrade to 8.10, because 8.04 is a long term support release. Having a look at the release notes, at least one unacceptable (for me) bug is:
This is not a new bug in 8.10 by any means, it's been present since 8.04.
Anyone remember those older ATMs that had the eight buttons, four on each side of the screen? Let's use those instead.
Do I remember them? I used one last week. 90% of the ATM machines I see are like that, touchscreen ones are a definite minority.
No, it's a design error to assume voting machine users will understand the same conventions as normal computer users. There any many people in the US who don't regularly interact with computers. The systems must be designed with the idea that, for many users, this will be one of their first experiences with a computer.
Who hasn't ever had a touchscreen ATM or a touchscreen POS station not register a touch as something unintended? You don't think the ATM is trying to rip you off when it picks "Savings" when you meant "Checking". You just hit cancel and do it again.)
Slight off topic but related alignment issue with non-touchscreen ATMs and POS devices. They usually have labels that line up with the physical buttons next to the screen. The problem is the screen is normally set back about an inch from the buttons. This means that the quality of the alignment between the label and the button depends on the angle you view the screen -- which depends on your height.
From my vantage as a taller person, the labels are often so shifted that they appear to the line up with the next row of buttons, causing me to hit the wrong ones. Very annoying. Occasional ATMs will use color coding as well, which avoids this problem.
Just take 30 seconds of time and bandwidth, by viewing this starting half-way through from 2:30-3:00
http://www.youtube.com/watch?v=Jd3-eiid-Uw
Now tell me that those 30 seconds don't convey more via video than could be conveyed through 30 seconds of reading abstract symbols.
Fun fact: YouTube now lets you link to a specific time in a video, by added a time-index anchor at the end of the URL. For example, add #t=2m30 to the link you just posted.
Then what's the record in TFS?
Good question, aside from the headline they make no mention of any record being set! Neither does the blog post they cite. Perhaps the confusion somehow arose from their use of the word twice in other senses.
NB: As the same FAQ page you linked earlier points out, helicopter flight, as the project is attempting, is much more inefficient than winged flight. Human-powered flight with winged craft had already been achieved with fairly good results 20 years ago - almost 4 hours of flight covering 74 miles.
They don't do mondain and they don't do what's been done before.
I fail to see what the villain from Ultima I has to do with this...