Copy Entire Directory Structure Using Tar
Sometimes you need to copy an entire directory structure to another location on the command line. Here is a quick way to do it using the tar command:
tar cf - * | ( cd /target; tar xfp -)
Fixing Screen Resolution on Second Monitor in Linux
I recently installed a 2nd hard drive in my Macbook Pro dedicated to Linux. When I hooked up a secondary monitor to it I found that I could not get a reasonable resolution. After some research I found that I can add a new mode to the “Display” choices by entering the following in a terminal console:
xrandr # to find the device name cvt 1920 1080 # to generate the mode for the xrandr program. xrandr –newmode “1920x1080_60.00” 173.00 1920 2048 2248 2576 1080 1083 1088 1120 -hsync +vsync # to add the new mode to the monitor choices. xrandr –addmode DP1 1920x1080_60.00 # to associate the new mode to the monitor.
Sort Directory by File Size
To sort files in a directory and to list them by the biggest file first:
$ du -a | sort -n -r | more
Alternatively you can use:
$ du -s * | sort -n -r | more
Count Occurences of a Character in a String
Sometimes I need to know how many times a specific character occurs in a string. The best tool to use for something like that is AWK. Let’s say we’re looking for the count of commas in a string: string=“text,text,text,text” char="," echo “${string}” | awk -F"${char}" ‘{print NF-1}’
Talkin' Trash
Having trouble getting the “Empty Trash” working in Thunar? Remove "~/.config/xfce4/xfconf/xfce-perchannel-xml/thunar*".
Uptime Statistics for Windows
To find the uptime for a Windows machine do
C:> net statistics server
Alternative to Using cp
To backup files from a source directory to a backup directory:
$ mkdir /path/to/backup/directory
$ cd $HOME/source/directory
$ tar cf - . | (cd /path/to/backup/directory && tar xBvf -)
Define the following alias:
tar cvf - . | ( cd \!* ; tar xvf - )
or as an alias:
alias cpbytar='tar cvf - . | ( cd \!* ; tar xvf - )'
(The alias definition above is for Bash)
To do a recursive copy of a directory to another location, preserving the PERMISSIONS and OWNERSHIP of the files. “cd” to the source location and invoke the following alias:
git Tips
A useful tip to beautify your output is to use:
$ git log --graph --decorate --oneline --abbrev-commit --all --date=local
when looking at your log entries. Or you can add
[alias]
lola = log --graph --decorate --pretty=oneline --abbrev-commit --all --date=local
to your ~/.gitconfig file to use $ git lola as an alias.