What's Your Command Line Judo?
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?"
foad works every time.
Trolling is a art,
My favourites are
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
Daily News http://newsblaze.com
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
I don't know how much information your script gives, but cp -g gives you a progress bar, transfer rate, completion percentage and other stuff when a transfer is going to take more than a few seconds (similar to what scp gives you). It's sometimes a handy feature to have, sounds like what your script is doing...
-ReK
md5sum -c reality.md5
reality: FAILED
md5sum: WARNING: 1 of 1 computed checksum did NOT match
Every person I see using linux clears the screen by typing CLS. The key combo "CTRL + L" is so much sexier.
Hacker Media
I'm not much of a linux guru, so my favorite is simple.
skill
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.
The ______ Agenda
I never figured out a way to use 'ls' to show only directories (and not their subcontents), so I created an alias called 'lsd':
.bash_profile
alias lsd='\ls -l | grep "drwx"'
and placed it in my
It's quite useful, but it doesn't work well with shell scripts.
Don't think that a small group of dedicated individuals can't change the world. It's the only thing that ever has.
First, I must comment the article. Question goes What little known command performs just the right function for you? I hope all sane people here (haha) would answer "None". There's no command that does just the right function since there's no one The Function. It depends on the situation what the function is. And in that case, per Unix philosophy, where one tool does one simple job, but does it well, you should choose the tool accordingly.
/etc to this new IP address. First you might think searching all the files under /etc with find(1), then passing the list of files to grep(1) and then manually editing the places where the old IP address was found with your $EDITOR. That's fine and will get the job done and all but what if you could just edit the files in place? With perl, you can.
/etc -type f`
:)
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!) 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
Justifies nicely said paragraphs; provides lists and sigart.
Junction lets you make symlinks in Windows without installing the entire Windows Resource Kit tools. Also, CACLS.EXE for changing ACLs in Windows via the command line, since I have no fucking clue where you do this in the GUI. Some of the more usefule CLI commands in Windows, IMO. I hope this discussion wasn't limited to Unix or anything.
in bash:
;
/home/
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.
perl -pi -e "s/x/y"
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
ls -t | head
This is nice for listing the 10 most recently modified files. Usually the one you want is the first or second one.
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
Multiple multiplexed ttys that stay running even after disconnect and you can reattach to them later.
If you reply, do so only to what I explicitly wrote. If I didn't write it, don't assume or infer it.
7 November 2006: The day Americans realized corruption and incompetence weren't addressing 11 September 2001
That's the Technical Fascist's .cshrc.
t ml
http://www.gnu.org/fun/jokes/know.your.sysadmin.h
-jpeg
Based on the rsync protocol, unison can maintain a bi-direction file sync. I use it to sync my personal data between home and co-lo'ed server, and work and co-lo'ed server. I can update files in any of the three locations and they'll be replicated across all three.
-buf
There's millions of tricks, but if I had to a couple simple powerful techniques that anyone should learn that doesn't know them already, it would be xargs and commandline "for" loops.
.o files anywhere underneath the current directory. However, if there are too many .o files to fit on a single commandline, it will barf with "argument list too long" or some such sounding error. The xargs way to do this would be:
...
...;rcp $fn remotehost:/tmp/;done
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
11*43+456^2
Need to find that file named somethingfoosomeotherthing?
g foo2
/etc/
alias ff='find . |grep -i '
>ff foo
./somedir/somethingfoo
./somedir/somethin
./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
'mc' is your gateway to a much more powerful shell. Combine your command line shell with quick changing to bookmarked dirs (ctrl+\); easy adding to that via alt+a; F2 menus that let you easily compress subdirs, or run other things from your actions file based on the mime-type or file pattern; two-panes at two different FS locations; undelete FS, FTPFS, and other meta-FS interfaces; good mouse support; built-in editor (Cool edit); prompts you for arguments for makefiles you hit enter on...
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!
--
Internet Explorer (n): Another bug -- that is, a feature that can't be turned off -- in Windows.
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. :-)
scp -C -r * user@system:target
and
scp -C -r 'user@system:/target/*' .
There are places where the networks are not touching,and there are places where they are-Boeing's Lori Gunter
Yea, Though I compute through the user interface of the shadow of death, I shall fear no evil, for ZTree is with me.
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 Don't leave $HOME without it.
Glonoinha the MebiByte Slayer
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.
Dewey, what part of this looks like authorities should be involved?
Hello Robert.
.cshrc, I have this:
.cshrc and it will work for just that session.
My name is Alan, no reference to Tron
in my
alias lh "ls -lt !* | head -15"
alias lt "ls -lt !* | more"
alias hog "ps -eo pcpu,vsz,args,time | sort -rn | head -11"
alias ff "find . -name !* -print"
I use these and many more when I'm working on the newspaper.
You can type these aliases on the commandline if you don't want to add them to your
So then I type lh in the CLI and it shows the newest 15 files - you can change that number to whatever you like.
Daily News http://newsblaze.com
...but it's limited to JP Software shells (4DOS, 4NT, 4OS2), and the authors of Linux shells don't seem interested in implementing it.
.ZIP files as potential targets.
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
Mainframe/UNIX Bit Twiddler and long time Windows/Linux Hobbyist.
The Theorem Theorem: If If, Then Then.