Search:  

 
 
   All ForumsHot TopicsGallery






how-to block ads


 
Forums » Tech and Talk » OS and Software » All Things Unix » Little Known Tips and Tricks...
Uniqs:
29485
Share Topic:
RSS topic:
toggle:
flat / full
normal / watch
Posting:
Post a:
Post a:
Gaim alternatives? »
« Need Light Network Enabled Distro..  
page: 1 · 2 · 3 · 4 · 5 · 6 · 7

Happyrat
Google Is Your Best Friend
Premium
join:2002-07-01
Disneyland

Re: Little Known Tips and Tricks...

Why is this thread no longer sticky? Most of the info presented in this thread is timeless...
--
Satan Loves You... »fuzzyrat.com

alien9999999
Your Head Looks Nice
Premium
join:2002-05-21
B-3000

Re: Little Known Tips and Tricks...

hmm, strange... it should be sticky...

you better sitemark it, just in case
--
Alien is my name and headbiting is my game.

FastEddie
iMod
join:2000-12-29
Channel Z

Host:
All Things Unix
Mozilla Software
Cyberonic
Rogers
Gadgets

Re: Little Known Tips and Tricks...


Pssst! Look over to your left at the Forum Links



Map for those that can't find this thread



--
Here's To You

armitage

join:2004-01-04
philippines
·mydestiny cable

I dont recall where or when I found this, but just in case that you cat a binary file while in a terminal (before starting X), hit -

ctrl-v ESC-C

and that'll reset your terminal to normal...

haven't seen this work in FreeBSD though (but I can cat a bin file and still have a normal term in BSD though).
--
Windows? It's a pack of instant noodles. Convenient, but not very healthy. Linux? Well, linux is the kitchen.

a398274

@cox.net
Hate when your cursor disappears?

tried a reset? clear?

invisible cursor no more!


alien9999999
Your Head Looks Nice
Premium
join:2002-05-21
B-3000
i don't want to sound arrogant, but i feel this might be usefull: »Installing IPv6 Server
--
Alien is my name and headbiting is my game.
ghost16825
Use security metrics
Premium
join:2003-08-26


3 edits
Gentoo installer/user tip:

This is more or less a RTFM tip rather than anything really brilliant. (Yes, I admit it - I occasionally do read the manual)

What should really be more prominent in the Official Gentoo docs is the elog system - logs info, warning messages etc when emerging.

#In your /etc/make.conf

#The default save directory for these logs is /var/log/portage/elog/
PORTAGE_ELOG_CLASSES="info warn error log qa"
PORTAGE_ELOG_SYSTEM="save"
#or save_summary for all the critical information in one file rather than separately.
dom6791

join:2001-11-23
Bronx, NY

1 edit

Re: Little Known Tips and Tricks...

In the event someone ever wanted to list only directories:

for i in * ; do if [ -d $i ]; then echo $i ; fi ; done

hohumdedumdum, True!

hohumdedumdum

@anduin.org

Re: Little Known Tips and Tricks...

No offense dom6791 See Profile, but that's just crazy. There's no need to do that.

ls -d */

That's it.

Also, your for loop will only work so long as the directory names have no spaces in them.

weeksben1
Premium
join:2004-02-26
Clarkston, MI
Just want to say thanks for the tips and tricks. Its great for showing us *nix rookies, some new (at least to us) stuff.
--
Ben WeeksNetwork AdminNovell CNA NW3.2/4.x/5.xNetwork + Certified
dom6791

join:2001-11-23
Bronx, NY

Didnt see this one in the list

If you have many files in a directory that you want to execute consecutively, but dont want the hassle of manually running one at a time:

find /tmp/syncfiles -name 'sync*' -exec sh {} \;

This will find all files that begin with 'sync' in the /tmp/syncfiles directory and execute one at a time. This saved me lots of time since it takes 7 hours sometimes. Now I can just start it and walk away.

Daniel
Premium,MVM
join:2000-06-26
San Francisco, CA
clubs:


4 edits
With lsof you can use the -t and -u switches to kill everything a user has open:
kill -9 `lsof -t -u daniel`
Use with care. ;)

timcuth
Braves Fan
Premium
join:2000-09-18
Pelham, AL
clubs:
·AT&T Southeast


1 edit
I don't know whether this already has been posted. I really think this thread should be edited into the ATU FAQ, as it is getting to be next to impossible to find anything specific in such a long thread.

Anyway, this week at work I was required to initiate a batch script upon reception of an FTP'ed file, rather than scheduling the job at a regular time. I did a Google search and then added my own twists, coming up with a very nice solution.

Since the batch script runs for about 10 minutes, I decided to check for the incoming file every 15 minutes during the range of times when the file might arrive (3 AM - 9 AM, Tue - Sat):

00,15,30,45 3-9 * * 2-6 /path/check_for_file.sh

check_for_file.sh runs the UNIX find command to look for the incoming file with a timestamp newer than the output file that is created by the batch script. When the newer input file is found, the find command starts the batch script:

find /expimp/blah -name input_file.txt -newer /path/output_file.txt -exec /path/batch_script.sh \;

Works like a charm!

Tim

--
The shortest sentence is, "I am". The longest is, "I do".
~ Project Hope ~

yock
TFTC
Premium
join:2000-11-21
Fairfield, OH

Re: Start a script based on reception of a file

said by timcuth See Profile :

I really think this thread should be edited into the ATU FAQ, as it is getting to be next to impossible to find anything specific in such a long thread.
That's a great idea. If users feel so inclined, they can submit their FAQ suggestions to this page and the system will IM the FAQ editors that there are new suggestions for the FAQ. In fact, Maxo See Profile sent us one just today.

No_Strings See Profile and I are slowly making our way through the FAQ in a massive cleanup effort, so anything you guys can add would be welcome.
--
Wiki Wiki
Laughter is the closest distance between two people. --Victor Borge

deblin
Dark Side of the Moon
Premium,MVM
join:2001-09-01
El Dorado Hills, CA

Quick and easy way to check for a valid date with "cal", which is pretty ubiquitous.

is_valid=0
cal $mon $year | grep -qw $day && is_valid=1
if [ $is_valid == 1 ]; then
echo "do stuff here if it's a valid date"
else
echo "invalid date entered"
fi

--
"Talk is cheap because the supply is greater than the demand" - Shelby Friedman

Steve
Consultant
join:2001-03-10
Yorba Linda, CA

Re: Little Known Tips and Tricks...

Why not:
if cal $mon $year | grep -qw $day
then
echo "do stuff here if it's a valid date"
else
echo "invalid date entered"
fi
No need for the variable set when you can check for the result directly in the "if"

Steve — who nevertheless would have not thought to do it this clever way

--
Stephen J. Friedl • Unix Wizard • Microsoft Security MVP • Tustin, California USA • my web site

yock
TFTC
Premium
join:2000-11-21
Fairfield, OH

Re: Little Known Tips and Tricks...

said by Steve See Profile :

Why not:
if cal $mon $year | grep -qw $day
then
echo "do stuff here if it's a valid date"
else
echo "invalid date entered"
fi
No need for the variable set when you can check for the result directly in the "if"

Steve — who nevertheless would have not thought to do it this clever way

I think a *LOT* of people forget about return codes when shell scripting...myself included. This script is a perfect example of why they're so damned useful.

--
Wiki Wiki
The more secretive a government is, the more skeptical we need to be. --Shepard Smith

Mordy
Comfortably Numb
Premium,MVM,ExMod 2004-07
join:2001-12-02
Denver, CO

1 edit

(topic move) Little Known Tips and Tricks...

Moderator Action
The post that was here (and all 6 followups to it), has been removed.

jdong
Eat A Beaver, Save A Tree.
Premium
join:2002-07-09
Rochester, MI
clubs:
I thought it was -f that did it, while -x just shows a more complete list of processes?
--
UbuntuForums Administrator: try Ubuntu Linux

Steve
Consultant
join:2001-03-10
Yorba Linda, CA

Wow, just tripped across something in Linux by accident: the x option to the ps command. Running ps -afx, it shows all processes with their parent/child relationship - very handy.
# ps afx
PID TTY STAT TIME COMMAND
1 ? S 0:45 init [3]
2 ? SW 0:00 [kflushd]
3 ? SW 0:06 [kupdate]
4 ? SW 0:00 [kpiod]
5 ? SW 0:01 [kswapd]
6 ? SW< 0:00 [mdrecoveryd]
274 ? S 267:19 named -t /chroot/named -u named -c /etc/named.conf
327 ? S 140:15 syslogd -m 0
338 ? S 0:00 klogd
354 ? S 0:00 /usr/sbin/atd
370 ? S 0:00 crond
447 ? S 0:56 /usr/libexec/postfix/master
454 ? S 0:17 \_ qmgr -l -t fifo -u
9737 ? S 0:00 \_ pickup -l -t fifo -u
456 ? S 8:00 /usr/local/sbin/sshd
9754 ? S 0:00 \_ sshd: root@pts/0
9756 pts/0 S 0:00 \_ -bash
9770 pts/0 R 0:00 \_ ps afx
491 tty1 S 0:00 /sbin/mingetty tty1
492 tty2 S 0:00 /sbin/mingetty tty2
Looking back in older versions, it's obviously been around a long time, but today was the first I'd ever seen it.

Nice!

--
Stephen J. Friedl • Unix Wizard • Microsoft Security MVP • Tustin, California USA • my web site

Happyrat
Google Is Your Best Friend
Premium
join:2002-07-01
Disneyland

Using YaST and a few custom repositories it's possible to easily update all of your applications in SuSE Linux (Any Version)...

Follow the instructions listed here on the SuSEwiki

»susewiki.org/index.php?title=Upd···via_YaST

And here's a couple of Listings of Repositories to make your life a little easier in this process...

»susewiki.org/index.php?title=Finding_RPMs

»en.opensuse.org/Additional_YaST_···sitories

»www.novell.com/products/suselinu···ors.html

Choosing the right mirrors and directories will depend on which version of SuSE you are running...
--
Crime wouldn't pay if the Government ran it...»www.fuzzyrat.com

toadlife
Premium
join:2004-05-03
Lemoore, CA

If you run FreeBSD as your desktop, and you frequently run portupgrade or portmanager to update your ports, you may have started an update of your ports and gone to bed while it compiles only to find in the morning that it stopped somewhere in the middle of compiling to ask you a configuration question about one of the programs.

To keep make from asking you any questions, put the following line in /etc/make.conf
BATCH=YES

With batch mode enabled, make will use the default options when compiling ports.

If you don't want batch mode to be turned on by default, you can pass the option to portupgrade when you run it.

With portupgrade, the option...
-m BATCH=YES
...will cause portupgrade to pass the batch=yes to the make command each time it compiles.

With portmanager, you cannot (AFAIK) pass arguments to make, so you would have to have the argument in make.conf

To pass the batch argument when compiling a single port (useful with huge meta-ports like kde), you can pass the batch argument like so...

make BATCH=yes install clean

wizard_ct
Gentoo Mage

join:2002-06-27
Santa Clara, CA
clubs:

Building on the split tip earlier, I'm sure the benefits of tarring to small chunks is obvious - burning to dvds, copying to a FAT partition (2gb limit) - what have you. Here's how to do it:

tar -cvf - /home/dirToBackup | split -b 1000m - backup-09-06-2005

Allows you to tar a directory to chunks in place, without needing to create the massive one first. This saves a ton of space.

Of course customize tar params and and split size to taste.

Use cat to recover on the other end.

cat backup-09-06-2005a? > backup.tar

You could easily do this in place as well if you needed.

ironwalker
World Renowned
Premium,MVM
join:2001-08-31
Keansburg, NJ
clubs:
·Optimum Online


1 edit

Re: Little Known Tips and Tricks...

said by wizard_ct See Profile :

Building on the split tip earlier, I'm sure the benefits of tarring to small chunks is obvious - burning to dvds, copying to a FAT partition (2gb limit) - what have you. Here's how to do it:

tar -cvf - /home/dirToBackup | split -b 1000m - backup-09-06-2005

Allows you to tar a directory to chunks in place, without needing to create the massive one first. This saves a ton of space.

Of course customize tar params and and split size to taste.

Use cat to recover on the other end.

cat backup-09-06-2005a? > backup.tar

You could easily do this in place as well if you needed.
Can I do it the same for Zip.I need to send a 48mb zip file to a windows user.I need them to be able to click first zip and open....if possible.
I will read man zip too.

Thanks for the tip though:)

Nevermind,I found it.
the tar command above made one 46mb archive for me and I had to use the split command seperately.

thanx again
--
"LIVE FREE OR DIE"
...
»www.rif.org/
...
Fiber Optics is the future of high-speed internet access. Stop by the BBR Fiber Optic

steve1515
Premium
join:2000-08-07
Peabody, MA
·Speakeasy
·Comcast Workplace

Here's a perl script I wrote that looks at apache logs and prints out unique counts, IPs, and DNS names.

syntax colored perl code:
#!/usr/bin/perl -w

use strict;

my $log_file = '/var/log/apache/access_log';

my %IP_count; #*** Hash containing count of hits from each IP
my %IP_DNS; #*** Hash containing the reverse lookups of IPs
my @sorted_IPs; #*** List of IPs sorted by count

#*** Check if log file exists and then try to open it
-e $log_file or die "ERROR: File not found.\n";
open LOG, "< $log_file" or die "ERROR: Can't create file: $!";

#*** Go through log and put IPs and counts in the hash
while (<LOG>)
{
$IP_count{$&}++ if (/^\d+\.\d+\.\d+\.\d+/);
}

close LOG;

#*** Go through each IP found, resolve it, and store result in the hash
foreach my $IP (keys %IP_count)
{
chomp($IP_DNS{$IP} = `dig +short -x $IP`);
}

#*** Store list of sorted IPs by count
@sorted_IPs = sort {$IP_count{$a} <=> $IP_count{$b} or
$IP_DNS{$a} cmp $IP_DNS{$b} or
$a cmp $b} keys %IP_count;

#*** Print out counts, IP, and DNS names
foreach my $IP (@sorted_IPs)
{
print " $IP_count{$IP}\t$IP\t$IP_DNS{$IP}\n";
}

This is my first perl program, so if theres some crazy error please let me know. :)
canadiancree
Crusin in the boonies

join:2004-02-10
Charlottetown, PE

Re: Little Known Tips and Tricks...

a good idea. one question though, wouldnt it be a bit taxing to resolve the DNS names everytime? What about adding a routine to have it look up a table or something to see if that IP range is already resolved, and if not, to then seek it out?

Unless you already have that, my perl is rustier than a '72 Vega

steve1515
Premium
join:2000-08-07
Peabody, MA

1 edit

Re: Little Known Tips and Tricks...

Ya, it only resolves each found IP once since each key in the hash is unique.

I'm also thinking that there is a simpler way than using dig...Maybe some built in perl resolving function, but I don't know what it is.
tld

join:2002-12-19
·Optimum Online

Re: Little Known Tips and Tricks...

said by steve1515 See Profile:

Ya, it only resolves each found IP once since each key in the hash is unique.

I'm also thinking that there is a simpler way than using dig...Maybe some built in perl resolving function, but I don't know what it is.
I've always used this:

sub iptoname {
my ($ip) = @_;
my (@list, $packed, @info, $hostname);
@list = split(/\./,$ip);
$packad = pack("C4",@list);
if (@info = gethostbyaddr($packad,2)) {
$hostname = $info[0];
} else {
$hostname = "";
}
$hostname;
}

I'm not sure I'd call it 'simpler' :D but it's probably a pretty efficient way of doing it.

Tom

ireallyneedtoregiste

@rr.com

Re: Little Known Tips and Tricks...

Multitasking on the command line is something I actually didn't know about until recently. I admit I felt stupid for not learning how to do this earlier, but I don't recall any intros to the command line that went over this.

If you are logged into the command line and don't have vt's enabled or don't want to switch vt's for whatever reason, you can still run a command and then run another while the previous job is running.

Let's say I bunzip2 LDPHowtos.tar.bz2
That will take a while, and I want to read Slashdot, so I hit Ctrl-Z to pause the unzip and send me back to the shell.
Now I can type bg to resume the unzip in the background, and use elinks to check the news.

If you know the command you're about to run will take a while, then a better way to do that is to put a "&" at the end of the command. That will background the job and put you back at the shell also.

Let's say I want to run multiple commands at the same time in one line. I can do that by putting a "&" at the end of each separate job. Like this:
bzip2 foo & bzip2 bar & bunzip2 wtf.bz2
then I do the Ctrl-Z and bg bit to put it in the background.
Or I could have just put another "&" at the end of the whole thing to background it.

Hope this helps someone new to the command line. I wish I knew this earlier. Would have saved me from having to wait for apps to finish whatever they were doing before I could check /.

jdong
Eat A Beaver, Save A Tree.
Premium
join:2002-07-09
Rochester, MI
clubs:

dd if=/dev/urandom of=- bs=1M count=10| mail emailaddress@domain.com
e-mail 10MB of randomness? ;)

--
Official Ubuntu Linux Forum Super Moderator: try Ubuntu Linux
ghost16825
Use security metrics
Premium
join:2003-08-26

This probably not original, but at the moment I quite like this neat one liner:

(Useful when you don't care about the subject title and just want to send it off)

cat message.txt | mail emailaddress@domain.com

or if you want a subject

cat message.txt | mail -s Subject address@domain.com

Of course this requires your message to be in message.txt. I'm sure someone can find a method without having to invoke cat at all.

--
Admin of the Kerio 2x-like open source project:
http://sourceforge.net/projects/kerio/
http://kerio.sourceforge.net/

See 6 replies to this post

jdong
Eat A Beaver, Save A Tree.
Premium
join:2002-07-09
Rochester, MI
clubs:
oh, so slocate is sgid/suid?

JohnInSJ
Premium
join:2003-09-22
San Jose, CA
·Comcast

Re: Little Known Tips and Tricks...

said by jdong See Profile:

oh, so slocate is sgid/suid?
$ ls -ld `which slocate`
-rwxr-sr-x 1 root slocate 26388 Apr 16 2004 /usr/bin/slocate
Looks like it [FC2]

yock
TFTC
Premium
join:2000-11-21
Fairfield, OH

Re: Little Known Tips and Tricks...

Assuming you add your user to the slocate group. Without being a member of that group it should follow file permissions.
--
This signiture pisses you off.

BeesTea
Network Janitor
Premium,VIP
join:2003-03-08
00000
Generally

$ ls -l `which slocate`
-rwx--s--x 1 root slocate 32468 Nov 12 2004 /usr/bin/slocate
--
$ /bin/whoami
nobody

jdong
Eat A Beaver, Save A Tree.
Premium
join:2002-07-09
Rochester, MI
clubs:

slocate started doing that, but nothing stops an experienced user from directly parsing the locate database, or using something like fakeroot to convince locate to let him through (though the latter can be foiled by checking FS permissions)
--
Official Ubuntu Linux Forum Super Moderator: try Ubuntu Linux

BeesTea
Network Janitor
Premium,VIP
join:2003-03-08
00000

Re: Little Known Tips and Tricks...

said by jdong See Profile:

slocate started doing that, but nothing stops an experienced user from directly parsing the locate database,
Well, except for file permissions that is.

$ ls -ld /var/lib/slocate/
drwxr-x--- 2 root slocate 104 May 23 03:22 /var/lib/slocate/
--
$ /bin/whoami
nobody
dom6791

join:2001-11-23
Bronx, NY

Little Known Tips and Tricks...

I was just wondering if some of you more knowledgeable *nix users would share some of your lesser known tips and tricks with Linux? Not including the information listed in this forums FAQs.
Forums » Tech and Talk » OS and Software » All Things UnixGaim alternatives? »
« Need Light Network Enabled Distro..  
page: 1 · 2 · 3 · 4 · 5 · 6 · 7


Wednesday, 17-Mar 23:23:00 Terms of Use | Privacy Policy | Hosting by www.nac.net - DSL,Hosting & Co-lo | feedback | contact
over 10.5 years online! © 1999-2010 dslreports.com.republican-creole
page compression OFF
Most commented news this week
· [121] What You Need To Know About The National Broadband Plan
· [96] The 'Electromagnetically Hypersensitive' Attack Smart Meters
· [70] 'Lawn Fridges' Attack UK Lawns
· [53] FCC Releases Copy Of The National Broadband Plan
· [45] FCC Gives Final Sales Pitch For Broadband Plan
· [38] Putting T-Mobile HSPA+ Through Its Paces
· [35] Remember Zer01? They've Mysteriously Disappeared
· [33] Verizon (Sort Of) Addresses FiOS Deployment Freeze
· [31] One Wireless Broadband Plan For All Your Devices
· [29] Cable Industry Pushing For Better Government Speed Tests
Most people now reading
· Windows 7 boot manager editing questions [Microsoft Help]
· [AZ] price increase and speed changes? [Cox HSI]
· Ashen Verdict Rep farming guide (ICC 10) [World of Warcraft]
· Montreal man jailed for movie piracy. [Canadian Chat]
· There's a slowdown in the Bronx [OptimumOnline]
· What is the spell hit cap for a lvl 80 full arcane spec mage [World of Warcraft]
· FiOS TV 2010 UPDATE: CHANNEL LINEUP CHANGES [Verizon FIOS TV]
· virtual US number that can receive SMS? [VOIP Tech Chat]
· Security Software Updates - 17 Mar 2010 [Security]
· Why so much hatred towards Bell? [TekSavvy]