How to create a UUID in bash?

See the uuidgen program which is part of the e2fsprogs package. According to this, libuuid is now part of util-linux and the inclusion in e2fsprogs is being phased out. However, on new Ubuntu systems, uuidgen is now in the uuid-runtime package. To create a uuid and save it in a variable: uuid=$(uuidgen) On my Ubuntu … Read more

How to run a command multiple times, using bash shell?

I don’t think a command or shell builtin for this exists, as it’s a trivial subset of what the Bourne shell for loop is designed for and implementing a command like this yourself is therefore quite simple. Per JimB’s suggestion, use the Bash builtin for generating sequences: for i in {1..10}; do command; done For … Read more

What are the functional differences between .profile .bash_profile and .bashrc

.bash_profile and .bashrc are specific to bash, whereas .profile is read by many shells in the absence of their own shell-specific config files. (.profile was used by the original Bourne shell.) .bash_profile or .profile is read by login shells, along with .bashrc; subshells read only .bashrc. (Between job control and modern windowing systems, .bashrc by … Read more

How do I get the current Unix time in milliseconds in Bash?

This: date +%s will return the number of seconds since the epoch. This: date +%s%N returns the seconds and current nanoseconds. So: date +%s%N | cut -b1-13 will give you the number of milliseconds since the epoch – current seconds plus the left three of the nanoseconds. and from MikeyB – echo $(($(date +%s%N)/1000000)) (dividing … Read more

How can I sort du -h output by size

As of GNU coreutils 7.5 released in August 2009, sort allows a -h parameter, which allows numeric suffixes of the kind produced by du -h: du -hs * | sort -h If you are using a sort that does not support -h, you can install GNU Coreutils. E.g. on an older Mac OS X: brew … Read more

How do I know the script file name in a Bash script?

For reading through a symlink1, which is usually not what you want (you usually don’t want to confuse the user this way), try: IMO, that’ll produce confusing output. “I ran foo.sh, but it’s saying I’m running bar.sh!? Must be a bug!” Besides, one of the purposes of having differently-named symlinks is to provide different functionality … Read more

bash sh – command not found 

Remove ; from the end of your script lines. This doesn’t happen in my bash, so I’m not sure what exactly is wrong, but my guess is this: ; is a separator of commands. Since your last command ends in ;, your bash probably expects another command after. Since the script finishes, though, it reads an empty command, which … Read more

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