Bash Scripts, snippets and examples

Bash Script

Snippets and Examples

Skip to content
  • Bash Manual

How to move files starting with special chars as dashes

November 21, 2013bashmv, special charsadmin

If it has come that you have tried to scape, enclose or do whatever to files starting with for example a dash, so as you can rename it, or copy it or scp it and didn’t find out how, this is how you can do it:

 bash | 
 
 copy code |
?

1
mv -file-with-a-dash file-without-dash
2
3
4
5
#one of the possible ways

Leave a comment

Recursively copy and rename files with find and sed

October 29, 2013bashfind, sedadmin

Script to recursively copy and rename files with find and sed
 

2
mv ./-file-with-a-dash file-without-dash
3
 bash | 
 
 copy code |
?

1
find aber/cs25010/ -iname "*.txt" -printf 'cp %p %p\n' \

Compare two Directories Using Diff

October 29, 2013bashcommand, diffadmin

Compare directories using diff.

    | sed 's/\.txt$/\.php/' \

 

Batch dvd vob to one avi

October 29, 2013bashavi, dvd, vobadmin

Convert your dvd to avi in one command.

    | while read l; do eval $l; done
2

Enable / Disable Screen Sharing in Terminal

October 23, 2013bashadmin

No description :/

 bash | 
 
 copy code |
?

1
diff -qr dirA dirB  | sort 

 bash | 
 
 copy code |
?

1
cat *.vob | ffmpeg -i - -ab 192k -ar 48000 -b 1800k -vcodec libxvid -acodec libmp3lame "name goes here.avi"
 bash | 
 
 copy code |
?

1
# To enable screen sharing: 

 bash | 
 
 copy code |
?

1
sudo sh -c "/bin/echo -n enabled > /private

 bash | 
 
 copy code |
?

1
/etc/ScreenSharing.launchd" 

Move small files to separate directory in one command

October 23, 2013bashcommand, find, for, loop, mvadmin

Loop files under a set weight to move it to a directory.

 bash | 
 
 copy code |
?

1
# To disable screen sharing: 

Check httpd.conf syntax in Apache Severs

October 23, 2013bashapache, conf, httpdadmin

Some times its hard to make changes to productions servers configuration. In apache you can check http.conf syntax before you restart or reload the service.

 bash | 
 
 copy code |
?

1
sudo sh -c "/bin/rm /private/etc/ScreenSharing.launchd" 

Check if a program (ex: Chrome) is installed

October 23, 2013bashapt, command, dpkg, grepadmin

This command works in systems running apt . With dpkg you can list all packages installed and the output is filtered with grep.

 bash | 
 
 copy code |
?

1
for f in `find . -iname "*.JPG" -size -500k`; do mv ${f} small; done
2

 bash | 
 
 copy code |
?

1
# /usr/sbin/httpd -t 

Delete empty directories

October 23, 2013bashdelete, directory, emptyadmin

Delete all empty directories found with find

 bash | 
 
 copy code |
?

1

Ext3 format USB Drive on Linux

October 23, 2013bashcommand, ext3, format, mkfs, usbadmin

Format an usb drive from cli. With fdisk you can list existing partitions in the system.

 bash | 
 
 copy code |
?

1
dpkg −l | grep chrome
2
 bash | 
 
 copy code |
?

1
find -depth -type d -empty -exec rmdir {} \; 
3
 bash | 
 
 copy code |
?

1
fdisk -l 

Posts navigation

← Older posts

Recent Posts

  • How to move files starting with special chars as dashes
  • Recursively copy and rename files with find and sed
  • Compare two Directories Using Diff
  • Batch dvd vob to one avi
  • Enable / Disable Screen Sharing in Terminal

Recent Comments

    Archives

    • November 2013
    • October 2013

    Categories

    • bash

    Meta

    • Log in
    • Entries feed
    • Comments feed
    • WordPress.org
    Proudly powered by WordPress