Hi there,
Recently I came up with a problem related to filename of downloaded files.In my college I use DC(Direct Connect) client to download files from other peers.Recently I downloaded a large number of music videos which remained in temporary directory and did not move to music directory.Although It downloaded completely, It remained in temporary directory and hence name of files was in the format "filename.(avi/mpg/flv etc.).(some chars).dctmp". So I had to rename them.Definitely, I couldn't do it manually as there were more than 1000 files.Hence I tried to write a bash script for renaming all of them at once.
Initially I tried to store the filename as "*.*.dctmp" in which I would trim the "*.dctmp" part.Hence the remaining part would the desired filename(with proper externsion).But storing the filename like that did not work out.
Then I saw that in temp files, there is a common pattern that before "dctmp" extension, there are exactly 39 chars. Then I tried a different method of trimming filename which is explained below with code.
code :
for i in *.dctmp
do
len="${#i}" ;
let len-=46
#echo "$len";
name="${i:0:len}" ;
#echo "$name"
mv "$i" "$name" ;
done
save it with name.sh and run "bash name.sh" on terminal.The script should be run in the same directory in which temp files are present.
e.g. Guns N' Roses - Welcome To The
jungle.mpg.47IMRQGAGFWOA7GMLZTK3X6QFIGR4P4EKHDRHKI.dctmp became Guns N' Roses - Welcome To The Jungle.mpg
Worked on ubuntu 10.10
I am Gaurav kumar, did M.Sc.(tech) in Information Systems from BITS pilani, India (2008-12). Software programmer and founding team member at GreyOrange (2012-present), Volunteer @FeedingIndia
Showing posts with label CLI. Show all posts
Showing posts with label CLI. Show all posts
Sunday, April 24, 2011
Wednesday, April 6, 2011
Various Aspects of a GNU Debugger
This blog is intended to give a brief overview of GDB and some internal features. GDB is an interactive tool. GDB should be responsive to the user.
GDB can do four main kinds of things (plus other things in support of these) to help you catch bugs in the act:
* Start your program, specifying anything that might affect its behavior.
* Make your program stop on specified conditions.
* Examine what has happened, when your program has stopped.
* Change things in your program, so you can experiment with correcting the effects of one bug and go on to learn about another.
GDB consists of three major subsystems:
1. User interface: The user interface consists of several actual interfaces, plus supporting code.
2. Symbol handling (the symbol side): The symbol side consists of object file readers, debugging info interpreters, symbol table management, source language expression parsing, type and value printing.
3.Target system handling (the target side): The target side consists of execution control, stack frame analysis, and physical target manipulation.
GDB uses a technique called prologue analysis to find frame sizes and saved registers. A prologue analyzer disassembles the function's machine code starting from its entry point, and looks for instructions that allocate frame space, save the stack pointer in a frame pointer register, save registers, and so on.
Breakpoint Handling:
Hardware breakpoints are sometimes available as a builtin debugging features with some chips. Typically these work by having dedicated register into which the breakpoint address may be stored. If the program counter ever matches a value in a breakpoint registers, the CPU raises an exception and reports it to gdb.
GDB can do four main kinds of things (plus other things in support of these) to help you catch bugs in the act:
* Start your program, specifying anything that might affect its behavior.
* Make your program stop on specified conditions.
* Examine what has happened, when your program has stopped.
* Change things in your program, so you can experiment with correcting the effects of one bug and go on to learn about another.
GDB consists of three major subsystems:
1. User interface: The user interface consists of several actual interfaces, plus supporting code.
2. Symbol handling (the symbol side): The symbol side consists of object file readers, debugging info interpreters, symbol table management, source language expression parsing, type and value printing.
3.Target system handling (the target side): The target side consists of execution control, stack frame analysis, and physical target manipulation.
GDB uses a technique called prologue analysis to find frame sizes and saved registers. A prologue analyzer disassembles the function's machine code starting from its entry point, and looks for instructions that allocate frame space, save the stack pointer in a frame pointer register, save registers, and so on.
Breakpoint Handling:
Hardware breakpoints are sometimes available as a builtin debugging features with some chips. Typically these work by having dedicated register into which the breakpoint address may be stored. If the program counter ever matches a value in a breakpoint registers, the CPU raises an exception and reports it to gdb.
Monday, March 21, 2011
password reset from shadow file in ubuntu 10.10
Hi,
Recently I was trying to write a script for changing password automatically for a user.I required something else for this but I found one similar script while searching over Internet.While I was experimenting with this on my ubuntu 10.10 system, I did a terrible mistake.At the place of username, I put my main account username.Not only this,I used "pwgen" program to generate random password which was there in the script and I blindly used it.
The script I used is below:-
touch pass.txt
chmod 600 pass.txt
# generate a nice secure password and put it in a file
pwgen > pass.txt
# get the password hash
ph=$(makepasswd --clearfrom=pass.txt --crypt-md5 |awk '{print $2}')
# Set the password
usermod -p $ph "username"
Now, first time I used it using sudo, It asked for password.Now this script randomly generated a new passowrd and set for my account.Now, a new password was hashed in /etc/shadow file which I didn't know.Next time, when I used it again,it asked for password which was changed randomly.So,I could not give correct password.
Now, I thought how would I login after next reboot.I asked someone who told me to use a live cd of ubuntu to change shadow file.In shadow file, password is stored encrypted corresponding to each username.Now, I was preparing for a back up.Still, I wasn't sure it will work.
When I rebooted,something clicked in my mind.I booted in recovery mode.Then using root shell, I opened /etc/shadow file.Usually it opens in read-only mode.But since I was root that time, I removed the hash of my username.I removed everything that was there between first 2 colon(:). I did it only for my username and root.Hence, password was omitted.Now I reboot again and reset the password using passwd command and it didn't ask for current password.I didn't know that we could reset our password in recovery mode.
I knew that this similar method worked in ubuntu 8.04. But I thought they removed this as a bug.Now it worked for me.I can't decide if it is a good or bad thing.Since I changed my password in emergency,It is cool. But someone else can access my account by resetting my password.
Recently I was trying to write a script for changing password automatically for a user.I required something else for this but I found one similar script while searching over Internet.While I was experimenting with this on my ubuntu 10.10 system, I did a terrible mistake.At the place of username, I put my main account username.Not only this,I used "pwgen" program to generate random password which was there in the script and I blindly used it.
The script I used is below:-
touch pass.txt
chmod 600 pass.txt
# generate a nice secure password and put it in a file
pwgen > pass.txt
# get the password hash
ph=$(makepasswd --clearfrom=pass.txt --crypt-md5 |awk '{print $2}')
# Set the password
usermod -p $ph "username"
Now, first time I used it using sudo, It asked for password.Now this script randomly generated a new passowrd and set for my account.Now, a new password was hashed in /etc/shadow file which I didn't know.Next time, when I used it again,it asked for password which was changed randomly.So,I could not give correct password.
Now, I thought how would I login after next reboot.I asked someone who told me to use a live cd of ubuntu to change shadow file.In shadow file, password is stored encrypted corresponding to each username.Now, I was preparing for a back up.Still, I wasn't sure it will work.
When I rebooted,something clicked in my mind.I booted in recovery mode.Then using root shell, I opened /etc/shadow file.Usually it opens in read-only mode.But since I was root that time, I removed the hash of my username.I removed everything that was there between first 2 colon(:). I did it only for my username and root.Hence, password was omitted.Now I reboot again and reset the password using passwd command and it didn't ask for current password.I didn't know that we could reset our password in recovery mode.
I knew that this similar method worked in ubuntu 8.04. But I thought they removed this as a bug.Now it worked for me.I can't decide if it is a good or bad thing.Since I changed my password in emergency,It is cool. But someone else can access my account by resetting my password.
Saturday, April 10, 2010
GPG public key
Hi,
As I was searching why my gpg public key is not working,I suddenly found answer.Actually gpg public key contains some extra words also which I neglected.public key can be viewed in terminal by typing :
gpg --armor --export [your public key id]
Now complete output is the public gpg key including "-----BEGIN PGP PUBLIC KEY BLOCK-----" and "-----END PGP PUBLIC KEY BLOCK-----".Initially I was taking only middle part.One more thing public key requires public key id which can be viewed by typing "gpg --list-keys". The pub part shows id.This command displays whole list of keys.So, if someone has made more than one key pairs,then it is useful to see which public key is for which public key id.As I successfully generated my public key, I am going to share it. It is right below :-
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1.4.9 (GNU/Linux)
mQGiBEu+azsRBACGVGTbi3GHDKa8rkzOWP8lQYg0omH6mU5tIHe+0fLiTMRzbr1o
/lTT2w+GksRhziWL03+zTc36R/gNAPJvp8djhaeDpYD0DCh1JuFNLPAZWVMQ1TJf
INgQ59KoBr/sWHWa0DXTFoTK1o/0wLsUioH54nN4rfxsPQgKMA5f/FYEzwCgitK5
WeQWsm8RMkZURaROcq7kHE0D/0GsXazBA0n+iQFVbbjblOpzs0/nvJfnEWKEbyCv
e9NUrbNqvttA501uy+VeIlMIbVzIOHAMeIpgWMT+z6vVYcBmKrZGCRv0i9gBzrd/
8HVWbVrZDwz7Mk076f/1wo5iLv9OP657O6i3B4F/1fiBmJubTQkXgL5nKwu1iQvj
wTfDBACAcLMha0rBLji4l3MCHpwYVb/vCs1OsGWmDlRElkST6zqv8bg9/O2AZqgE
fewe8ZqcYyRMlElsoqXlL0z+JZykCp4QUGwajB/oWCdecFK09uOU518Os90wLjro
LvAZmebkmoR2gsy3J9QBar7Lp63Y1AfxZGiCQU9/a5+0OIGCbrQ6Z2F1cmF2IGt1
bWFyIHlhZGF2IChlbmNyeXB0aW9uKSA8Z2F1cmF2a3VtYXI1NTJAZ21haWwuY29t
PohgBBMRAgAgBQJLvms7AhsDBgsJCAcDAgQVAggDBBYCAwECHgECF4AACgkQdFo6
7FlOrR11+gCbBsVq1jpmwo1JE10bcO5UEWySlRkAn0JuAhWtePIR8pK14NasjSNO
xDg8uQINBEu+azsQCACLKpR8orOIiaooO+fI2IEVFL8Qb+s/9/dfx/asMoBB2bAS
IhpNt6N65a3MtMhDeIZcfafwtpgjxJAuxp1iwWpbEyj2vDWcZ5xpnf3N3hrb8wm9
eBpGnGj7ugETBgNZ/G3aQJsljv6Ze+Ys83wQ20mdXTTIg3Yc/bzlohE0Itl3JgMW
BioI13pxXcWgxcPMBBeeoL0bBGCQOhjCTckjVjoJTrHxXvxqembTeUQ8wG6tnLj7
HIMOtKp9usF83H0qvDhiYjGJ7xI5KplJXyEw9+T1afrHY7KcggMmwOdHvuTrKI62
XIpX3eVFu7zDh5cA7tMtbErSpSZxhskPNPYpQYKzAAMFCACCUEAJHO9FHL9zq7fR
GNcx5o4TaNsplBpq42zFnd14pq1ftxr5SfUVn6ciPVkGnj9v5LVOxib0SJCgcDCw
mGkQ5SmD3XCq/KDqjSlFYacLJOIH/sKMWmkLrF7Nv5o0VrQbSdzPCCWCbNsiFoad
Zb5bGXtOrg2nLj6uIUe5ZM3EUJr/iMFRhZ9Xk4ETTsqyD95yfdM8y+Djnri3bdTg
eL3QriiZu3k0CJGcBu/lYWcVR7wseIUa7LYsLuGhzH3zyFuZHw8NqUls4H7UQel1
dMut5SGo6Ksn0n9UwyKzUe+Eir49efX+gMivn+ttupOZ2t7OcCH6IaCr0Y6E1Iz6
BCveiEkEGBECAAkFAku+azsCGwwACgkQdFo67FlOrR0zFACfdSLkUkkvO++A6XyH
2ItqsnYVgCQAn0iB1mZ1eI7xuUyR6y+teREIc4Bf
=+Uo3
-----END PGP PUBLIC KEY BLOCK-----
And Now I am working on sending a mail with encryption by my private key.Hope,It works.
As I was searching why my gpg public key is not working,I suddenly found answer.Actually gpg public key contains some extra words also which I neglected.public key can be viewed in terminal by typing :
gpg --armor --export [your public key id]
Now complete output is the public gpg key including "-----BEGIN PGP PUBLIC KEY BLOCK-----" and "-----END PGP PUBLIC KEY BLOCK-----".Initially I was taking only middle part.One more thing public key requires public key id which can be viewed by typing "gpg --list-keys". The pub part shows id.This command displays whole list of keys.So, if someone has made more than one key pairs,then it is useful to see which public key is for which public key id.As I successfully generated my public key, I am going to share it. It is right below :-
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1.4.9 (GNU/Linux)
mQGiBEu+azsRBACGVGTbi3GHDKa8rkzOWP8lQYg0omH6mU5tIHe+0fLiTMRzbr1o
/lTT2w+GksRhziWL03+zTc36R/gNAPJvp8djhaeDpYD0DCh1JuFNLPAZWVMQ1TJf
INgQ59KoBr/sWHWa0DXTFoTK1o/0wLsUioH54nN4rfxsPQgKMA5f/FYEzwCgitK5
WeQWsm8RMkZURaROcq7kHE0D/0GsXazBA0n+iQFVbbjblOpzs0/nvJfnEWKEbyCv
e9NUrbNqvttA501uy+VeIlMIbVzIOHAMeIpgWMT+z6vVYcBmKrZGCRv0i9gBzrd/
8HVWbVrZDwz7Mk076f/1wo5iLv9OP657O6i3B4F/1fiBmJubTQkXgL5nKwu1iQvj
wTfDBACAcLMha0rBLji4l3MCHpwYVb/vCs1OsGWmDlRElkST6zqv8bg9/O2AZqgE
fewe8ZqcYyRMlElsoqXlL0z+JZykCp4QUGwajB/oWCdecFK09uOU518Os90wLjro
LvAZmebkmoR2gsy3J9QBar7Lp63Y1AfxZGiCQU9/a5+0OIGCbrQ6Z2F1cmF2IGt1
bWFyIHlhZGF2IChlbmNyeXB0aW9uKSA8Z2F1cmF2a3VtYXI1NTJAZ21haWwuY29t
PohgBBMRAgAgBQJLvms7AhsDBgsJCAcDAgQVAggDBBYCAwECHgECF4AACgkQdFo6
7FlOrR11+gCbBsVq1jpmwo1JE10bcO5UEWySlRkAn0JuAhWtePIR8pK14NasjSNO
xDg8uQINBEu+azsQCACLKpR8orOIiaooO+fI2IEVFL8Qb+s/9/dfx/asMoBB2bAS
IhpNt6N65a3MtMhDeIZcfafwtpgjxJAuxp1iwWpbEyj2vDWcZ5xpnf3N3hrb8wm9
eBpGnGj7ugETBgNZ/G3aQJsljv6Ze+Ys83wQ20mdXTTIg3Yc/bzlohE0Itl3JgMW
BioI13pxXcWgxcPMBBeeoL0bBGCQOhjCTckjVjoJTrHxXvxqembTeUQ8wG6tnLj7
HIMOtKp9usF83H0qvDhiYjGJ7xI5KplJXyEw9+T1afrHY7KcggMmwOdHvuTrKI62
XIpX3eVFu7zDh5cA7tMtbErSpSZxhskPNPYpQYKzAAMFCACCUEAJHO9FHL9zq7fR
GNcx5o4TaNsplBpq42zFnd14pq1ftxr5SfUVn6ciPVkGnj9v5LVOxib0SJCgcDCw
mGkQ5SmD3XCq/KDqjSlFYacLJOIH/sKMWmkLrF7Nv5o0VrQbSdzPCCWCbNsiFoad
Zb5bGXtOrg2nLj6uIUe5ZM3EUJr/iMFRhZ9Xk4ETTsqyD95yfdM8y+Djnri3bdTg
eL3QriiZu3k0CJGcBu/lYWcVR7wseIUa7LYsLuGhzH3zyFuZHw8NqUls4H7UQel1
dMut5SGo6Ksn0n9UwyKzUe+Eir49efX+gMivn+ttupOZ2t7OcCH6IaCr0Y6E1Iz6
BCveiEkEGBECAAkFAku+azsCGwwACgkQdFo67FlOrR0zFACfdSLkUkkvO++A6XyH
2ItqsnYVgCQAn0iB1mZ1eI7xuUyR6y+teREIc4Bf
=+Uo3
-----END PGP PUBLIC KEY BLOCK-----
And Now I am working on sending a mail with encryption by my private key.Hope,It works.
Thursday, April 8, 2010
GPG encryption
recently I came to know about GPG encryption.It means Gnu Privacy Guard.GPG is a command line tool with features for easy integration with other applications also.GPG is mostly used for secure communication and storing data in encrypted form.There are other uses also which I am not discussing right now.
Actually when I was filling a form for account in a site,I was asked for pgp/gpg public key and then I started wandering around to search for it.It is open source and mostly used in command line which I like.There is a windows version of it also.There are so many online pages with uncountable words for its description that I got confused sometime.But finally I figured out the theory behind it.It is like this.
There are 2 type of keys generated by gpg.One is public and another is private.Public keys can be distributed to your friends and published anywhere.With public gpg keys someone can encrypt the message and send it to you.Now, to decrypt it we need the private key which is only with you.So this way emails can be securely sent.Even if somebody sniffs the mail in the middle,It will be secure because the attacker will not have the private key to decrypt it.To create your own key pair just type gpg --gen-key in command line and follow rest instruction(You will mostly choose default values).This way you can export your public keys.But unfortunately my public keys are not working for no reason.I am still looking for answer.
But I did use gpg encryption to my file which is very easy to use and fun to watch.I am going to show what exactly I did.In the terminal just make a simple file. e.g
$ echo "my first encryption" >gen hit enter
$ gpg -e gen it will ask for user ID,use your own user ID
And done! Now hit terminal with ls command and see that there is another file named gen.gpg which is encrypted.Now If you deleted old file named gen then the content can only be viewed by opening gen.gpg which needs password.To decrypt it,put gpg -d gen.gpg in command line and hit enter.Now it will ask for the passphrase which is confidential and it makes the file secure.
Actually when I was filling a form for account in a site,I was asked for pgp/gpg public key and then I started wandering around to search for it.It is open source and mostly used in command line which I like.There is a windows version of it also.There are so many online pages with uncountable words for its description that I got confused sometime.But finally I figured out the theory behind it.It is like this.
There are 2 type of keys generated by gpg.One is public and another is private.Public keys can be distributed to your friends and published anywhere.With public gpg keys someone can encrypt the message and send it to you.Now, to decrypt it we need the private key which is only with you.So this way emails can be securely sent.Even if somebody sniffs the mail in the middle,It will be secure because the attacker will not have the private key to decrypt it.To create your own key pair just type gpg --gen-key in command line and follow rest instruction(You will mostly choose default values).This way you can export your public keys.But unfortunately my public keys are not working for no reason.I am still looking for answer.
But I did use gpg encryption to my file which is very easy to use and fun to watch.I am going to show what exactly I did.In the terminal just make a simple file. e.g
$ echo "my first encryption" >gen hit enter
$ gpg -e gen it will ask for user ID,use your own user ID
And done! Now hit terminal with ls command and see that there is another file named gen.gpg which is encrypted.Now If you deleted old file named gen then the content can only be viewed by opening gen.gpg which needs password.To decrypt it,put gpg -d gen.gpg in command line and hit enter.Now it will ask for the passphrase which is confidential and it makes the file secure.
Labels:
CLI,
encryption,
GPG,
linux,
PGP
Wednesday, July 15, 2009
CLI over GUI
hello folks,
I am learning a bit linux nowadays.so, I thought it would be better to write something related to that.Don't worry , i will not teach you commands here(there are so many sources for that). I was thinking that CLI(command line interface) seems to be boring and cumbersome to use and I know so many people would say the same.Most of us are used to of windows' GUI(graphical user interface).Around 5 months ago my friend bought a laptop and got windows vista as default OS by that company.When i asked him to use linux,he said that as he had been using windows since childhood,he was more comfortable with that.Now i think that how can you compare two things without knowing both. If you also admire GUI then this is for you.CLI has really got some advantages over GUI.lets get it one by one
Shell keeps history of recent commands.its very useful.and, if you have to perform certain operations in sequence then you can create shell scripts also.shell script is just like batch files in windows.
there is one more thing that i have recently come to know.shell is more useful in hardware terms.Shells are much less resources-intensive than GUI's.shell requires less memory.It means that command issued in shell will run more quickly than in GUI.
Only thing that i feel difficult is to remember commands.well,once you get used to it,its much easier than you think.
That's it for today.hope,you got something useful.
I am learning a bit linux nowadays.so, I thought it would be better to write something related to that.Don't worry , i will not teach you commands here(there are so many sources for that). I was thinking that CLI(command line interface) seems to be boring and cumbersome to use and I know so many people would say the same.Most of us are used to of windows' GUI(graphical user interface).Around 5 months ago my friend bought a laptop and got windows vista as default OS by that company.When i asked him to use linux,he said that as he had been using windows since childhood,he was more comfortable with that.Now i think that how can you compare two things without knowing both. If you also admire GUI then this is for you.CLI has really got some advantages over GUI.lets get it one by one
- with a GUI, only the options provided by the interface are available to the user
- lack of space on a screen can limit the number of options that a GUI displays
- no standard methods exist within GUIs for performing standard command-line tasks, such as linking commands in sequences, redirecting output from one destination to another, or collecting commands into scripts
Shell keeps history of recent commands.its very useful.and, if you have to perform certain operations in sequence then you can create shell scripts also.shell script is just like batch files in windows.
there is one more thing that i have recently come to know.shell is more useful in hardware terms.Shells are much less resources-intensive than GUI's.shell requires less memory.It means that command issued in shell will run more quickly than in GUI.
Only thing that i feel difficult is to remember commands.well,once you get used to it,its much easier than you think.
That's it for today.hope,you got something useful.
Subscribe to:
Posts (Atom)