Friday, June 24, 2011

Transfer files using ssh

'scp' command to copy files and directories to the server: 

scp your_file_name login@remoteserver.com:path to copy files, 
and scp –r your_directory_name login@remoteserver.com:path to copy entire directories.

grep character count

Use grep to count the frequency of a character in a file:

grep o 'character' filename | wc -l

Wednesday, June 22, 2011

Difference between continue and pass in python

Pass is a "do-nothing" statement. Best used with a if-else or try-except condition

Continue means "jump to start of loop", ignoring rest of the statements in the loop

Code Output

for r in [1,2,3]:
   print(r)
   continue
   print(r,"\tagain")

1
2
3

for r in [1,2,3]:
   print(r)
   pass
   print(r,"again")



1
(1, 'again')
2
(2, 'again')
3
(3, 'again')



for r in [1,2,3]:
   if r%2!=0:
      print(r)
   else:
      pass


1
3


for r in [1,2,3]:
   if r%2==0:
      continue
   print(r)


Bad coding practice according to me but nevertheless this is possible.


1
3

Allow wget to overwrite files

Default behavior of wget is to make new files if files of same name are downloaded again, appended with a counter.

wget filename > filename
wget filename > filename.1
wget filename > filename.2

To overwrite the existing file with the new downloads without creating new files, the answer is:

On GNU Wget 1.12 built on linux-gnu:

Use wget -N filename