Showing posts with label shell. Show all posts
Showing posts with label shell. Show all posts

Thursday, December 4, 2014

Ubuntu - 3 tricks to copy DVD into iso file

Built in command

cat /dev/sr0 > /home/Documents/mydisk.iso
dd if=/dev/sr0 of=/home/Documents/mydisk.iso

If both cat, and dd not work because of '/dev/sr0': Input/output error
If I run dmesg, I recieve a lot of Buffer I/O error on device sr0

Try ddrescue in Ubuntu the package is gddrescue
sudo apt-get install gddrescue
ddrescue --direct --block-size=2048 --no-split /dev/sr0 /home/Documents/mydisk.iso

Now you can open iso file with VLC

Tuesday, December 2, 2014

Linux find command for files or folders older than .....

Find files and folders in current working directory older than 60 days
find ./* -maxdepth 0 -mtime +60

Find only folders in /mnt/media -> child folder -> grandchild exclude these folder notme, dtran, xXXx older than 3 years
find /mnt/media -maxdepth 2 -mtime +1095 -type d -not \( -path "./notme*" -o -path "./dtran*" -o -path "./xXXx*" \) > ~/Folder2Backup.txt

Remove all files that have xxx in names and older than 2 years
find ./ -type f -name "*xxx*.*" -mtime +730 -exec rm "{}" \;

Windows not a big deal, install Cygwin and Finding Nemoooo
find /cygdrive/f -maxdepth 2 -type d -mtime +730 > ~/dir_older_than_2years.txt

Find directory older than 2 years and list its size
find /cygdrive/f -maxdepth 1 -type d -mtime +730 -exec du -sh "{}" \; 

Friday, November 28, 2014

Listing directory in Graphical format in Bash

ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/   /' -e 's/-/|/'

Script from centerkey.com: http://www.centerkey.com/tree/tree.sh
#!/bin/sh
#######################################################
#  UNIX TREE                                          #
#  Version: 2.3                                       #
#  File: ~/apps/tree/tree.sh                          #
#                                                     #
#  Displays Structure of Directory Hierarchy          #
#  -------------------------------------------------  #
#  This tiny script uses "ls", "grep", and "sed"      #
#  in a single command to show the nesting of         #
#  sub-directories.  The setup command for PATH       #
#  works with the Bash shell (the Mac OS X default).  #
#                                                     #
#  Setup:                                             #
#     $ cd ~/apps/tree                                #
#     $ chmod u+x tree.sh                             #
#     $ ln -s ~/apps/tree/tree.sh ~/bin/tree          #
#     $ echo "PATH=~/bin:\${PATH}" >> ~/.profile      #
#                                                     #
#  Usage:                                             #
#     $ tree [directory]                              #
#                                                     #
#  Examples:                                          #
#     $ tree                                          #
#     $ tree /etc/opt                                 #
#     $ tree ..                                       #
#                                                     #
#  Public Domain Software -- Free to Use as You Like  #
#  http://www.centerkey.com/tree  -  By Dem Pilafian  #
#######################################################
echo
if [ "$1" != "" ]  #if parameter exists, use as base folder
   then cd "$1"
   fi
pwd
ls -R | grep ":$" |   \
   sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/   /' -e 's/-/|/'
# 1st sed: remove colons
# 2nd sed: replace higher level folder names with dashes
# 3rd sed: indent graph three spaces
# 4th sed: replace first dash with a vertical bar
if [ `ls -F -1 | grep "/" | wc -l` = 0 ]   # check if no folders
   then echo "   -> no sub-directories"
   fi
echo
exit

Add it to your system. Please watch out the code before running it!
curl http://www.centerkey.com/tree/tree.sh > /usr/bin/tree
chmod +x /usr/bin/tree
 
 http://stackoverflow.com/questions/3455625/linux-command-to-print-directory-structure-in-the-form-of-a-tree

Compare 2 directory in Linux

Let's make an example. Create 2 folder and put files in it
mkdir dir{1,2}
touch dir1/{1,2,3,4,5,6}.txt
touch dir2/{2,4,5,7,9}.txt

ls -R dir1
dir1:
1.txt  2.txt  3.txt  4.txt  5.txt  6.txt

ls -R dir2
dir2:
2.txt  4.txt  5.txt  7.txt  9.txt

diff -r dir1 dir2
Only in dir1: 1.txt
Only in dir1: 3.txt
Only in dir1: 6.txt
Only in dir2: 7.txt
Only in dir2: 9.txt

http://stackoverflow.com/questions/16787916/difference-between-2-directories-in-linux