Get just the filename from a path in a Bash script [duplicate]

Many UNIX-like operating systems have a basename executable for a very similar purpose (and dirname for the path): pax> full_name=/tmp/file.txt pax> base_name=$(basename ${full_name}) pax> echo ${base_name} file.txt That unfortunately just gives you the file name, including the extension, so you’d need to find a way to strip that off as well. So, given you have … Read more

How to urlencode data for curl command?

Use curl –data-urlencode; from man curl: This posts data, similar to the other –data options with the exception that this performs URL-encoding. To be CGI-compliant, the <data> part should begin with a name followed by a separator and a content specification. Example usage: curl \ –data-urlencode “paramName=value” \ –data-urlencode “secondParam=value” \ http://example.com See the man … Read more

Stopping scripters from slamming your website

How about implementing something like SO does with the CAPTCHAs? If you’re using the site normally, you’ll probably never see one. If you happen to reload the same page too often, post successive comments too quickly, or something else that triggers an alarm, make them prove they’re human. In your case, this would probably be … Read more

How can you find and replace text in a file using the Windows command-line environment?

A lot of the answers here helped point me in the right direction, however none were suitable for me, so I am posting my solution. I have Windows 7, which comes with PowerShell built-in. Here is the script I used to find/replace all instances of text in a file: powershell -Command “(gc myFile.txt) -replace ‘foo’, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)