74 Comments
- snurfle, on 10/12/2007, -0/+24So let me get this straight...
You went into the Linux/Unix topics so you could bury comments and articles about Linux/Unix?
What the ***** is wrong with you? - jstevewhite, on 10/12/2007, -0/+17"Just for the record, I've buried every other post in this thread.
I've buried the article as well.
"
Idiot. - markr, on 10/12/2007, -1/+16it's interesting - but more "tips" than "good habits"...
- BigSlacker, on 10/12/2007, -1/+15One cool shell features that doesn't get used that much is pushd and popd.
% pushd /some/directory
Now in /some/directory
% pushd /another/directory
Now in /another/directory
% popd
Now in /some/directory
% popd
Now in original directory
You can also use pushd without any options and swap back and forth between the top two in your stack. - negativefx, on 10/12/2007, -3/+15regardless....good resource.
- l0ne, on 10/12/2007, -3/+13It works without the z but does not compress with gzip, therefore making the extension wrong (it should be .tar rather than .tar.gz).
- Schpariel, on 10/12/2007, -1/+111) This article is in the unix/linux section, get out if you don't like it
2) Enough with the anti-unix *****, digg wouldn't even exist without unix
3) You don't have to tell us that your pathetic OS is better than X OS. What a typical windows-fanboy/troll
I'm going to bury you, block you and I'll proceed to digg up every comment except yours on this page just to piss you off. kthxbai - MikeDawg, on 10/12/2007, -0/+9It is kind of both. I always pipe cat'ed text when I don't have to, as the utility I'm piping stuff to doesn't have to read form stdout; its one of those forces of nature. Talking a matter of milli-seconds is not, and has not ever been a concern to me.
It always drives me nuts when I'm explaining to someone the process of what I do, and they bitch and moan that I cat something, when it doesn't have to be cat'ed.
The other thing I always do, is with awk (gawk and all the other clones) is always use the -F flag, even if I want to use a space as a delimeter. While typing the -F flag is unnecessary when using a space as a delimiter, I always have done it, and I probably will always do it.
Old habits die hard, and if there isn't something more compelling to me than .001 seconds, then I'm not going to change my old ways, that I can type very quickly.
However, the mkdir -p command actually saves a fair amount of time, and it is something that I highly recommend people to get in the habit of using when creating any size of directory "tree" structure. - felis, on 10/12/2007, -1/+9Yeah, definitely more tips than habits - they're good timesavers.
Although I wouldn't pipe find to xargs, I would use -exec - although I suppose there's probably a situation or two that xargs would be better, I just can't think of one offhand. - BxBoy, on 10/12/2007, -0/+8I do.
- MikeDawg, on 10/12/2007, -0/+8Actually there is a good reason to use xargs instead of using the standard find -exec, I mean for one, I find typing a pipe easier to type than remembering the structure of the exec command, and closing curly braces and semi-colon.
The other big reason and the main reason to use xargs is because every file -exec finds it executes your command, whereas xargs will group in bunches and therefore execute a fewer number of times, and it is actually a true time saver, and not just by a matter of milliseconds. - webgeek2point0, on 10/12/2007, -0/+8I found another mistake by the author too. Under Quote Variables with caution:
"enclose the variable name in square brackets ([])"
Then he goes on to show us in his example:
~ $ echo "${VAR}a"
tmp/*a
~ $ echo ${VAR}a
tmp/a
Using curly braces. Why don't people proofread their articles any more? I find mistakes like this all the time, even on big sites like CNN. Drives me crazy. - jasz, on 10/12/2007, -0/+8new stuff i didnt know of...dugg
- bart9h, on 10/12/2007, -0/+8Mkdir does not "support" syntax like project/{lib/ext,bin,src,doc/{html,info,pdf},demo/stat/a}
It's the bash shell that does it.
Try this command:
echo project/{lib/ext,bin,src,doc/{html,info,pdf},demo/stat/a}
and you will see. Bash makes the substitution, then passes the result to the command. The same goes for "rm *" and the like. - PleaseJustDie, on 10/12/2007, -1/+8I tend to pipe find into grep. Usually I'm looking for some config file or another and have no clue where its hiding. i.e. find /| grep "somefile"
Probably a crappy way to do it, but it was the easiest way I could get the output I wanted from find without actually digging through the man find to figure out how to make it do what I wanted. - inactive, on 10/12/2007, -0/+7foad
- dbr_onix, on 10/12/2007, -1/+8Err.. okay? Arrogent/obnoxious anti-'nix idocy aside, you do know you can disable certain sections from showing via your profile? ( http://digg.com/users/ItchyMcknobster/profile )
[merr] "Piping cat to grep.... who does that?"
Me, I find `cat [file] | grep something | grep something | grep else` easier than doing long complicated single grep commands, which take far longer than the 0.05 seconds gained from not piping cat
"This should be on slashdots front page, not diggs." Quite the oposite, Slashdot is a news site, Digg is just an "interesting content" site. My new favourite link for disproving "DIGG IS A NEWS SITE! THIS SHOULDN'T BE ON IT" : http://www.digg.com/about
- Ben - jstevewhite, on 10/12/2007, -0/+6Here's the problem I have with that... I got into the habit of zvxf; problem is that it KILLS you on a remote serial terminal (say, a terminal server @9600bps console to a Sun box); it takes a LOT longer than zxf... A tip: When you don't actually NEED to see the contents of the archive as it unzips, leave out the -v; it's a *lot* faster, even locally.
- Markie1006, on 10/12/2007, -0/+6It's also good habit to always add the '-' in front of the options.
'tar -zxf'
Not every system you work on will be using gnu tar. - jstevewhite, on 10/12/2007, -0/+6@felis
What he's saying is that most external unix commands have a limit to the number of filenames they can accept on the command line. For example, 1024 is a common number. So if rm can only handle 1024 input filenames, we can use xargs to rm a directory with 4096 entries; we do the ls | xargs, right? That invokes rm 4 times, each time with 1024 arguments. Find -exec, on the other hand, invokes rm 4096 times with 1 argument each time.
Make sense? - bart9h, on 10/12/2007, -0/+6@MyKungFu: If you suspect the command output can be lengthy, you can add a "| tail" or "| head" (depending if you want to see the beginning of the end of the text). It won't hurt if it will have few lines. Use "head -20" to increase the default 10 lines.
- EgoDemens, on 10/12/2007, -0/+6edit: jstevewhite got to it first.
just like to add you can use * like: "somefile*" - jstevewhite, on 10/12/2007, -0/+6@PleaseJustDie
I used to do it that way, too; however, it's worth it to learn how to use the different selection criteria for find; it becomes a much more powerful tool. You can select by size, by permissions, by age... you name it. It's awesome. Incidentally, you're looking for -name or -iname when you do find ./ | grep "somefile" (that is, 'find ./ -name "somefile") - merr, on 10/12/2007, -2/+7Piping cat to grep.... who does that?
- NTolerance, on 10/12/2007, -1/+6Maybe I'm just not l33t enough with UNIX, but I'd rather do a step-by-step file extraction and prevent my head from exploding than to put in a huge syntax like this:
cd tmp/a/b/c || mkdir -p tmp/a/b/c && tar xvf -C tmp/a/b/c ~/archive.tar - MikeDawg, on 10/12/2007, -1/+6I always do it, and will probably continue doing it. It's a force of habit.
- bart9h, on 10/12/2007, -0/+5Other nitpick, about the tar -C thing: it's simpler (as in "one less argument to memorize") to go to the dir you want to extract to, and type:
tar xf /other/dir/archive.tar - MyKungFu, on 10/12/2007, -0/+5I'm a unix noob, so I'm probably missing something, but a lot of times I cat something, and it returns a whole bunch of data, then i type "up arrow" and then add a grep at the end.
If I knew the "cat something" was going to return too much data i would just grep it to begin with and omit the cat.
How are you supposed to know before you run the command how much data it is going to return? How can that be a bad habit? - KennMac, on 10/12/2007, -2/+7"tar xvf -C tmp/a/b/c newarc.tar.gz"
It's an even better habit to use the correct switches.
Surely the author means "tar zxvf -C ...." - KennMac, on 10/12/2007, -0/+5"When you don't actually NEED to see the contents of the archive as it unzips, leave out the -v; it's a *lot* faster, even locally."
That restraint is of course directly related to what you're untaring and your connection speed. - kitykity, on 10/12/2007, -0/+4I noticed the curly brace too... my Unix mind hit it... and stopped... and said... ???
- kremvax, on 10/12/2007, -2/+6"Probably a crappy way to do it"
Not at all, actually. The more you use grep, the more uses you find for grep.
Being comfortable with one of the most powerful command line tools ever is a great habit to be in. - jBullfrog, on 10/12/2007, -1/+5just in case anyone inexperienced with *nix is wondering what the command in the above comment does... it removes every file that you have access to from the system. do not try.
rm means remove file
-r option means recurse into child directories
-f option means force (won't ask if you really want to do it i.e yes/no)
I'm sure theres a better way to explain this... - MrDiggDugg, on 10/12/2007, -0/+4Another tip:
"alias" is your friend. You can alias 'shorthand' mnemonics to commonly used commands:
ex:
alias ls='ls -ltr'
More examples:
http://linuxboxadmin.com/articles/daily-aliases.php - burke, on 10/12/2007, -0/+4Hardly. I found it very interesting. If all you have to contribute is that you found the story boring, maybe you should take your comments to a different section of digg. I hear "comedy videos" is pretty entertaining.
- bart9h, on 10/12/2007, -0/+4Also, the find | xargs thing doesn't work when you have spaces in file names.
Try `find -print0 | xargs -0` for that.
Check the man pages of find and xargs for details. - felis, on 10/12/2007, -1/+5Not sure I get what you're saying, MikeDawg - xargs groups in bunches? How is the logic different?
Maybe it's the lack of coffee up in my brain, but I thought they were more or less the same, except you're spawning a new process for xargs and not with exec. - Markie1006, on 10/12/2007, -0/+4Those milliseconds add up - especially if you're having to process huge files (I'm talking hundreds of gigs, up to tb sized)
- PleaseJustDie, on 10/12/2007, -0/+3Thanks to everyone about the -name and -iname.
- LabThug, on 10/12/2007, -0/+3I once encountered a case where I had to `cat | grep` I needed to find a line in a 13GB text file (yes, 13 f'ing GB). I quickly found out that grep pukes on files greater than 2GB (or was it 4/8?). However, the same program works perfectly fine when I piped from cat first.
I don't know why on an operating system that claims "everything is a file" would the file not work and the piping would. I'm curious now, but at the time, I was too busy fixing what was wrong with that line to care. - MrDiggDugg, on 10/12/2007, -0/+3"I tend to pipe find into grep. Usually I'm looking for some config file or another and have no clue where its hiding. i.e. find /| grep "somefile""
Two alternatives. Many systems maintain an active "slocate" database -- so you can just type "locate somefile"
If that's not an option:
find . -name somefile - BigSlacker, on 10/12/2007, -0/+3Cool, I didn't know about that one. It looks like it's only bash and tcsh and not on csh. The OLDPWD variable looks like it's bash only.
- subgeniusd, on 10/12/2007, -0/+3That "stranger" sounds like i440''s little brother.
This ended up way off the comment I responded to. - ricce, on 10/12/2007, -0/+3find can be used in many ways:
$ find . -type f -exec echo "{}" ";"
Will exec echo one time for each regular file in the current directory and any subdirectories.
$ find . -type f -exec echo "{}" +
Will exec echo exactly one time with all files in the current directory and any subdirectories.
To mach filenames:
$ find . -iname "*some*"
(or)
$ find . -name "*some*"
-iname for case insensitive match, and -name for case sensitive match..., they will match the whole and exact filename if you don't add joker * - felis, on 10/12/2007, -0/+3@jstevewhite:
Yep, that makes perfect sense; I guess it's the "grouping" terminology that got me.
I've been bitten by that before, and had I thought to use xargs instead of an overly complicated while loop, I might have saved myself a few minutes.... - Brobdingnagian, on 10/12/2007, -1/+4Blocked...
Wish you used your efforts for good. - skymt, on 10/12/2007, -0/+3The z flag really is unnecessary if you're just e(x)tracting a .tar.gz archive. All tar implementations I've used automagically use gzip decompression if tar recognizes the archive as being gzipped. -z is only used if you're (c)reating a new archive, or if the tar automagic fails (I think it depends on the extension).
- seuaniu, on 10/12/2007, -0/+3Here's one that I use:
alias screensaver='rain -d 20 && vlock'
Whenever I need to go get coffee, i can lock my screen using that, and have a nice text-mode screensaver.
obviously, that requires the rain and vlock commands, which aren't always on default install anymore.
EDIT: for those that don't know, you can put these aliases in your ~/.bashrc and have an entire repository of custom commands at your disposal - underthelinux, on 10/12/2007, -0/+3I think the "habit" is just reducing potential errors. I think that's what the author is getting at. But agreed, definitely 'tips' is an accurate word for what is posted.
- meBigGuy, on 10/12/2007, -0/+3 alias mc mv
-
Show 51 - 74 of 74 discussions



What is Digg?
Browsing Digg on your phone just got easier with our enhancements to the