Paul’s Linux Blog

Just Another Uber-Geek

I found myself today needing to move some files around but unfortunately they had spaces in them and would not move as expected.

A quick solution soon found using the infamous 'FIND' command and some examples.

the most basic kind of search is as follows:

 find . -name "*.avi" -print

It quite simply finds all files the have .avi on the end.

However sometimes you need a bit more, say you want to see the file sizes for these files:

 find . -name "*.avi" -exec ls -l {} ;

Now we should get the file attributes for each file found, note the {} expand during the execution of the script and are replaced by the filenames found.

Lets say we want to move these files into the same directory, but some files we don't want to move, we could use the following command for this:

 find / -name *.avi -a ! -name *Clip* -a ! -name *clock* -exec cp -v {} /usb01/ ;

The command in this example says find in directory "/" files with .avi AND (-a) NOT (!) Clip or clock, then execute the copy command (cp) filename into /usb01/

The next part is to remove original files, this could all be done on the same command line but I like to check things have worked before committing to a delete.

 find / -name *.avi -a ! -name *Clip* -a ! -name *clock* -exec rm -v {} ;

496 find / -name "*.avi" -exec file {} ;

I also cam across the following command that search the path ie the directory name as well, I have not used it yet but thought I would add it.

You can match the entire filename with -path instead of -name.

 
find . -path '*/139.P/*smooth' -exec mv "{}" destination ;

Hope this explains some of the mysteries of the find utility.

The other day I connected my laptop to my work via VPN, great I thought now to connect to my laptop from my work PC using SSH computer say's NO! :(

I could log into to my work desktop however from the laptop, It turns out my works firewall blocks the port 22 so ssh fails to connect, not wanting to give up I thought maybe using an SSH tunnel to my work PC and then use the work PC to connect back to my laptop through the tunnel, after some googling I finally worked it out and managed to get it to work. :)

The code below works as follows:

-N stops the command from executing on remote server, without it you end up logged onto the remote server.

-R Remote Port

What this happens is the port 22 on the localhost (my laptop) uses ssh to connect to the work desktop and binds to port 2210, after entering my password the connection is made.

ssh -N -R 2210:localhost:22 work.desktop.com

To connect to my laptop I use the below command, this makes an ssh connection from my work desktop to it's port 2210, as this a tunnel the ssh is automatically forwarded to my laptop and tada the connection is made. :)

ssh -p 2210 localhost

See toic.org for more info

Numero Uno!

No comments

I have been using Linux since 2002, I have worked on AIX, SCO, Redhat and recently Solaris as a system administrator,  in this time I have learned a lot but still find myself barely scratching the surface.

I have used many different flavors of Linux at home in this time ranging from Fedora, PCLOS, Ubuntu and recently Crunchbang, which is now my preferred Linux of choice on my Laptop and Server read this blog to find out why.

More and more I find myself playing with Linux and increasing my knowledge, I will try and document it so I don't have to remember it :)

Feel free to join me on my Linux Adventure,  subscribe to my blog feed.

Powered by WordPress Web Design by SRS Solutions © 2010 Paul’s Linux Blog Design by SRS Solutions