What's Your Command Line Judo? 272
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?"
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.
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:2, Informative)
Sorry to be picky, but Microsoft bought a license for UNIX from AT&T, developed Xenix, then sold it to SCO who would transform it into SCO UNIX.
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
Re:can't eat just one (Score:2)
Re:can't eat just one (Score:2)
If I want to remove every nautilus RPM in my system, what easier way then:
rpm -qa | grep nautilus | xargs rpm -e
pbcopy and pbpaste (Score:2)
Re:pbcopy and pbpaste (Score:2)
http://people.debian.org/~kims/xclip/ [debian.org]
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
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)
Re:cp -g (Score:2)
[rek@SigSeg:~] $ cp --version
cp (coreutils) 5.2.1
This is the version currently used by Gentoo.
[rek@SigSeg:~] $ cp --help
...
-g, --progress show a progress bar if operation is going to take a long time
...
I always took -g for granted, now I noticed that my openbsd box doesn't have it.
Re:cp -g (Score:2)
I checked linuxpackages.net, and found that this version is from Slackware 9.1 (current is 10.2), so it's pretty old.
Perhaps this is a new option in the nightly, or an unofficial patch?
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
Re:a funny Microsoft diff story. (Score:2)
Re:a funny Microsoft diff story. (Score:2)
There isn't one. My point was just that comparing diff to diff wasn't really comparing the same things. DOS just out and out lacks the functionality.
Re:a funny Microsoft diff story. (Score:2)
Heck, get familiar with it and you will be FTPing your files down to your DOS box just to diff them - it's that good.
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.
Re:CTRL + L (Score:2)
Re:CTRL + L (Score:2)
^D -- end of file, logs out of most shells, and exits programs looking for user input
^S -- stop terminal output (useful if you're watching make output and see something scroll by too quickly)
^Q -- resume terminal output. Before learning this one, everything I accidently hit ^S (save reflex), I had to kill the terminal
^Z -- suspend. Stops a foreground process and gives you your command line back. Useful for GUI apps you started without '&'. Also useful with the 'bg'
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:2)
Re:skill (Score:4, Informative)
pkill/grep are nice too, and are standard on a fair few systems now.
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.
Re:ls -d without the subcontents (Score:2)
Re:ls -d without the subcontents (Score:2)
Re:ls -d without the subcontents (Score:2)
Re:ls -d without the subcontents (Score:2)
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 -t | head (Score:2)
ls -rt
so they will appear last, near the prompt.
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.
Re:perl (Score:2)
Hun? `man perlrun` says -p overrides -n
I don't see how this will work. Either way, it would edit all files, not only the ones wich has the 'newip' string.
Re:perl (Score:2)
Perl / PHP is not a killer solution for everything. Particularly, if you use an embedded system that doesn't have php/perl installed, you'll find that bash/busybox is very much your friend.
That said, I love php and don't know that I'd do without it (aside from use bash for everything).
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:2)
Re:Junction for Windows (Score:2)
Now I use it all the time.
p.s. Did you spell "asinine" wrong on purpose?
Re:Junction for Windows (Score:3, Insightful)
UNIX Utils, Natively Compiled for Windows [sourceforge.net]
Re:Junction for Windows (Score:4, Informative)
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.
Buh? (Score:2)
$ find
Replace "-sm" with "-sk" if you want kilobytes instead of megabytes. Total space consumed by the named directory appears at the bottom of the list.
Re:Buh? (Score:2)
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
rsync (Score:2)
I use it to update my web site. I use it to synchronize bookmarks between multiple machines. I use it for online incremental backups. I use it to copy directory trees around from disk to disk.
I even use it to fetch my mail. Yes, I switched my mail account to Maildir by using procmail for final delivery, and now I can use rsync -avz --remove-sent-files instead of crappy POP3 or IMAP protocols to pull the mail do
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:2)
Hi screen brother. :) I live and breath screen -- I sometimes open multiple windows to the same screen session, but different 'screens.' I've also changed the MAXWIN value from 40 to 60 before compiling because, well, 40 screens just isn't enough.
I had one screen session up for almost a year, which would've been longer but I upgraded my kernel.
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.
find . -name '*.ext' |xargs grep -i bar (Score:2)
finds all the files having the extension 'ext' and matching the pattern 'bar'.
Re:find . -name '*.ext' |xargs grep -i bar (Score:2)
Re:find . -name '*.ext' |xargs grep -i bar (Score:2)
Just use -exec. It's slower, but easier and you don't have to fight with line-endings, spaces in the filenames, and stupid cli arg limitations.
the one that impresses most people (Score:3, Interesting)
Re:the one that impresses most people (Score:2)
find . -type f |grep '.thumb.gif'
Okay, then I can eyeball the result and check it. Pipe it to less if necessary. Then up arrow and append:
find . -type f |grep '.thumb.gif' | while read FN ; do echo "$FN"... ; rm "$FN" ; convert -geometry 200 "$( echo "$FN" | sed 's/.thumb//' )" "$FN" ; done
I make no claim that this is better, it's just what rolls off my fingertips when working on mass groups of files. One nice thi
Re:the one that impresses most people (Score:2)
Re:the one that impresses most people (Score:2, Informative)
Re:the one that impresses most people (Score:2)
find . -type f -print -exec grep regexp \{} \;
Re:the one that impresses most people (Score:2)
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.
Re:xargs and for loops (Score:2)
Just because you think globbing on the commandline is stupid (and I don't neccesarily agree with you, but I haven't really thought through all the ramifications of ydoing it your way yet) doesn't make it go away. That being the environment we're dealing with on standard unix shells, xargs is a big win for dealing with that environment. Write us a new shell and a new set of the standard commandline binaries that does everything your way, or deal with the status quo like the rest of us
Going waaaaay back here ... (Score:2)
Re:Going waaaaay back here ... (Score:2)
Of course, by the time I finally got rid of that old machine, I had flopply controllers in slots 6, 5, and 4. ProDOS made handling multiple disks a breeze. Printers were on 7 and 1 (one for labels, the other for regular), mouse on 2, and a 64 KB RAM expansion
To add to all the others (Score:2)
du -sh *
Probably best to put this in your
alias diskusage=`du -sh * && du -sh
(I know this can be shortened with regular expressions, but I've never looked into it)
Anyway, if need be, pipe that to a "sort"-on-steroids and you can see where your disk space is getting eaten up.
Re:To add to all the others (Score:2)
du -h --max-depth=1
for profiling disk usage quickly
fastest shutdown or restart command for Linux (Score:2)
shutdown -hn now (for halt)
shutdown -rn now (for restart)
I call this my "Express Elevator to Hell: System Goin' DOWN!" command. [Somebody wake up Hicks.]
There are a few, I guess (Score:2)
sort -n
grep is an amazing tool.
ssh is a pipe, too (from linux.com) (Score:2)
tar cf - * | ssh user@system " cd ; tar xvf - "
Conversely, from remote to local:
( ssh user@system " cd ; tar cf - * " ) | ( cd ; tar xvf - )
Add a "-C" to the ssh commands for compression.
scp is your friend (Score:3, Informative)
scp -C -r * user@system:target
and
scp -C -r 'user@system:/target/*' .
Re:ssh is a pipe, too (from linux.com) (Score:2)
But I've certainly used the tar over ssh method a few times, and I will be using it again soon for a nightly build install to a remote machine (cat tarball | (ssh rmachine tar -C / -x -f -))
make yourself a few aliases (Score:2, Informative)
alias ff='find . |grep -i '
>ff foo
./somedir/somethingfoo
./somedir/something foo2
./somedir/somethingfoo3
Need to find that pesky configuration file for printer?
~/bin/gr:
grep -i -r $1
~/bin/fgre:
grep -i -r -l $1
>cd
>fgr laserjet
./cups/ppd/hp.ppd:*ShortNickName: "HP LaserJet Series"
Just interested which files to check?
>fgre laserjet
./cups/ppd/hp.ppd
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. :-)
abcde (Score:2)
Aieeeee! (Score:2)
No, no we don't.
Deleting files with untypable characters (Score:2)
ls -i
find . -inum inode -exec rm -i {} \;
The ls -i gives you the inodes for all the files in the current directory. Find the inode for the file you can't delete, then use that in the find command to actually select it and delete it wit
Re:Deleting files with untypable characters (Score:2)
here's one back a ya
Files with a leading "-" often give me fits, for example...
ls -- -*
-- generally 'means no more args'
I can't believe no one mentioned it... (Score:2)
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
Re:Looking around. (Score:2)