Slashdot Log In
What's Your Command Line Judo?
Posted by
Cliff
on Sat Oct 01, 2005 05:55 PM
from the |-ownz0r dept.
from the |-ownz0r dept.
lousyd asks: "We all have our CLI amor. That two- or three-letter command that fiddles our heartstrings. 'mv' is pedestrian, but 'mmv' is so cool. 'cp' can lug bits around all day to no applause, but 'cpio' will excite even the most jaded of command line linguists. 'How perfect!' you exclaim. So what's your poison? What turns you on? What little known command performs just the right function for you?"
This discussion has been archived.
No new comments can be posted.
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
Full
Abbreviated
Hidden
Loading... please wait.
hrm. (Score:2, Funny)
foad works every time.
ZTree and UnixTree (Score:4, Interesting)
No joke - ZTree is a character for character re-write of an old utility called XTree Gold v2.0 or 2.5 - and it is by far the most effective and influential interface between me and my data. The entire file system is but an extension of my mental processes, and I can slice and dice through the multi-dimensional (time, space, attributes, multi-layered directory structure, multi-drive architecture,) in effect creating a virtual directory within which I control the parameters driving what is listed, in what order - then copy, view, move, delete, diff (file compare), view in hex mode (and edit it in hex mode), search for text in lists of files, compare directory trees for like or different files (binary, time stamp, etc.)
It is totally CUI, about like Midnight commander but a ton better. Take time to get fluent in ZTree (UnixTree for Unix / Linux, a bit older with a few quirks, but still pretty damn good) and you will be like the guys in the Matrix sitting at their green screen terminals.
ZTree [ztree.com] Don't leave $HOME without it.
Parent
Re:ZTree and UnixTree (Score:3, Interesting)
And I got excited about TC - but alas it is mouse clicky centric. ZTree was designed and implemted to be 100% character based (although I guess you could use the mouse, I haven't actually tried.)
When you can use TC to find the files located somewhere on your hard drive, directory unknown, name unknown, extension unknown, dated somewhere around Christmas of 2003, containing the phrase 'Total Commander' but not c
lh and hog (Score:4, Informative)
lh ls -lt !* | head -15
which shows me the newest 15 stories in the current or specified directory
hog "ps -eo pcpu,vsz,args,time | sort -rn | head -11"
which shown the 10 most cpu-intensive processes
can't eat just one (Score:5, Informative)
Command line judo? Sheesh! Where to start?
Okay, the tool I'm using now: vim, derivative of Bill Joy's vi, with color syntax and a bounty of enhancements. (Yes, I prepare my comments in vi, then cut and paste, don't even try to make me use some GUI text widget editor and claim it can be productive.)
And then there's:
find mystring *.*
and literally got back:
mystring found in *.*, and then a listing of all the lines found. No reference to the files they were in... Shit, after all, I asked to find the lines in '*.*'.
I complained. They showed me their (Microsoft's purchased from IBM) unix, "xenix", and their "grep" command. Ahhhhh, better. I typed: grep -i mystring *.*
and it replied "unknown option -i". I complained about not having an "ignore case" option. They looked at me like I was crazy... "Why would you ever want to ignore case?"
I could go on, and probably will in some subsequent posts. When you have so many well written, well evolved, well crafted, and well behaved tools all flying in
Re:can't eat just one (Score:3, Interesting)
I don't mean that I was looking for a single command; I use bash pretty hardcore, and I've used pipes to do some pretty extensive things - that's where I think history has it's greatest use.
(and yes, I'm using bash 3 and my HISTSIZE envvar is set to 1000
pbcopy and pbpaste (Score:2)
Here's mine (Score:5, Funny)
Give credit where credit is due (Score:5, Informative)
http://www.gnu.org/fun/jokes/know.your.sysadmin.h
Parent
cp.php (Score:2)
I found this little php script called "cp.php" which I renamed pcp and use for mundane cp whenever I'm in a tty and hafta do lotsa copying. It gives lotsa info about progress of copying and such, which I really like compared to the rather spartan cp function. It may be somewhat superfluous, but it's nice eye candy in a bash, and nice for moving lotsa big files.
Someone with more Google skills than I might be able to find it online. I got it from sourceforge originally, but it doesn't seem to show up in thei
cp -g (Score:3, Informative)
-ReK
Re:cp -g (Score:2)
Re:cp -g (Score:2)
a funny Microsoft diff story. (Score:2)
I was on a special project, tucked away in a secret office in Seattle. We were creating a workbench of sorts using one of the very first PC networks in our company (it was 1986). Five of us created hundreds of files and thousands of lines of code and balanced version control ad hoc and on-the-fly. The project was a success.
One day though, I'd transferred an image of our work from one machine to another. When I "ls'ed", oooops, I mean "dir'ed" the directory structures on the two machines they did not ma
CTRL + L (Score:3, Insightful)
Re:CTRL + L (Score:3, Interesting)
I wish the behavior was the same in bash, but for some reason they chose to make it clear the screen instead.
skill (Score:3, Insightful)
skill [about.com]
s-kill, basically, kills a process by name. "skill netscape" will kill netscape, no finding proc ID required. It's what kill should have been from the beginning.
The only command I love more than skill is apt-get, but that doesn't really count.
Re:skill (Score:2)
Re:skill (Score:2)
Oops... I forgot my html tags =[ Shoulda been:
man skill : skill, snice - send a signal or report process status
There's also:
man killall : killall - kill processes by name
I got annoyed by having to find the proc ID in top too, and stubled across killall. Haha =]
Re:skill (Score:4, Informative)
pkill/grep are nice too, and are standard on a fair few systems now.
Parent
Just the right command? (Score:2)
What little-known command performs just the right function for me?
strip, of course.
Re:Just the right command? (Score:2)
# unzip
# strip
# touch
# finger
# mount
# fsck
# more
# yes
# umount
# sleep
for the gamut of unix double entendres...
ls -d without the subcontents (Score:3, Informative)
alias lsd='\ls -l | grep "drwx"'
and placed it in my
It's quite useful, but it doesn't work well with shell scripts.
Re:ls -d without the subcontents (Score:5, Informative)
ls -d */
The final slash is key.
Parent
Re:ls -d without the subcontents (Score:3, Informative)
What if a file has the string "drwx" in it?
And you forgot about dot directories.
ls -t | head (Score:3, Interesting)
This is nice for listing the 10 most recently modified files. Usually the one you want is the first or second one.
Re:ls -d without the subcontents (Score:3, Interesting)
'-F' shows a slash after each entry that's a directory, an asterisk after each executable, and some other things. Read the man page for 'ls' sometime, it's like a whole freaking operating system.
NAME
ls - list directory contents
SYNOPSIS
ls [-ABCFGHLPRTWZabcdfghiklmnopqrstuwx1]
By the way, my favorite script fu is `du -sh
The best is (Score:2)
perl (Score:5, Insightful)
Enough of that. If you really must name something, then, in my opinion, there's one gizmo above others. And that is
perl
Perl one-liners is a damn powerful concept when you get it. Say one of your boxen switches IP address. You want to replace all references in files under
perl -pne's/oldip/newip/g' -i `find
and you're done (better be extra careful with commands like that for obvious reasons!). Of course you're able to do the same thing with other tools too, but I don't think it could be much easier than that. And naturally you're not just limited to simple search and replace of text, you have the full power of Perl (and CPAN [cpan.org]!) at your disposal.
Besides being my number one choice for creating complex scripts and small applications, Perl has very special place in my command line toolbox just next to the old friends such as grep(1), cut(1), wc(1), etc. and a huge pile of pipes
Re:perl (Score:3, Interesting)
I use this all the time:
$ perlrename -e's/.\[www.descargasweb.net\]//' *
$ perlrename -e's/.\[www.\S+?\]//' *
$ perlrename -e'$_=lc' *
$ perlrename -de's/Sex And The City - S(\d+)E(\d+)/SATC - $1$2/ig' Sex*
etc etc
where perlrename is a 30-something perl script.
groff (Score:2, Interesting)
Justifies nicely said paragraphs; provides lists and sigart.
Junction for Windows (Score:4, Informative)
Re:Junction for Windows (Score:3, Informative)
It shouldn't be. Another source of good command line tools is sysinternals.com.
The pstools let you do all kinds of nifty things that are sometimes covered by RK utils, but the sysinternals stuff is usually way better...
Re:Junction for Windows (Score:3, Insightful)
UNIX Utils, Natively Compiled for Windows [sourceforge.net]
Re:Junction for Windows (Score:4, Informative)
Parent
dusort (Score:3, Informative)
function dusort ()
{
du -s "$@" | sort -r -n |
awk '{sum+=$1;printf("%9d %9d %s\n",sum,$1,$2)}'
}
in tcsh:
alias dusort 'du -s \!* | sort -r -n | awk '"'"'{sum+=$1;printf("%9d %9d %s\n",sum,$1,$2)}'"'"
The most common way to use those commands would be:
cd
dusort *
It's useful for tracking down what's using up your space, for example finding a sub directory deep in a source tree that isn't cleaned by make clean.
hmm... (Score:3, Informative)
ever had to make a change to every line in a test vector (up to several million lines long), but didn't have the half hour it would take to retranslate the whole thing? - has saved my ass more than anything I can think of
also fun to do something like
perl -pi -e "s/(alias \w) \'.+\'/$1 \'echo \"DFU DFU DFU\"/g ~user/.aliases
We're not talking about cool commands, here! (Score:3, Informative)
Here's something that I run via cron on a nightly basis. See if you can decode its function :-)
for F in $(find $SRCDIR); do echo $(basename $F) $F; done | sort | rev | uniq -c -f 1 | grep -E ^[[:space:]]*1[[:space:]] | awk '{print $2 " " $3}' | rev > $CACHEFILE
screen (Score:5, Informative)
Re:screen (Score:3, Informative)
Example:
The complex task continues to run in the background; though the output will be lost to /dev/null unless redirected.
the one that impresses most people (Score:3, Interesting)
unison (Score:3, Interesting)
-buf
xargs and for loops (Score:5, Informative)
xargs takes whatever is piped into it, and executes a command with those things as arguments. It can do it all at once, or it can break them up in chunks, or it can execute your command once per input. Consider:
rm -f `find . -name "*.o"`
This normally works fine, and will forcibly remove all
find . -name "*.o" | xargs -n 50 rm -f
Which will execute a seperate "rm -f" for each chunk of 50 filenames. Take a look at the "-i" mode as well, read the whole man page. It's a great little peice of glue.
On to for loops. You've seen them in sh/ksh/bash shellscripts like so:
for fn in *.c
do
echo Sending $fn
rcp $fn remotehost:/tmp/
done
You can of course do this straight from the commandline, which is indispensable for complex looped operations. To do it all in one line, you just have to get the semicolons in the right place. Just remember there's a semicolon before the "do", but not immediately after it:
for fn in *.c; do echo Sending $fn
Re:xargs and for loops (Score:3, Interesting)
Oh a couple more good simple ones popped into my head for beginners:
Use "&&" between commands, and the second command will only execute if the first command succeeded. For example:
make && make install
That will only run the "make install" if the "make" succeeded (which is kinda contrived, since for most packages a simple "make install" would have done the same all on it's own).
And also, did you know that you can group commands with parentheses, and you can pipe into parenthesized groups of c
You are frickin' insane. (Score:5, Insightful)
That's great. Now, create a directory called " " (empty space). Inside that, create a directory called " -rf " ("-rf" with an empty space on either side). Inside that, create a file named " " (yet another empty space). Now, watch in horror as find prints "./ -rf /", which it passes dutifully to "rm -f". Since xargs by default passes each word as an individual argument, that expands to:
Hope you weren't running as root! The moral of this story is to never, never! use find/xargs without the "-print0" option whenever the command you're executing is destructive. "ls" is probably OK. "rm" definitely isn't.
Parent
Midnight Commander. (Score:3, Interesting)
The list goes on. Midnight Commander is a shell designed to speed up all your common tasks. It has sane defaults you don't really have to change much. It'll make you more productive!
Re:Midnight Commander. (Score:3, Informative)
Not to mention, it's really useful for temporary (ie. until you can reinstall) cleanups of compromised systems, since (a) it uses its own internal code for things like ls, chmod, etc, and (b) rootkits don't generally replace it :)
My favourites (Score:3, Informative)
strace/truss/ktrace for Linux, Solaris and BSD/MacOS respectively. If a program fails to start, or terminates abnormally, this will usually give me the heads up on why (it's usually a missing file, or bad permissions) without having to break out gdb.
lsof. Useful in so many ways; for debugging situations similar to the above, as well as hardening systems and building chroot environments for specific programs.
tcpdump/snoop/tethereal/ethereal. If you can see what's really on the wire between two network applications, you can probably figure out what's going wrong. Ethereal is particularly nice.
hexdump/khexedit. If you can see what's really in the file used by an application, you can probably figure out what's going wrong. :-) khexedit also has a bonus feature of being able to perform statistical logical operations across the file; useful if you have a file which you suspect has been encrypted with some lame substitution cipher.
After those, the usual - sed, awk, grep, find. It's rare that I can't turn any problem into an awk-shaped nail. :-)
I love the SELECT command... (Score:3, Interesting)
SELECT is a command which provides a fullscreen point-and-shoot file selection interface for other commands, allowing for the easy arbitrary selection of target files (point-and-shoot) in command aliases or batch/script files. In essence, it provides a mini filemanager interface which can be used to select the targets for *any* command on the command line, used in aliases, etc.
Some simple examples (from my 4OS2 alias file) are as follows:
TCOPY=select copy (*.*) %1
TMOVE=select move (*.*) %1
TDEL=select del (*.*)
TRUN=select %1 (*.*)
TEDIT=trun fte
TLIST=trun list
UNZ=f:\unz.cmd
TUNZ=select unz (*.zip)
The filespec in parenthesis limits the files which appear in the selection list, so the TUNZ command will only show
scp is your friend (Score:3, Informative)
scp -C -r * user@system:target
and
scp -C -r 'user@system:/target/*' .