//Tips tagged cat
Latest tips by RSS
Click here to subscribe
Follow Shell-Fu on Twitter
Click here to follow
Follow Shell-Fu on identi.ca
Click here to follow
It is possible to hide a rar archive inside a png image file and then retrieve the files from this image.
This can also be done on Windows:
When you want to retrieve the hidden files, download the image, rename to .rar and extract.
cat picture.png archive.rar > hidden_archive_in_pic.png
This can also be done on Windows:
copy picture.png + archive.rar hidden_archive_in_pic.png
When you want to retrieve the hidden files, download the image, rename to .rar and extract.
If, like me, you often make mistakes on the command line, try using the history shortcut '^^' to repeat the last command with changes.
For example:
For example:
$ cat fiel cat: fiel: No such file or directory $ ^el^le cat file
You can view unprintable and non ASCII characters in a file with 'cat -v -t -e'
Example:
In this file there is a tab between the two words and 4 spaces at the end of the line that would not have been visible with a plain cat.
Example:
$ cat myfile Hello, World! $ cat -v -t -e myfile Hello, ^IWorld! $
In this file there is a tab between the two words and 4 spaces at the end of the line that would not have been visible with a plain cat.
If you want to surround the output of a command by a header or a footer try the following:
For example
$ command | cat headerFile - footerFile
For example
$ ls *txt | cat header - footer Here is a list of files: 1.txt 2.txt End of file list
Zero out files leaving directory and file sets in place - used for archival purposes.
command line:
This example zeros all mp2/mp3/mpc of any case anywhere under the current directory + sub directories and tells you what got zapped.
Do the same thing for all files in a directory from a file manager (such as rox) menu shortcut.
The method of calling this script depends on the file manager. With rox you right click on a file (such as a directory) and select "Customize menu" on the selected file sub menu. A rox window pops open with all the menu items for that file type and you can then open rox /usr/local/bin and drag and drop a link for xt-zerofiles.
I recommend a link instead of a copy so if you update the script you dont have to figure out where you copied it. The custom menu is my single favorite rox feature.
The script pops open a small bash window to ask for verification due to the risk of running such a command arbitrarily. And yes, I keep two logs there, you could reduce it to the $HOME/.zero-log or even have no logging.
/// Cataboligne
/// bash script file: cdn (located in /usr/local/bin) #!/bin/bash # # Cataboligne - zero a single file passed in argument 1, and make a log entry # cat /dev/null > "$1" echo "zero $1" >> $HOME/.zero-log /// end bash script
command line:
find -wholename '*/*.[mM][pP][32cC]' -exec echo {}\; -exec cdn {} \;
This example zeros all mp2/mp3/mpc of any case anywhere under the current directory + sub directories and tells you what got zapped.
Do the same thing for all files in a directory from a file manager (such as rox) menu shortcut.
/// bash script file: xt-zerofiles (located in /usr/local/bin)
#!/bin/bash
#
# Cataboligne - zero all files in a directory structure with double logging
# and verify, called from rox sub menu
#
cd "$@"
echo "" > /tmp/.cont
xterm -geometry 70x1 -title 'Zero Caution!' -e 'read -p "zero files in $PWD: Y/N? " RSP;echo $RSP > /tmp/.cont'
RSP2=`cat /tmp/.cont`
if [[ "$RSP2" != "Y" && "$RSP2" != "Yes" && "$RSP2" != "y" ]]; then exit; fi;
echo >> $HOME/.zero-log-summary
echo >> $HOME/.zero-log
echo $(date) " zero fn() = $PWD" >> $HOME/.zero-log-summary
echo "------------------------------" >> $HOME/.zero-log-summary
echo $(date) " zero fn() = $PWD" >> $HOME/.zero-log
echo "------------------------------" >> $HOME/.zero-log
find -type f -exec cdn {} \;
rm -f /tmp/.cont
echo >> $HOME/.zero-log-summary
echo >> $HOME/.zero-log
/// end bash script
The method of calling this script depends on the file manager. With rox you right click on a file (such as a directory) and select "Customize menu" on the selected file sub menu. A rox window pops open with all the menu items for that file type and you can then open rox /usr/local/bin and drag and drop a link for xt-zerofiles.
I recommend a link instead of a copy so if you update the script you dont have to figure out where you copied it. The custom menu is my single favorite rox feature.
The script pops open a small bash window to ask for verification due to the risk of running such a command arbitrarily. And yes, I keep two logs there, you could reduce it to the $HOME/.zero-log or even have no logging.
/// Cataboligne
Tired to get your mailbox full of cron information messages?
Eg.: some programs (pg_dump, /etc/init.d/xxx, ...) output informational messages on stderr, but you can't close stderr because it may also contain failure informations.
Eg.: some programs (pg_dump, /etc/init.d/xxx, ...) output informational messages on stderr, but you can't close stderr because it may also contain failure informations.
#!/bin/bash
LOG="/tmp/myscript-`date +%s`.tmp" IGNORE='^(Username: Password:|)[[:space:]]*$' # message to ignore, for demonstration only exec 3<&2; exec 2>$LOG # duplicate stderr for later use; redirect stderr to $LOG file
# insert your code (eg.: echo -e "login\npassword"|pg_dump -u user > file.dump)
exec 2<&3 # restore stderr # if $LOG file is not empty and contain anything else than what should be ignored, output it to stderr (for demonstration purpose) [ -s $LOG ] && egrep -vq $IGNORE $LOG && egrep -v $IGNORE $LOG >&2 rm -f $LOG
CASE: You've relocated Subversion and Trac repositories to another machine/directories. You don't want to edit n+1 trac.ini files.
You have for example:
/repos/svn-myprojects/my-first-project
/repos/trac-myprojects/my-first-project
/repos/svn-myprojects/my-second-project
/repos/trac-myprojects/my-second-project
...etc...
Change ALL trac.ini repository_dir settings:
trac-mass-repodir-edit.sh:
Usage:
Then you want to resync and upgrade all existing Tracs:
trac-mass-upgrade.sh:
Usage:
Now you have everything in order.
You have for example:
/repos/svn-myprojects/my-first-project
/repos/trac-myprojects/my-first-project
/repos/svn-myprojects/my-second-project
/repos/trac-myprojects/my-second-project
...etc...
Change ALL trac.ini repository_dir settings:
trac-mass-repodir-edit.sh:
#!/bin/bash TRACSPATH=$1 REPOPATH=$2 for i in $( find $TRACSPATH -maxdepth 1 -type d | grep -v "^$TRACSPATH\$" ); do BN=`basename $i` INIPATH=$i/conf/trac.ini TMP=$i/conf/trac.ini-temp # Replace repository_dir cat $INIPATH | perl -pe "s@repository_dir = .*@repository_dir = $REPOPATH/$BN@i" > $TMP mv $INIPATH $INIPATH-old && mv $TMP $INIPATH && rm $INIPATH-old done
Usage:
./trac-mass-repodir-edit.sh /repos/trac-myprojects /repos/svn-myprojects
Then you want to resync and upgrade all existing Tracs:
trac-mass-upgrade.sh:
#!/bin/bash
TRACSPATH=$1
REPOPATH=$2
for i in $( find $TRACSPATH -maxdepth 1 -type d | grep -v "^$TRACSPATH\$" ); do
BN=`basename $i`
# SVN directory exists
if [ -d $REPOPATH/$BN ]; then
echo "Processinc Trac: $BN.."
trac-admin $i resync
trac-admin $i upgrade
fi
done
Usage:
./trac-mass-upgrade.sh /repos/trac-myprojects /repos/svn-myprojects
Now you have everything in order.
Print a file until a regular expression is matched.
cat file.txt | perl -pe "exit if(/Last line we want/)"
This short script reads a file line-by-line ( whith whitespace characters too ) and outputs to STDOUT.
#!/bin/bash FILE='/path/to/filename' for linecount in `seq $(cat $FILE | wc -l)`; do line=`head -n$linecount $FILE | tail -1` echo $line done

