snippets with tag 'linux'

Python : cross platform library loader helperdrax's answer for loading a named or absolute library on any platform :)
import os, sys, ctypes

# Types reminder:
#!/usr/bin/python
# String  : ctypes.c_char_p
# Integer : ctypes.c_int
# Long    : c_ulonglong

def loadbinlib(libname="", libpath=""):
   if not libpath:
       if sys.platform in ['win32','win64']:
          libpath = '%s.dll' % libname
       elif sys.platform in ['mac']:
          libpath = '%s.dylib' % libname
       elif sys.platform in ['linux', 'linux2']:
          libpath = '%s.so' % libname
   return ctypes.CDLL(libpath)
tags : python, system, linux, windows

Shell : trouver tous les fichiers qui contiennent un patternAffiche toutes les lignes contenant 'todo' (insensible a la casse avec -i) dans tous les fichiers .py du repertoire en cours et recursivement. Affiche 2 lignes au dessous et en dessous du match, le nom du fichier, et colore les matches dans le term. 'todo' peut etre une expression régulière.
#!/bin/sh

find . -iname '*.py' -exec grep -H -B 2 -A 2 --color -i todo {} \;
tags : system, linux, regexp, bash

Shell : Liste fichiers récemment modifiés (récursif)
find . -type f -printf "%TY-%Tm-%Td %TT %p\n" | sort | less
tags : system, linux

Shell : Compter le nombre total de lignes dans un dossier (récursif)
#!/bin/sh
find . -type f -exec wc -l "{}" \; | awk ' { sum += $1 } END {print sum}'
tags : system, linux

all tags : python, system, vlc, video, apache, proxy, linux, django, MySQL, .NET, XML, XSL, regexp, bat, windows, bash, git

back to snippets home
site réalisé et hébergé par revolunet © 2009 - informations légales