Binary Revolution Forums: Shell tricks - Binary Revolution Forums

Jump to content

Welcome to Binary Revolution Forums

Welcome to the Binary Revolution Forums! You are a guest and are welcome to browse our 7 public forums at the top of the list without registering. All other forums are restricted to registered users only and will give you an "unauthorized" message if you try to browse them. However, if you Register or Sign In (ABSOLUTELY FREE and PRIVATE) you will be able to access many more sections of the site that are reserved for registered members and have lots of other benefits such as bypassing those annoying ads.

  • NO ADS! All of the ads are for GUESTS ONLY!
  • The annoying guest message (this very one) at the top of every page will go away.
  • Access our private messaging system to communicate with other users.
  • Start new topics and reply to others instead of just reading.
  • Subscribe to topics and forums to get automatic updates on watched threads.
  • Add/view events to our community calendar.
  • Customize your profile and see your statistics.
  • Change your preferences such as choosing layouts and tweaking your settings.
  • Contribute your site to our database of links.
  • Access our Gallery and all of its features (instead of just viewing thumbnails) including uploading images of your own.
  • Build up your reputation using our reputation controls.
  • Once again: NO ADS! All of the ads are for GUESTS ONLY! It is all free so Register Now!
Guest Message © 2012 DevFuse
ANNOUNCEMENTS & NEWS:


ANNOUNCEMENT: BinRev is now proud to be hosted and affiliated with lunarpages! See the announcement at the top of the forums for more details.
ANNOUNCEMENT: Follow us on twitter: @binrev @stankdawg

NOTE 2011-11-11: post-dated! I will be getting married on 11/11/11 and will be unavailable for the rest of of November! Any forum issues should be directed to lattera. We apologize in advance for slow responses.

-- StankDawg

  • (5 Pages)
  • +
  • 1
  • 2
  • 3
  • 4
  • 5
  • You cannot start a new topic
  • You cannot reply to this topic

Shell tricks Rate Topic: ***** 3 Votes

#41 User is offline   iceni 

  • SUPR3M3 31337 Mack Daddy P1MP
  • Icon
  • View blog
  • Group: Members
  • Posts: 400
  • Joined: 06-January 06
Reputation: 0
Neutral

Posted 04 February 2007 - 09:37 PM

i've got this command as an alias i made :D
watch --interval=2 "sudo netstat -apn -l -A inet"


this is the alias
alias net1='watch --interval=2 "sudo netstat -apn -l -A inet"'


someone said they don't like aliases, but i think that one is important to be able to run quickly if you want to see what's happening on the network. it refreshes every 2 seconds 8)

This post has been edited by iceni: 04 February 2007 - 09:42 PM

0

#42 User is offline   pbx43k 

  • Mack Daddy 31337
  • Icon
  • View blog
  • Group: Members
  • Posts: 241
  • Joined: 28-January 05
Reputation: 0
Neutral

Posted 04 February 2007 - 11:43 PM

Ever accidentally cat'd a binary file to your terminal and ended up with a bunch of junk characters filling your screen and making the terminal useless? Try using the reset command to restore the correct character set.
0

#43 User is offline   Ohm 

  • I could have written a book with all of these posts
  • Icon
  • View blog
  • View gallery
  • Group: Members
  • Posts: 3,209
  • Joined: 04-October 06
  • Gender:Male
  • Location:Maine, USA
Reputation: 27
Neutral

Posted 05 February 2007 - 01:46 AM

That sudo one is semi-dangerous, about as dangerous as leaving a root terminal up on your screen. Anyone can walk up, ^C out of it, and have passwordless sudo since you've been preventing it from timing out by re-launching the command every 2 minutes. Of course, sudo being the leet tool that it is gives you plenty of config options to get around that.
0

#44 User is offline   Daniel Holiday 

  • I broke 10 posts and all I got was this lousy title!
  • Icon
  • View blog
  • Group: Members
  • Posts: 16
  • Joined: 21-November 06
Reputation: 0
Neutral

Posted 10 February 2007 - 01:43 AM

View PostDirk Chestnut, on Jan 30 2007, 07:34 AM, said:

Ugh, I don't want to talk about all the times I've seen some jackass dev get in a hurry, and chmod -R 777 an entire /var/www directory... All it takes is one time doing that, and the security of your system can be seriously compromised.


Have you been watching me?
0

#45 User is offline   mecca_ 

  • DDP Fan club member
  • Icon
  • View blog
  • Group: Members
  • Posts: 54
  • Joined: 10-February 07
Reputation: 1
Neutral

Posted 10 February 2007 - 02:45 AM

Hello everyone, thanks for the good information here!

I'm not really sure if you would want to consider this a "trick" or not but it's gotten me out of some sticky situations when sshing from one machine with my shell set as bash to another machine with my shell set as certain versions of ksh.

Basically if you find yourself in a situation where the backspace key is no longer working, and you don't feel like pressing ctrl-h to erase things all day, you can use "stty" to remap the erase key to the backspace button.

$ stty erase <press the key you wish you map erase to, usually backspace>


You can use stty to remap various other things as well (man stty =)

---

Oh yeah, another thing that may come in handy. (again sorry this may not be considered a trick)
On linux the 'killall' command will let you kill all of the processes with a given name. On some Solaris machines killall will flat out kill all processes... including init. :blowfuse:
A handy string of commands to use when you have a bunch of stray processes out there but you can't use killall is the following:

$ ps -aef | grep <process name> | awk '{print $2}' | xargs kill -9


Again not a trick, but a common, helpful, string that people may end up using :)
0

#46 User is offline   dual 

  • BinRev veteran
  • Icon
  • View blog
  • Group: Agents of the Revolution
  • Posts: 1,196
  • Joined: 15-September 02
  • Gender:Male
Reputation: 0
Neutral

Posted 11 February 2007 - 08:36 AM

Thanks for the leet :> trick. Btw, echo > file != :> file. echo leaves a newline in the file where :> leaves nothing. Prove it with od...

luser@windows:~$ echo >| test.txt
luser@windows:~$ od -h test.txt 
0000000	  0a00														
0000001
luser@windows:~$ :>| test.txt
luser@windows:~$ od -h test.txt
luser@windows:~$


If you "set -o noclobber" then you have to use >| file.
0

#47 User is offline   Ohm 

  • I could have written a book with all of these posts
  • Icon
  • View blog
  • View gallery
  • Group: Members
  • Posts: 3,209
  • Joined: 04-October 06
  • Gender:Male
  • Location:Maine, USA
Reputation: 27
Neutral

Posted 11 February 2007 - 03:31 PM

Try echo -n >file instead. No newline.
0

#48 User is offline   livinded 

  • Dangerous free thinker
  • Icon
  • View blog
  • Group: Agents of the Revolution
  • Posts: 1,942
  • Joined: 08-December 04
  • Location:~/
Reputation: 10
Neutral

Posted 12 February 2007 - 09:15 AM

Here are the slides from a great presentation on writing optimized shellscripts. http://netmeister.or...useless_use.pdf
0

#49 User is offline   operat0r 

  • Dangerous free thinker
  • Icon
  • View blog
  • Group: Members
  • Posts: 793
  • Joined: 05-September 06
  • Location:ops
Reputation: 0
Neutral

  Posted 16 February 2007 - 02:27 PM

wget -q -O 1.html "http://rds.yahoo.com/S=96062857/K=$1+$2/v=2/SID=e/TID=I047_86/l=IPGN/R=1/SIG=1451curee/
EXP=1126931656/*-http%3A//images.search.yahoo.com/search/images?p=$1+$2&sm=Yahoo%21+Search&
toggle=1&ei=UTF-8&&vm=p&prev_sBL=off&safesearch=1&imgsz=large&b=41"
grep 'fullsize' 1.html  | sed 's/.*imgurl=/<img src="http:\/\//g' | sed -e 's/pg&rurl.*/pg">/g' | sed -e "s/%2F/\//g" |  sed -e "s/%2520/_/g" |  sed -e "s/%7E/~/g" | sed -e "s/%27/'/g" | sed -e "s/%40/@/g" >> $1-$2.html


http://rmccurdy.com/scripts/
0

#50 User is offline   Octal 

  • Dangerous free thinker
  • Icon
  • View blog
  • Group: Members
  • Posts: 886
  • Joined: 19-February 06
Reputation: 0
Neutral

Posted 19 February 2007 - 12:50 PM

Look at this:
<user@dv5000t ~/> wtf
usage: wtf [-f dbfile] [-t type] [is] <acronym>
<user@dv5000t ~/$ wtf lol
LOL: laughing out loud
<user@dv5000t ~/>$ wtf rofl
ROFL: rolling on floor laughing

haha, that's a sweet command.

This post has been edited by Octal: 19 February 2007 - 12:52 PM

0

#51 User is offline   iceni 

  • SUPR3M3 31337 Mack Daddy P1MP
  • Icon
  • View blog
  • Group: Members
  • Posts: 400
  • Joined: 06-January 06
Reputation: 0
Neutral

Posted 13 August 2007 - 10:56 AM

here's my terminal doing some tricks B) lol

http://xs218.xs.to/xs218/07331/term.jpg.xs.jpg
0

#52 User is offline   ragweed 

  • SUPR3M3 31337 Mack Daddy P1MP
  • Icon
  • View blog
  • Group: Members
  • Posts: 484
  • Joined: 19-April 03
Reputation: 0
Neutral

Posted 22 August 2007 - 07:06 PM

I don't think these really qualify as 'tricks' but
echo "/blah/whatever" | xargs ls -ln
cat /dev/null > somefile
cat /dev/ttyS0 (reading from a serial device)
0

#53 User is offline   inaequitas 

  • SUP3R 31337
  • Icon
  • View blog
  • Group: Members
  • Posts: 158
  • Joined: 25-July 07
Reputation: 0
Neutral

Posted 22 August 2007 - 10:37 PM

Whenever I get bored with the music selection I have I improvise:

dd if=/dev/urandom of=/dev/dsp

Ctrl + C to stop listening...
0

#54 User is offline   n3xg3n 

  • "I Hack, therefore, I am"
  • Icon
  • View blog
  • Group: Members
  • Posts: 960
  • Joined: 14-July 06
  • Country:
  • Gender:Male
  • Location:(703)
Reputation: 34
Neutral

Posted 23 August 2007 - 09:41 PM

View Postinaequitas, on Aug 22 2007, 11:37 PM, said:

Whenever I get bored with the music selection I have I improvise:

dd if=/dev/urandom of=/dev/dsp

Ctrl + C to stop listening...


Is it bad if that tells you kill specific people :blink:

my "trick"

echo `curl -s http://www.binrev.com/forums/ | tr "<p>" "\ " | tr "</p>" "\ " | grep "users online"`

:lol:
0

#55 User is offline   stansmith 

  • H4x0r
  • Icon
  • View blog
  • Group: Members
  • Posts: 30
  • Joined: 06-December 07
Reputation: -1
Neutral

Posted 14 December 2007 - 12:24 PM

DONT LOOK AT THIS IF YOU THINK YOU MIGHT ACTUALLY TRY IT

as root....

Spoiler



... i typed this on purpose the other night before i reformatted, all my shell commands were deleted
-1

#56 User is offline   Mikhail 

  • SCRiPT KiDDie
  • Icon
  • View blog
  • View gallery
  • Group: Members
  • Posts: 21
  • Joined: 16-December 07
  • Location:Long Beach, Ca
Reputation: -3
Neutral

Posted 17 December 2007 - 03:18 AM

or dd if=/dev/zero of=/dev/hda
for a lowlevel format / self-destruct basically; sure is a good way to securely delete your HD
hey you could even try dd if=/dev/urandom of=/dev/dsp same command using I/O redirection is cat /dev/urandom > /dev/dsp
0

#57 User is offline   mobilec 

  • SCRiPT KiDDie
  • Icon
  • View blog
  • Group: Members
  • Posts: 25
  • Joined: 09-September 06
  • Location:Ottawa, Canada
Reputation: 0
Neutral

Posted 18 December 2007 - 11:04 AM

Sorry if this was mentioned before:
Anything within `` gets executed, e.g.:
$ HELLO="`echo Hello`"
$ echo "$HELLO"
Hello

0

#58 User is offline   iceni 

  • SUPR3M3 31337 Mack Daddy P1MP
  • Icon
  • View blog
  • Group: Members
  • Posts: 400
  • Joined: 06-January 06
Reputation: 0
Neutral

Posted 18 December 2007 - 12:52 PM

i use this script, below, to unpack archives. i made an alias for it, so i only have to type 'unpack whatever_archive'
this is the alias -
alias unpack='/home/iceni60/scripts/unpack2dir.sh'

#! /bin/sh
# #############################################################################

	   NAME_="unpack2dir"
	   HTML_="uncompress unpack script"
	PURPOSE_="unpack zip, tar, tgz, tar.gz, tar.bz2, tar.z to a dir of the same name as archive prefix"
   SYNOPSIS_="$NAME_ [-vhlr] <file> [file...]"
   REQUIRES_="standard GNU commands"
	VERSION_="1.2"
	   DATE_="1999-09-20; last update: 2006-02-03"
	 AUTHOR_="Dawid Michalczyk <dm@eonworks.com>"
		URL_="www.comp.eonworks.com"
   CATEGORY_="compress"
   PLATFORM_="Linux"
	  SHELL_="bash"
 DISTRIBUTE_="yes"

# #############################################################################
# This program is distributed under the terms of the GNU General Public License

# HISTORY:
# 2006-02-03 v1.2 - added the -C flag to tar options. Otherwise tar would not 
#			extract to a dir with different name then the one found in the 
#			archive.

usage () {

echo >&2 "$NAME_ $VERSION_ - $PURPOSE_
Usage: $SYNOPSIS_
Requires: $REQUIRES_
Options:
	 -r, remove the compressed file after extraction
	 -v, verbose
	 -h, usage and options (help)
	 -l, see this script"
	exit 1
}

# args check
[ $# -eq 0 ] && { echo >&2 missing argument, type $NAME_ -h for help; exit 1; }

# var init
rmf=
verbose=

# option and argument handling
while getopts vhlr options; do

	case $options in
		r) rmf=on;;
		v) verbose=on;;
		h) usage;;
		l) more $0; exit 1;;
	   \?) echo invalid argument, type $NAME_ -h for help; exit 1;;
	esac

done
shift $(( $OPTIND - 1 ))

mkdirf() {

	# usage: fnc <file_prefix> <file>

	[ -d $1 ] && { echo "${NAME_}: skipping ${2} - dir ${1} already exist"; continue; }
	#echo $1
	mkdir $1
#	[[ $verbose ]] && echo "${NAME_}: unpacking "$2
}

file_getDirname() {

	local _dir="${1%${1##*/}}"
	[ "${_dir:=./}" != "/" ] && _dir="${_dir%?}"
	echo "$_dir"

}

file_getBasename() {

	local _name="${1##*/}"
	echo "${_name%$2}"

}

clean() {

	# usage <exit_status> <dir_to_rm>

	[[ $1 != 0 ]] && rmdir $2 # remove empty dir if unpacking went wrong
	[[ $1 == 0 && $verbose ]] && echo "${NAME_}: unpacking " ${dir}/${a}
	[[ $rmf ]] && rm -f -- $a

}

start_dir=$(pwd)

for a in "$@"; do

	cd $start_dir		
	fname=$(file_getBasename $a)
	dir=$(file_getDirname $a)
	cd $dir
	a=$fname

	case $a in


		# zip
		*.[zZ][iI][pP])
			mkdirf ${a/.[zZ][iI][pP]/} $a
			unzip -qq $a -d ${a/.[zZ][iI][pP]/}
			clean $? ${a/.[zZ][iI][pP]/}
		   ;;

		# tar
		*.[tT][aA][rR])
			mkdirf ${a/.[tT][aA][rR]/} $a
			tar -xf $a -C ${a/.[tT][aA][rR]/}/
			clean $? ${a/.[tT][aA][rR]/}
		   ;;

		# tgz
		*.[tT][gG][zZ])
			mkdirf ${a/.[tT][gG][zZ]/} $a
			tar -xzf $a -C ${a/.[tT][gG][zZ]/}
			clean $? ${a/.[tT][gG][zZ]/}
		   ;;

		# tar.gz 
		*.[tT][aA][rR].[gG][zZ])
			mkdirf ${a/.[tT][aA][rR].[gG][zZ]/} $a
			tar -xzf $a -C ${a/.[tT][aA][rR].[gG][zZ]/}/
			clean $? ${a/.[tT][aA][rR].[gG][zZ]/}
		   ;;

		# tar.bz2
		*.[tT][aA][rR].[bB][zZ]2)
			mkdirf ${a/.[tT][aA][rR].[bB][zZ]2/} $a
			tar -xjf $a -C ${a/.[tT][aA][rR].[bB][zZ]2/}/
			clean $? ${a/.[tT][aA][rR].[bB][zZ]2/}
		   ;;

		# tar.z
		*.[tT][aA][rR].[zZ])
			mkdirf ${a/.[tT][aA][rR].[zZ]/} $a
			tar -xZf $a -C ${a/.[tT][aA][rR].[zZ]/}/
			clean $? ${a/.[tT][aA][rR].[zZ]/}
		   ;;


		*) echo "${NAME_}: $a not a compressed file or lacks proper suffix";;

	esac

done

0

#59 User is offline   iceni 

  • SUPR3M3 31337 Mack Daddy P1MP
  • Icon
  • View blog
  • Group: Members
  • Posts: 400
  • Joined: 06-January 06
Reputation: 0
Neutral

Posted 18 December 2007 - 01:01 PM

here are some more aliases i've got -

# screenshots
alias screenshot='import -window root ~/Desktop/`date +%Y%m%d%H%M`.png'

# System info
alias cpuu="ps -e -o pcpu,cpu,nice,state,cputime,args --sort pcpu | sed '/^ 0.0 /d'"
alias memu='ps -e -o rss=,args= | sort -b -k1,1n | pr -TW$COLUMNS'
alias pg='ps aux | grep'  #requires an argument

# interactive
alias cp='cp -vi'
alias mv='mv -vi'
alias rm='mv --target-directory=$HOME/.Trash/'

# network
alias net1='watch --interval=2 "sudo netstat -apn -l -A inet"'
alias net2='watch --interval=2 "sudo netstat -anp --inet --inet6"'  
alias net3='sudo lsof -i'
alias ping='ping -c 10'
alias currports='wine /home/iceni60/Desktop/Desktop_Folder/Network_Tools/currports/cports.exe'
alias winwhois='wine /home/iceni60/Desktop/Desktop_Folder/Network_Tools/win32whois_0_9_13/win32whois.exe'
alias xnews='wine /home/iceni60/Desktop/Desktop_Folder/Network_Tools/XNews/XNEWS.EXE'
alias whois='whois -H'

# chmod and permissions commands
alias mx='chmod a+x'
alias 000='chmod 000'
alias 644='chmod 644'
alias 755='chmod 755'
alias perm='stat --printf "%a %n \n "' # requires a file name e.g. perm file

# lynx web browser
alias bbc='lynx http://news.bbc.co.uk/text_only.stm'
alias google='lynx http://google.co.uk'


here are some functions
function	ff			   { find . -name $@ -print; }

function	mfloppy		  { mount /dev/fd0 /mnt/floppy; }
function	umfloppy		 { umount /mnt/floppy; }

function	mdvd			 { mount -t iso9660 -o ro /dev/dvd /mnt/dvd; }
function	umdvd			{ umount /mnt/dvd; }

function	mcdrom		   { mount -t iso9660 -o ro /dev/cdrom /mnt/cdrom; }
function	umcdrom		  { umount /mnt/cdrom; }

function	psa			  { ps aux $@; }
function	psu			  { ps  ux $@; }

# clock - A bash clock that can run in your terminal window. 
clock () 
{ 
while true;do clear;echo "===========";date +"%r";echo "===========";sleep 1;done 
}

netinfo ()
{
echo "--------------- Network Information ---------------"
/sbin/ifconfig | awk /'inet addr/ {print $2}'
echo ""
/sbin/ifconfig | awk /'Bcast/ {print $3}'
echo ""
/sbin/ifconfig | awk /'inet addr/ {print $4}'

# /sbin/ifconfig | awk /'HWaddr/ {print $4,$5}'
echo "---------------------------------------------------"
}

0

#60 User is offline   Octal 

  • Dangerous free thinker
  • Icon
  • View blog
  • Group: Members
  • Posts: 886
  • Joined: 19-February 06
Reputation: 0
Neutral

Posted 30 December 2007 - 05:58 PM

View Poststansmith, on Dec 14 2007, 12:24 PM, said:

DONT LOOK AT THIS IF YOU THINK YOU MIGHT ACTUALLY TRY IT

as root....

Spoiler



... i typed this on purpose the other night before i reformatted, all my shell commands were deleted

So when you make an alias the command gets executed?

Anyway, that doesn't delete all the files on the harddrive. It skips a few, because they are being used.
0

Share this topic:


  • (5 Pages)
  • +
  • 1
  • 2
  • 3
  • 4
  • 5
  • You cannot start a new topic
  • You cannot reply to this topic


  • Time Now: Feb 10 2012 10:08 PM