![]() |
![]() |
#1 (permalink) |
Crazy
Location: Nova Scotia, Canada
|
Share you Bash Command Line Tips & Tricks
I've been a linux user for a fair amount of time now, but it's just now that I'm getting really used to the command line interface.
I've picked up a few cool tidbits here and there, and I'm sure a lot of you have too, so let's hear 'em. ----- Here's a flexible sequntial download (think ezpics) Code:
for NUM in `seq -f %02g 00 30`; do URL="http://www.coasar.com/newgalleries/pbc/ahv/03/images/fullimage/0$moo.jpg"; wget $NUM 2>/dev/null && echo Downloaded $URL || echo " Failed $URL" ; done ----- This one I picked up on the net somewhere. I use firefox almost exclusively, so I set up aMSN to open up links with firefox. The major problem with that though is that if I'm already "surfin' the web" firefox will ask me to launch with a different profile. ![]() Here's a fix that will make it so that if firefox is already open it'll open the link in a new tab. Open up your favorite text editor *cough*VI*cough* and paste this: Code:
#!/bin/bash /etc/firefox/firefox -remote "openURL($@, new-tab)" >/dev/null || exec /etc/firefox/firefox "$@" >/dev/null; Now you can do stuff like this (i called mine firefox_newtab) Code:
firefox_newtab www.tfproject.org ----- This is likely common knowledge but I'm going to write in anyway, just incase someone finds it usefull. In my tips i used && (and) and || (or). If two commands are seperated by && then the the second will only be executed if the first one is sucessfull. For example: Code:
./configure && make If two commands are sperated by || (two pipes, shift + \ ) the second command will only execute if the first fails. E.g.: Code:
wget http://www.moo.com/somefile.tar || echo Download Failed Code:
echo Beyond here lie dragons echo Beyond here lie dragons >/dev/null
__________________
Ask a simple question... get pain. |
![]() |
![]() |
#2 (permalink) |
Psycho
|
Probably not what you're looking for, but, some jokers made a pizza-ordering command line utility. You sign up for an account on Domino's website and the utility does everything else! I've never tried it, but it looks like it works.
http://www.beigerecords.com/cory/pizza_party/ |
![]() |
![]() |
#3 (permalink) |
A Real American
|
a lil simple bash script that will create an individual gzip tar of each sub-dir in the dir that it executed in. each tar has the name of the dir that it has compressed.
Code:
find . -type d -mindepth 1 -maxdepth 1 -exec tar zcf {}.tar.gz {} \;
__________________
I happen to like the words "fuck", "cock", "pussy", "tits", "cunt", "twat", "shit" and even "bitch". As long as I am not using them to describe you, don't go telling me whether or not I can/should use them...that is, if you want me to continue refraining from using them to describe you. ~Prince |
![]() |
![]() |
#4 (permalink) |
Crazy
Location: Salt Town, UT
|
Search command history
Ctrl+R will search backwards through your previous commands, just press Ctrl+R, then start typing part of the command you want to recall (any substring, it doesn't have to be from the beginning).
Ctrl+A will go to the start of the line. Ctrl+E will go to the end Ctrl+U will nuke from the cursor to the start of the line Ctrl+W will nuke the word to the left of the cursor |
![]() |
![]() |
#5 (permalink) |
Upright
|
Here are some simple things that are really invaluable - I use them several times per day
![]() 'cd -' will go 'back' a directory (eg. say you were in /usr/src/linux, then went to ~/kernelconfigs ... you can quickly get back to /usr/src/linux by typing cd -) when you're typing in a file name, you can enter the first few letters and then <TAB>. It'll either automatically be completed for you or it'll show you a list of potential matches. and if you want to perform batch operations on files in a directory, you can try this: Code:
for i in *; do operation_1_on $i; operation_2_on $i; done Code:
for i in *; do mpg123 -w "${i/.mp3}.wav" "$i"; toolame -v 5 "${i/.mp3}.wav" "${i/.mp3}.mp2"; done |
![]() |
![]() |
#6 (permalink) |
In Your Dreams
Location: City of Lights
|
set permissions on files only:
Code:
find . -type f -exec chmod 0644 {} \; Code:
find . -type d -exec chmod 0755 {} \; recursively set permissions on something depending on if it's a file or a directory (note: chmod -R 0755 would make EVERYTHING (files AND directories) 755.. I don't want that). Of course that can be changed to chown or pretty much anything you want hehe.. I have some other scripts, but they're only relevant for work.. |
![]() |
![]() |
#8 (permalink) | |
Irresponsible
|
Quote:
Code:
pkill -u username ![]() By default, pkill kills by process name.
__________________
I am Jack's signature. |
|
![]() |
![]() |
#9 (permalink) |
Upright
|
Type
! followed by the beginning of a command you've already used...and hit enter. it will auto exec that command in full...you ran last. obvoiusly be careful with somethings. i also presume everyone knows ~userid prefers to userid's home directory. also if on the command line and have vi editor mode activated ( bash -o vi ( works with ksh too ) ) then go for a ESC V and that will bring the command line straight into a full vi session |
![]() |
![]() |
#11 (permalink) |
beauty in the breakdown
Location: Chapel Hill, NC
|
Dont know... I just wrote a couple of shell scripts to backup stuff (one backs up MySQL, another backs up my website, another backs up stuff edited in the past day/week/month) and FTP them to backup. Kinda long to be posting on here though.
__________________
"Good people do not need laws to tell them to act responsibly, while bad people will find a way around the laws." --Plato |
![]() |
![]() |
#12 (permalink) |
Psycho
|
here's a few random ones i have:
Create your own short user name: Code:
#!/usr/bin/env python from random import choice # Vowels vowels = ['a','e','i','o','u'] # Beginning hard consonants startcons = ['b','c','d','g','j','k','m','n','p','q','t','v','x','z'] # Ending hard consonoants endcons = ['b','c','d','g','k','m','n','p','t','x','z'] # Soft Consonants -- note v and z are listed twice softcons = ['f','h','l','r','s','v','w','z'] print choice(startcons) + choice(vowels) + choice(softcons) + choice(endcons) Code:
#!/bin/bash # by Tom Law, September 2003 # "ub" = "Unique Bookmarks" # Compare two bookmark files, and create for each one a new html file # that contains the bookmarks unique to the other one. # You'll need to edit the following two lines to show where # the two existing bookmark files (that you want to compare) are. BA="/home/keyshawn2/august 18 2004 bookmarks -win.html" BB="/home/keyshawn2/august 18 2004 bookmarks-linux.html" ################################# # sort each bookmark file, while removing extra spaces, # and adding a browser identifier (I put the identifier # at the end of the title to help with debugging.) cd /tmp sort -b $BA | sed -e 's/<\/A>/---A<\/A>/g' | sed -e 's/ */ /g' > utmpA sort -b $BB | sed -e 's/<\/A>/---B<\/A>/g' | sed -e 's/ */ /g' > utmpB # merge the two files, while removing duplicate lines, # as well as unwanted lines and characters sort -bd utmpA utmpB | uniq -uW 2 | grep HREF | grep -vE "(about:config|>---|N---A|N---B|uniqA|uniqB)" | sed s/\<DT\>//g | sed s/$/\<br\>/g > utmpC # split the merged file back into two, while removing the identifiers cat utmpC | grep -e ---A | sed -e 's/---A//g'> utmpA cat utmpC | grep -e ---B | sed -e 's/---B//g'> utmpB # convert them into html files echo "<html><body>" > uhead echo "</body></html>" > utail cat uhead utmpA utail > uniqA.html cat uhead utmpB utail > uniqB.html rm utmpA utmpB utmpC uhead utail # After running this command, load the "/tmp/uniq?.html" files # into their respective browsers (file A into browser B, # and file B into browser A), and drag each link to somewhere # in the bookmark file. It doesn't matter if you put them # in different folders than you did in the other bookmark file. # Run ub at bootup or by cron, and then every day or so look at # the "uniq" file (which you should bookmark) in each browser, and # update the browser's bookmark file. Code:
for dirs in `ls /` do if [ -d /$dirs ] then echo "Listing of /$dirs" >> /tmp/disk_usage.txt echo "################################" >> /tmp/disk_usage.txt du -h /$dirs >> /tmp/disk_usage.txt echo "" >> /tmp/disk_usage.txt fi done
__________________
currently reading: currently playing : |
![]() |
![]() |
#13 (permalink) |
Junkie
Location: RI
|
You can use PHP on the CLI which I love. I use that now as a way to list usage on my game hosting server so I know where I am on my usage. I've also set it up so that it'll kill certain processes or start them up.
Those are for linux I've made scripting tips in Windows(I know, not bash, but still useful batch files that I wanna brag about) that'll list all installed applications on a computer and another one that can set the ip address. If anyone would like any of them, let me know and I'll post them. |
![]() |
![]() |
#14 (permalink) |
Insane
Location: Austin, TX
|
I have written some serious one-liner doozies in the past...usually when trying to do something somewhat complicated with a bunch of files. For example, one time I did a one-liner that recursively went through a directory tree and renamed files with certain names to match the directory name, or something like that.
Other one-liners I've used for doing recursive media conversion (WMA->MP3 for example), and of course for downloading Pr0n from various places with nice sequential filenames. Probably my most frequently used BASH construct is the "while read" one: Code:
cat /etc/passwd | awk -F: '{ print $1 }' | while read line; do echo $line; done; Last edited by skaven; 03-21-2005 at 11:59 PM.. |
![]() |
![]() |
#15 (permalink) |
Junkie
Location: NorthEast
|
Kind of like the cd - trick above, but pushd and popd are invaluable. You can create a whole stack of directories to switch from. The command dirs will give you a list of whats on the current stack. Very useful if you keep going back and forth, just pushd dir then popd and then to keep swapping !push and !pop to get back.
Bash is great. |
![]() |
Tags |
bash, command, line, share, tips, tricks |
|
|