Linux Commands You've Never Used
# lsof | grep TCP portmap 2587 rpc 4u IPv4 5544 TCP *:sunrpc (LISTEN) rpc.statd 2606 root 6u IPv4 5585 TCP *:668 (LISTEN) sshd 2788 root 3u IPv6 5991 TCP *:ssh (LISTEN) sendmail 2843 root 4u IPv4 6160 TCP badhd:smtp (LISTEN) vsftpd 9337 root 3u IPv4 34949 TCP *:ftp (LISTEN) cupsd 16459 root 0u IPv4 41061 TCP badhd:ipp (LISTEN)
Here's a short list of useful Linux shell programs, many of which you may have never known about. I've got a new favorite shell command, lsof (shown above), which displays information on every open file handle. - Link.
If I could add one to the list, it'd have to be the short and sweet command line search and replace using perl:
perl -pi -e 's/searchpattern/replacewith/g' *.html
Do you have a favorite command line secret? Please share it in the comments.
Posted by Jason Striegel |
Feb 25, 2007 12:30 AM
Linux, Perl |
Permalink
| Comments (6)
Recent Entries
- Poromenos' hello world curve
- USB CapsLocker and Sun keyboard simulation
- Robosapien has a coil gun
- Faster Windows shutdown
- Assign USB drives to a folder
- Little drummer bot
- CSS ad blocking for Firefox and Safari
- Design Coding: web standards rap
- Shredz64: Guitar Hero for C64
- BATMAN: adhoc mesh routing
Comments
Newest comments listed first.
| Posted by: A.Nonny.Mouse on February 25, 2007 at 8:26 AM |
This is probably a well known trick, but I like xargs.
It takes standard in and treats it as an argument to a command give in the args of xargs... So, for example, say you have a web directory tree with a mixed bag of php, html, css and xml files. If you only want to search for something in the php files you can do this:
find . -name "*.php" | xargs grep -i "special"
That'll find only the php files and grep them for special.
You could also pipe ps through awk and use xargs to kill all of a certain process...
But everybody probably already knew that.
| Posted by: jher on February 26, 2007 at 11:15 AM |
can't get something to unmount so you can restart autofs?
try this:
ps -ef |grep rpciod |awk '{print $2}' |xargs kill -9
This doesn't actually cause rpciod to die, it just forces it to release any stuck nfs mount points (in linux).
| Posted by: illovich on February 26, 2007 at 12:10 PM |
For the record (or for the mac users, I guess) I thought I would point out that the following from the page 10 linux commands also work in the Mac OS X terminal:
#3 bc
#4 split
#5 nl
#6 mkfifo
#8 col
and
#10 lsof
Additionally xargs is available as well (from the first tip).
| Posted by: LBonanomi on March 4, 2007 at 6:23 PM |
I'm begging you, please don't pipe grep out to awk. Awk can match patterns all by it's lonesome. In fact, if you find awk in a pipeline with cat, grep, tr, wc or sed you need to stop and re-think whats happening.
Awk handles files without a cat pipeline. Awk can make its own text substitutions with sub and gsub. Awk can count lines with 'END { print NR }'. If your version of awk doesn't accept environment variables (my old rationale for using grep | awk...) use:
eval awk '/$1/ { print }'
Awk may not have the horsepower of perl, but it can do a lot more than act as a heavier version of cut.
| Posted by: ctb on March 9, 2007 at 11:54 AM |
I always enjoy passing multiple files or directories with curly brackets. This is nice for changing permissions on a handful of items really quickly, i.e...
chmod 755 {file1,file2,dir1,file3}
Or for creating a handful of directories in one swipe...
mkdir {music,images,text,archive}
| Posted by: MCasillo on March 30, 2007 at 10:11 PM |
A.Nonny.Mouse - this will also work for your example :)
grep -i "special" *.html
Another neat shell trick for commands without an 'ignore case' command is to use bracketed 'sets' :
chmod all .Zip or .zip files
chmod 755 help.[Zz]ip
chmod all files named help.zip (or HelP.zIP, etc)
chmod 755 [Hh][Ee][Ll][Pp].[Zz][Ii][Pp]
chmod all files that start with the letter 's' but do not end in any form of zip:
chmod 755 [Ss]*.[!Zz][!Ii][!Pp]
Bloggers
Welcome to the Hacks Blog!
Categories
- Ajax
- Amazon
- AppleTV
- Astronomy
- BlackBerry
- Blogging
- Body
- Cars
- Cryptography
- Data
- Education
- Electronics
- Energy
- Events
- Excel
- Excerpts
- Firefox
- Flash
- Flickr
- Flying Things
- Food
- Gaming
- Gmail
- Google Earth
- Google Maps
- Government
- Greasemonkey
- Hacks Series
- Hackszine Podcast
- Halo
- Hardware
- Home
- Home Theater
- iPhone
- iPod
- IRC
- iTunes
- Java
- Kindle
- Knoppix
- Language
- LEGO
- Life
- Lifehacker
- Linux
- Linux Desktop
- Linux Multimedia
- Linux Server
- Mac
- Mapping
- Math
- Microsoft Office
- Mind
- Mind Performance
- Mobile Phones
- Music
- MySpace
- MySQL
- NetFlix
- Network Security
- olpc
- OpenOffice
- Outdoor
- Parenting
- PDAs
- Perl
- Philosophy
- Photography
- PHP
- Pleo
- Podcast
- Podcasting
- Productivity
- PSP
- Retro Computing
- Retro Gaming
- Science
- Screencasts
- Shopping
- Skype
- Smart Home
- Software Engineering
- Sports
- SQL
- Statistics
- Survival
- TiVo
- Transportation
- Travel
- Ubuntu
- Video
- Virtualization
- Visual Studio
- VoIP
- Web
- Web Site Measurement
- Windows
- Windows Server
- Wireless
- Word
- World
- Xbox
- Yahoo!
- YouTube
Archives
Recent Posts
- Poromenos' hello world curve
- USB CapsLocker and Sun keyboard simulation
- Robosapien has a coil gun
- Faster Windows shutdown
- Assign USB drives to a folder
- Little drummer bot
- CSS ad blocking for Firefox and Safari
- Design Coding: web standards rap
- Shredz64: Guitar Hero for C64
- BATMAN: adhoc mesh routing
www.flickr.com
|





Leave a comment