Bash – Adams Bros Blog http://blog.adamsbros.org Sun, 03 Jan 2016 04:55:36 +0000 en-US hourly 1 https://wordpress.org/?v=5.2.2 Linux Disk Usage Exclude Dot Directories http://blog.adamsbros.org/2015/12/13/linux-disk-usage-exclude-dot-directories/ http://blog.adamsbros.org/2015/12/13/linux-disk-usage-exclude-dot-directories/#respond Sun, 13 Dec 2015 21:26:36 +0000 http://blog.adamsbros.org/?p=615 I’m always searching for how to do this because I keep forgetting. So here it is, no more searching.

du -mcs /home/user/* /home/user/.[!.]* | sort -n
]]>
http://blog.adamsbros.org/2015/12/13/linux-disk-usage-exclude-dot-directories/feed/ 0
Backups Made Simple http://blog.adamsbros.org/2015/08/31/backups-made-simple/ http://blog.adamsbros.org/2015/08/31/backups-made-simple/#respond Mon, 31 Aug 2015 21:57:03 +0000 http://blog.adamsbros.org/?p=593 I’ve had complex backup solutions in the past, which I wrote myself with rsync and bash.  I’ve recently got sick and tired of the issues that come up now and then with them, so I decided to keep it extremely simple. So, I decided to opt for a couple of rsync only shell scripts. I get emails every time they run, as part of cron.

So, the cronjobs look like this…

0 8-19 * * 1 /home/trenta/backup/monday-rsync.sh
0 8-19 * * 2-5 /home/trenta/backup/daily-rsync.sh

monday-rsync.sh…

#!/bin/bash
# /home/trenta/backup/monday-rsync.sh
/usr/bin/rsync -avH --exclude-from=/home/trenta/backup/daily-excludes.txt /home/trenta/ /media/backup/trenta-home/

daily-rsync.sh…

#!/bin/bash
# /home/trenta/backup/daily-rsync.sh
/usr/bin/rsync -avH --exclude-from=/home/trenta/backup/daily-excludes.txt --link-dest=/media/backup/trenta-home/ /home/trenta/ /media/backup/trenta-home-$(/bin/date +'%w')/
]]>
http://blog.adamsbros.org/2015/08/31/backups-made-simple/feed/ 0
Save Bash History Realtime http://blog.adamsbros.org/2014/11/18/save-bash-history-realtime/ http://blog.adamsbros.org/2014/11/18/save-bash-history-realtime/#comments Wed, 19 Nov 2014 02:49:52 +0000 http://blog.adamsbros.org/?p=525 I kind of get sick of my work computer dying, and then I lose some history because I forgot to exit my terminal sessions.  I’ve always used the histappend feature, but this prompt command thing is great. 😀  Thank you Stack Exchange.  The other benefit of this is that each terminal immediately receives the new history next time you press enter.

shopt -s histappend # append to history, don't overwrite it
export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND"
]]>
http://blog.adamsbros.org/2014/11/18/save-bash-history-realtime/feed/ 1
Compress All Log Files http://blog.adamsbros.org/2014/11/04/compress-all-log-files/ http://blog.adamsbros.org/2014/11/04/compress-all-log-files/#respond Tue, 04 Nov 2014 18:26:44 +0000 http://blog.adamsbros.org/?p=463 I decided to start being more active with this blog.  I’ve always wanted a personal indexer for all the things I learn in Linux or software development.  Might as well make this blog that index.

So, you want to gzip all the log files in a particular directory right?  Well, you better be sure that you’re not doing that to live files, so just check them with lsof…

find /var/log/somefolder -type f | while read -r file; do lsof "$file"; if [ $? -eq 1 ]; then gzip "$file"; fi; done
]]>
http://blog.adamsbros.org/2014/11/04/compress-all-log-files/feed/ 0
Removing spaces from filenames http://blog.adamsbros.org/2010/06/13/removing-spaces-from-filenames/ http://blog.adamsbros.org/2010/06/13/removing-spaces-from-filenames/#respond Mon, 14 Jun 2010 03:38:08 +0000 http://blog.adamsbros.org/?p=275 If you use bash under unix, Linux, or Mac OS X, and you’re continually forgetting how to convert filenames with spaces to filenames without spaces, then look no further.

I use dash (-) for the final space replacement, as it looks sharp IMO.

find ./ -name '* *' -type f -print0 | \
while IFS= read -r -d $'\0' file; do 
 echo "$file" "${file// /-}"; 
done

I figured if it takes me a few minutes each time to figure it out, it’s worth documenting. And, if it’s worth documenting, it’s worth sharing with others. I hope this was useful. If it is, please leave a comment.

]]>
http://blog.adamsbros.org/2010/06/13/removing-spaces-from-filenames/feed/ 0