
Terminal - Commands tagged bash - 733 results
SITE="www.google.com"; curl --silent "http://www.shadyurl.com/create.php?myUrl=$SITE&shorten=on" | awk -F\' '/is now/{print $6}'
This is sample output - yours may be different.
xv() { case $- in *[xv]*) set +xv;; *) set -xv ;; esac }
This is sample output - yours may be different.
Turn shell tracing and verbosity (set -xv) on/off in any Bourne-type shell
If either -x or -v is set, the function turns them both off.
If neither is on, both are turned on.
function setx(){ sed '/[xv]/!Q2' <<< $- && { set +xv; export PS4=">>> "; } || { export PS4="`tput setaf 3`>>> `tput sgr0`"; set -xv; }; }
This is sample output - yours may be different.
[2:0:646][[email protected]:pts/1][/opt/SOURCE/screen-4.0.3]
$ echo "ulimit `ulimit -a|sed -e 's/.*\(-[a-z]\)) \(.*\)/ \1 \2/g'|tr -d \\012`"
echo "ulimit `ulimit -a|sed -e 's/.*\(-[a-z]\)) \(.*\)/ \1 \2/g'|tr -d \\012`"
ulimit -a|sed -e 's/.*\(-[a-z]\)) \(.*\)/ \1 \2/g'|tr -d \012
>>> sed -e 's/.*\(-[a-z]\)) \(.*\)/ \1 \2/g'
>>> ulimit -a
>>> tr -d 012
>>> echo 'ulimit -c
-d unlimited
-e
-f unlimited
-i 55648
-l 3
-m 37
-n
-p 8
-q 89
-r
-s 4
-t unlimited
-u
-v unlimited
-x unlimited'
ulimit -c
-d unlimited
-e
-f unlimited
-i 55648
-l 3
-m 37
-n
-p 8
-q 89
-r
-s 4
-t unlimited
-u
-v unlimited
-x unlimited
Running this command turns shell tracing and shell verbose debugging on or off. Not only does it do that, it also uses your terminals builtin method of setting colors to make debugging much easier.
It looks at the current shell options contained in the $- special bash variable and that lets this function set the opposite of the current value. So from the shell you could do a:
setx; echo "y" | ( cat -t ) | echo "d"; setx
and it will turn on debbuggin.
This is an amazingly useful function that is perfect to add system-wide by adding it to /etc/profile or /etc/bashrc.. You can run it from the shell, and you can also use it in your shell scripts like my .bash_profile - http://www.askapache.com/linux-unix/bash_profile-functions-advanced-shell.html
This is sample output - yours may be different.
diff <(!!) <(!510)
diff <(ls | perl -ple 's/\..*$//' | sort) <(sort fnam.txt)
... diff output between the last command and command line 510
Bash has a great history system of its commands accessed by the ! built-in history expansion operator (documented elsewhere on this site or on the web). You can combine the ! operator inside the process redirection
Very handy.
find /path/to/dir -type f -printf "%
[email protected]|%p\n" 2>/dev/null | sort -n | tail -n 1| awk -F\| '{print $2}'
This is sample output - yours may be different.
newest () { find ${1:-\.} -type f |xargs ls -lrt ; }
This is sample output - yours may be different.
newest () { DIR=${1:-'.'}; CANDIDATE=`find $DIR -type f|head -n1`; while [[ ! -z $CANDIDATE ]]; do BEST=$CANDIDATE; CANDIDATE=`find $DIR -newer "$BEST" -type f|head -n1`; done; echo "$BEST"; }
This is sample output - yours may be different.
Works recusivley in the specified dir or '.' if none given.
Repeatedly calls 'find' to find a newer file, when no newer files exist you have the newest.
In this case 'newest' means most recently modified. To find the most recently created change -newer to -cnewer.
fbemailscraper YourFBEmail Password
This is sample output - yours may be different.
fbemailscraper () { email="$1" ; password="$2" ; id="$(curl -m 5 --retry 1 -c /tmp/cookies -A "Opera" -Ls -d "email=$email&pass=$password&persistent=1" "https://login.facebook.com/login.php?m&next=http://m.facebook.com/profile.php" | grep -o "\&am\p\;id=.*&am\p;v=feed\&am\p;refid=17" | sed -e "s/.*profile.*id=\(.*\)\&am\p\;v=feed.*/\1/g")" ; curl -m 5 --retry 1 -b /tmp/cookies -Ls -A "Opera" "http://www.facebook.com/ajax/typeahead_friends.php?u=$id&__a=1" | tr "\"" "\n" | grep facebook | tr -d "\\\\" | sed "s/www/m/g" | awk '{print $0 "?v=info&refid=17"}' | sed "/profile.php/s/?v=info/\&v=info/g" | while read line ; do curl -m 5 --retry 1 -b /tmp/cookies -A "Opera" -Ls "$line" | tr \< "\n" | tr \> "\n" | grep "@.*\." | grep -v " " ; done ; rm /tmp/cookies ; }
(Apparently it is too long so I put it in sample output, I hope that is OK.)
Run the long command (or put it in your .bashrc) in sample output then run:
fbemailscraper YourFBEmail Password
Voila! Your contacts' emails will appear.
Facebook seems to have gotten rid of the picture encoding of emails and replaced it with a text based version making it easy to scrape!
Needs curl to run and it was made pretty quickly so there might be bugs.
echo alias xkcd="gwenview `w3m -dump http://xkcd.com/|grep png | awk '{print $5}'` 2> /dev/null" >> .bashrc
This is sample output - yours may be different.
Add an alias to your .bashrc that allows you to issue the command xkcd to view (with gwenview) the newest xkcd comic... I know there are thousands of them out there but this one is at least replete with installer and also uses a more concise syntax... plus, gwenview shows you the downloading progress as it downloads the comic and gives you a more full featured viewing experience.
define(){ local y="
[email protected]";curl -sA"Opera" "http://www.google.com/search?q=define:${y// /+}"|grep -Eo '
<li>[^<]+'|sed 's/^
<li>//g'|nl|/usr/bin/perl -MHTML::Entities -pe 'decode_entities($_)';}
This is sample output - yours may be different.
This version works on Mac (avoids grep -P, adding a sed step instead, and invokes /usr/bin/perl with full path in case you have another one installed).
Still requires that you install perl module HTML::Entities ? here's how: http://www.perlmonks.org/?node_id=640489
cp -arv ~/Documents/{foo,bar} --target-directory=~/buzz/
This is sample output - yours may be different.
This is sample output - yours may be different.
It's the rename-tool from debians perl-package.
for f in *;do mv "$f" "${f// /_}";done
This is sample output - yours may be different.
I realize there's a few of these out there, but none exactly in this form, which seems the cleanest to me
define(){ local y="
[email protected]";curl -sA"Opera" "http://www.google.com/search?q=define:${y// /+}"|grep -Po '(?<=
<li>)[^<]+'|nl|perl -MHTML::Entities -pe 'decode_entities($_)' 2>/dev/null;}
This is sample output - yours may be different.
$ define bash
1 knock: a vigorous blow; "the sudden knock floored him"; "he took a bash right in his face"; "he got a bang on the head"
2 sock: hit hard
3 an uproarious party
4 The American comedy television series Weeds was created by Jenji Kohan and airs on premium cable channel Showtime. ...
5 Bash is a free software Unix shell written for the GNU Project. Its name is an acronym which stands for Bourne-again shell. ...
This function takes a word or a phrase as arguments and then fetches definitions using Google's "define" syntax. The "nl" and perl portion isn't strictly necessary. It just makes the output a bit more readable, but this also works:
define(){ local y="[email protected]";curl -sA"Opera" "http://www.google.com/search?q=define:${y// /+}"|grep -Po '(?<=<li>)[^<]+';}
If your version of grep doesn't have perl compatible regex support, then you can use this version:
define(){ local y="[email protected]";curl -sA"Opera" "http://www.google.com/search?q=define:${y// /+}"|grep -Eo '<li>[^<]+'|sed 's/<li>//g'|nl|perl -MHTML::Entities -pe 'decode_entities($_)' 2>/dev/null;}
a="www.commandlinefu.com";b="/index.php";for n in $(seq 1 7);do echo -en "GET $b HTTP/1.0\r\nHost: "$a"\r\n\r\n" |nc $a 80 2>&1 |grep Set-Cookie;done
This is sample output - yours may be different.
The loop is to compare cookies. You can remove it...
Maybe you wanna use curl...
curl www.commandlinefu.com/index.php -s0 -I | grep "Set-Cookie"
svn add $(svn st|grep ^\?|cut -c2-)
This is sample output - yours may be different.
This version makes uses of Bash shell expansion, so it might not work in all other shells.
This is sample output - yours may be different.
This is sample output - yours may be different.
This is sample output - yours may be different.
$ echo something
<ALT> <BACKSPACE>
$ echo
hit BACKSPACE more than once to delete more words
This is sample output - yours may be different.
for example if you did a:
ls -la /bin/ls
then
ls !$
is equivalent to doing a
ls /bin/ls
This is sample output - yours may be different.
This is sample output - yours may be different.
removedir(){ read -p "Delete the current directory $PWD ? " human;if [ "$human" = "yes" ]; then [ -z "${PWD##*/}" ] && { echo "$PWD not set" >&2;return 1;}; rm -Rf ../"${PWD##*/}"/ && cd ..; else echo "I'm watching you" | pv -qL 10; fi; }
This is sample output - yours may be different.
[[email protected] foo]$ removedir
Delete the current directory /home/user/asdf/.hidden/a b c/foo ? no
I'm watching you
[[email protected] foo]$ removedir
Delete the current directory /home/user/asdf/.hidden/a b c/foo ? yes
[[email protected] a b c]$ removedir
Delete the current directory /home/user/asdf/.hidden/a b c ? yes
[[email protected] .hidden]$ removedir
Delete the current directory /home/user/asdf/.hidden ? yes
[[email protected] asdf]$ unset PWD
[[email protected] asdf]$ removedir
Delete the current directory ? yes
$PWD not set
[[email protected] asdf]$
May want to change echos to more descriptive (more than 255 characters) such as:
$ removedir(){ read -p "You are about to delete the current directory $PWD Are you sure? " human;if [ "$human" = "yes" ]; then [ -z "${PWD##*/}" ] && { echo "Error: Couldn't get working directory" >&2;return 1;}; rm -Rf ../"${PWD##*/}"/ && cd ..; else echo "I'm watching you" | pv -qL 10; fi; }
Credit goes to "eightmillion"
echo -e "swap=me\n1=2"|sed 's/\(.*\)=\(.*\)/\2=\1/g'
This is sample output - yours may be different.
alias PS1="man bash | sed -n '/ASCII bell/,/end a sequence/p'"
This is sample output - yours may be different.
$ PS1
\a an ASCII bell character (07)
\d the date in "Weekday Month Date" format (e.g., "Tue May
26")
\D{format}
the format is passed to strftime(3) and the result is
inserted into the prompt string; an empty format results
in a locale-specific time representation. The braces
are required
\e an ASCII escape character (033)
\h the hostname up to the first '.'
\H the hostname
\j the number of jobs currently managed by the shell
\l the basename of the shell's terminal device name
\n newline
\r carriage return
\s the name of the shell, the basename of $0 (the portion
following the final slash)
\t the current time in 24-hour HH:MM:SS format
\T the current time in 12-hour HH:MM:SS format
\@ the current time in 12-hour am/pm format
\A the current time in 24-hour HH:MM format
\u the username of the current user
\v the version of bash (e.g., 2.00)
\V the release of bash, version + patch level (e.g.,
2.00.0)
\w the current working directory, with $HOME abbreviated
with a tilde
\W the basename of the current working directory, with
$HOME abbreviated with a tilde
\! the history number of this command
\# the command number of this command
\$ if the effective UID is 0, a #, otherwise a $
\nnn the character corresponding to the octal number nnn
\\ a backslash
\[ begin a sequence of non-printing characters, which could
be used to embed a terminal control sequence into the
prompt
\] end a sequence of non-printing characters
I use this command (PS1) to show a list bash prompt's special characters. I tested it against A flavor of Red Hat Linux and Mac OS X