Tag Archive for linux

find the largest top 10 files and directories on a Linux / UNIX / BSD filesystem

du -a directory | sort -n -r | head -n 10

source

Getting Timestamp into BASH Script (or in SSH)

NOW=$(date +'%m.%d.%y at %H:%M:%S')

source

If a ‘bin’ exists in the user home, then add that to the PATH.

# enable bin diretory in PATH when found
if [ -a ~/bin ]; then
    PATH=$PATH:~/bin
fi

source

File size and location

du -akx / | sort -nr | head -n 50

source

Simple rsync backupscript.

#!/bin/sh

RSYNC=/usr/bin/rsync
SSH=/usr/bin/ssh
KEY=$HOME/.ssh/id_dsa_passwdless
RUSER=foo
RHOST=ssh.example.com
RPATH=/var/www/
LPATH=$HOME/archive/example-com/

date=`date "+%Y-%m-%dT%H:%M:%S"`

$RSYNC -v -n -az -e "$SSH -i $KEY" --link-dest=$LPATH/current $RUSER@$RHOST:$RPATH $LPATH/back-$date

rm $LPATH/current && 
 ln -s $LPATH/back-$date $LPATH/current

source

Count the number of files in a Directory / Sub-Directories

ls -1R /path/to/directory | wc -l

source

Combine .rar file in Linux

<a href="mailto:wk@wk-laptop">wk@wk-laptop</a>:$ unrar e -kb iDeneb_v1.6_1058_Lite_Edition.part1.rar 

UNRAR 3.90 beta 2 freeware      Copyright (c) 1993-2009 Alexander Roshal


Extracting from iDeneb_v1.6_1058_Lite_Edition.part1.rar

Extracting  .DS_Store                                                 OK 
Extracting  iDeneb_v1.6_1058_Lite_Edition.iso                         16%

Extracting from iDeneb_v1.6_1058_Lite_Edition.part2.rar

...         iDeneb_v1.6_1058_Lite_Edition/iDeneb_v1.6_1058_Lite_Edition.iso  33%

Extracting from iDeneb_v1.6_1058_Lite_Edition.part3.rar

...         iDeneb_v1.6_1058_Lite_Edition/iDeneb_v1.6_1058_Lite_Edition.iso  50%

Extracting from iDeneb_v1.6_1058_Lite_Edition.part4.rar

...         iDeneb_v1.6_1058_Lite_Edition/iDeneb_v1.6_1058_Lite_Edition.iso  67%

Extracting from iDeneb_v1.6_1058_Lite_Edition.part5.rar

...         iDeneb_v1.6_1058_Lite_Edition/iDeneb_v1.6_1058_Lite_Edition.iso  84%

Extracting from iDeneb_v1.6_1058_Lite_Edition.part6.rar

...         iDeneb_v1.6_1058_Lite_Edition/iDeneb_v1.6_1058_Lite_Edition.iso  OK 
Extracting  Leggimi.rtf                                               OK 
Extracting  md5.rtf                                                   OK 
Extracting  Readme.rtf                                                OK 
All OK

source

Check how long a process has been running (Linux)

ls -ld /proc/{pid}

source

Add fancy stuff to your Git prompt

# Ignore Crap
git config --global core.excludesfile ~/.gitignore
touch               "$HOME/.gitignore"
echo '.DS_Store' >> "$HOME/.gitignore"
echo '._*'       >> "$HOME/.gitignore"
echo '.svn'      >> "$HOME/.gitignore"
echo '.hg'       >> "$HOME/.gitignore"

# Shortcuts
git config --global alias.st status
git config --global alias.ci commit
git config --global alias.co checkout
git config --global alias.br branch

# Colors? YES!
git config --global color.ui auto

# Personal Setup
git config --global user.name "Your Name"
git config --global user.email <a href="mailto:your_email@your-domain.com">your_email@your-domain.com</a>

# Setup Bash Completion
mkdir -p "$HOME/bin"
export PATH="$HOME/bin:$PATH"
echo 'export PATH="$HOME/bin:$PATH"'               >> ~/.bash_profile
cp "$HOME/Downloads/src/git-$GIT_VERSION/contrib/completion/git-completion.bash" ~/bin
echo 'source ~/bin/git-completion.bash'            >> ~/.bash_profile

# Add the current Git Branch to your Bash Prompt
echo "PS1='[<a href="mailto:u@h">u@h</a> w$(__git_ps1 " (%s)")]$ '" >> ~/.bash_profile

source

Copying files faster with rsync on linux

rsync -rv file_path target_path --progress

source