Bash repository
This is exactly what the title says, a bash repository containing bash one liners and all
the commands I find useful in my everyday little tasks. Maybe in the future it will have
sections on the left, if the content will become unmanageable, for now I'll leave it as it is;
the scope of this section is to remind me of bash commands, rapidly browsing through them.
For a wider repository look on commandlinefu.
I've recently found http://mywiki.wooledge.org/BashFAQ, which
seems a good resource to look at when in need of a clarification.
removes all files with extension different from .java
find . ! -name "*.java" -exec rm -f {} \;
pushes current path onto the dirs stack
pushd .
pops last pushed path from the dirs stack and cds to it
popd
pushed path list
dirs
l prints the file in wchich the string is, i is ignore case, r recursive
grep -lir "text" *
prints the size of all dirs in home that start with backup
find /home -name backup* -type d -exec du -h {} --max-depth=1 \;
different way to go in tail on a file
less +F logfile
check bash script syntax
bash -n scriptname
renames all images ending with JPG in jpg
for i in *.JPG; do mv $i `basename $i JPG`jpg; done
check if var is a number, only works with int
$var -eq $var
prints last command in history rather than executing it (imagine printing last touch command
instead of grepping through history when you have to touch anm apache tomcat context)
!touch:p
is the "end" of the previous command
!$
is all of the arguments to the previous command
!*
vom file
oops!
^o^i
bash history: & suppresses duplicate entries
export HISTIGNORE="&:[bf]g:exit:mplayer"
no limit to bash history
unset HISTSIZE
unset HISTFILESIZE
which flavour of linux am i on?
lsb_release -d
uname -a
cat /etc/issue
create a sequence from 001 to 100
seq -w 100
starts counting from 1 and go on until user action
yes "" | cat -n
SECONDS is a variable that can be used to track the time a function took to complete, as in:
SECONDS=0; sleep 5 ; echo "that took approximately $SECONDS seconds"
easy to understand
killall -STOP -m firefox
killall -CONT -m firefox
test this, also as ALT- and input a number
ALT-.
searching for regular expression patterns in folders names
find . -type d -regextype posix-egrep -regex "./gwt-([0-9].[0-9].[0-9])"
port 8080 is opened but what process is it related to?
lsof -i :8080
change database_column_names to camelCaseColumnNames and print them to standard output
sed 's/_\([a-z]\)/\U\1/g' <file
print line 23451, efficient on large files
sed '52q;d' <largefile
create a 20MB file
dd if=/dev/zero of=dati bs=1024k count=20
go back
cd -
execute last command
!!
tell me if Tomcat is running and please, do not show the grep instance (trick is [t])
ps -ef | grep [t]omcat