Posts

Showing posts from December, 2017

Learn basic regex for Linux in 2 minutes

re  :  strings in which ^a : a is the beginning char a$ : a is the end char a? : 0 or 1 a a+ : 1 or more a a* : 0 or more a ^a : doesn't contains a . : matches any character {3,5} : range of 3 to 5 [abcf] : matches any one of a,b,c or f [[:space:]] : matches spaces [[:space:]]{4,} : matches 4 or more spaces [a-z] : a to z [a-zA-Z] :  a to z and A to Z d : any digit s : space w : any alphabet w+(.ab)w+(53) : grouping (.ab) into group 1 and (53) into group 2, use them using \1,\2 Exercises: 1. ab(cd)ef to abcdef  rename -f 's/\([a-zA-Z0-9]+\)//g' * 2. ab_cde_f to ab cde f  rename -f 's/_/ /g' * 3. 0abcde to abcde  rename -f 's/(0)+([0-9a-zA-Z-.]+)/$2/g' * 4. a.enbc to a bc  rename -f  's/\.en/ /g' * 5. a-bcdef to a bcdef  rename -f  's/-/ /g' * 6. AbcDeF to abcdef  rename -f  'y/A-Z/a-z/' *

Some basic linux hacks

Image
#Sharing files on local server: sender:target dir$ python3 -m http.server port receiver$ wget -r sender_ip:port/{name of file or folder}     Or sender:target dir$ tar -cz . | nc -q 10 -l -p 45454 receiver$ nc -w 10 $REMOTE_HOST 45454 | tar -xz #Pushing  a local GIT repository to remote #Pulling a GIT remote repository: #To download an EDX course: 1. Download edx-dl from  https://github.com/coursera-dl/edx-dl 2. Now browse to downloaded dir and type: sudo python setup.py install 3. Now authenticate (your credentials will be protected as per author of edx-dl): edx-dl -u chap.rishabhk173@gmail.com --list-courses 4. Now use link of one of the course links from output of previous command: edx-dl -u chap.rishabhk173@gmail.com link #To rename files in all subdir recursively changing name1 in filename to name2: find . -type f -exec rename 's/name1/name2/g' *.vtt '{}' \; #To rename files, appending it's parent