Extract substring in Bash
echo 'someletters_12345_moreleters.ext' | cut -d'_' -f 2
output
12345
ip route show | grep default | cut -d' ' -f 3
output
178.134.45.216
References
https://stackoverflow.com/questions/428109/extract-substring-in-bash
echo 'someletters_12345_moreleters.ext' | cut -d'_' -f 2
output
12345
ip route show | grep default | cut -d' ' -f 3
output
178.134.45.216
References
https://stackoverflow.com/questions/428109/extract-substring-in-bash
sudo nano /etc/redis/redis.conf
# requirepass foobared
Uncomment it by removing the #
, and change foobared
to a secure password.
sudo systemctl restart redis.service
References
https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-redis-on-ubuntu-20-04
sudo mysql
-- for MySQL ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root'; -- for MariaDB ALTER USER 'root'@'localhost' IDENTIFIED VIA mysql_native_password USING PASSWORD('root');
With a single query we are changing the auth_plugin
to mysql_native_password
and setting the root password to root and there isn’t any need to restart mysqld or start it with special privileges.
References
https://stackoverflow.com/questions/41645309/mysql-error-access-denied-for-user-rootlocalhost
ffmpeg -i filename.mp4 filename.mp3
fixed bit rate :
ffmpeg -i video.mp4 -b:a 192K -vn music.mp3
variable bit rate :
ffmpeg -i in.mp4 -q:a 0 -map a out.mp3
variable bit rate of 165 with libmp3lame encoder :
ffmpeg -vn -sn -dn -i input.mp4 -codec:a libmp3lame -qscale:a 4 output.mp3
References
https://superuser.com/questions/332347/how-can-i-convert-mp4-video-to-mp3-audio-with-ffmpeg
https://superuser.com/questions/1463710/convert-mp4-to-mp3-with-ffmpeg
grep tom /etc/passwd
ignore word case
grep -i "tom" /etc/passwd
References
https://www.howtoforge.com/tutorial/linux-grep-command/
sudo systemctl disable apparmor
References
https://linuxconfig.org/how-to-disable-apparmor-on-ubuntu-20-04-focal-fossa-linux
An environment variable can be in three types:
1. Local Environment Variable
a)
$ VAR1='TecMint is best Site for Linux Articles' $ echo $VAR1 $ unset VAR1 $ echo $VAR1
b)
$ export VAR='TecMint is best Site for Linux Articles' $ echo $VAR $ VAR= $ echo $VAR
c)
$ VAR2='TecMint is best Site for Linux Articles' $ echo $VAR2 $ env -i bash $ echo $VAR2
2. User Environment Variable
a) Modify .bashrc
file in your home directory to export or set the environment variable you need to add. After that source the file, to make the changes take effect. Then you would see the variable (‘CD’ in my case), taking effect. This variable will be available every time you open a new terminal for this user, but not for remote login sessions.
$ vi .bashrc
Add the following line to .bashrc
file at the bottom.
export CD='This is TecMint Home'
Now run the following command to take new changes and test it.
$ source .bashrc $ echo $CD
To remove this variable, just remove the following line in .bashrc file and re-source it:
b) To add a variable which will be available for remote login sessions (i.e. when you ssh to the user from remote system), modify .bash_profile
file.
$ vi .bash_profile
Add the following line to .bash_profile
file at the bottom.
export VAR2='This is TecMint Home'
When on sourcing this file, the variable will be available when you ssh to this user, but not on opening any new local terminal.
$ source .bash_profile $ echo $VAR2
Here, VAR2 is not initially available but, on doing ssh to user on localhost, the variable becomes available.
$ ssh tecmint@localhost $ echo $VAR2
To remove this variable, just remove the line in .bash_profile
file which you added, and re-source the file.
NOTE: These variables will be available every time you are logged in to current user but not for other users.
3. System wide Environment Variables
a) To add system wide no-login variable (i.e. one which is available for all users when any of them opens new terminal but not when any user of machine is remotely accessed) add the variable to /etc/bash.bashrc
file.
export VAR='This is system-wide variable'
After that, source the file.
$ source /etc/bash.bashrc
Now this variable will be available for every user when he opens any new terminal.
$ echo $VAR $ sudo su $ echo $VAR $ su - $ echo $VAR
Here, same variable is available for root user as well as normal user. You can verify this by logging in to other user.
b) If you want any environment variable to be available when any of the user on your machine is remotely logged in, but not on opening any new terminal on local machine, then you need to edit the file – '/etc/profile'
.
export VAR1='This is system-wide variable for only remote sessions'
After adding the variable, just re-source the file. Then the variable would be available.
$ source /etc/profile $ echo $VAR1
To remove this variable, remove the line from /etc/profile
file and re-source it.
c) However, if you want to add any environment which you want to be available all throughout the system, on both remote login sessions as well as local sessions( i.e. opening a new terminal window) for all users, just export the variable in /etc/environment file.
export VAR12='I am available everywhere'
After that just source the file and the changes would take effect.
$ source /etc/environment $ echo $VAR12 $ sudo su $ echo $VAR12 $ exit $ ssh localhost $ echo $VAR12
Here, as we see the environment variable is available for normal user, root user, as well as on remote login session (here, to localhost).
To clear out this variable, just remove the entry in the /etc/environment file and re-source it or login again.
NOTE: Changes take effect when you source the file. But, if not then you might need to log out and log in again.
References
https://www.tecmint.com/set-unset-environment-variables-in-linux/
killall gnome-software rm -rf ~/.cache/gnome-software
References
https://www.linuxuprising.com/2019/03/fix-gnome-software-stuck-with-software.html
If you are using wine installed from the repositories then wine related files is stored in a folder called ~/.wine
Windows programs are stored within this folder – for example :
~/.wine/drive_c/program_files/Internet Explorer
You can start a windows program in a similar way as from a command line in windows but prefix it with wine
wine "c:\program files\internet explorer\iexplore.exe"
References
https://askubuntu.com/questions/65487/invoke-a-wine-installed-application-from-command-line
Configuring an Interface with Static Network Settings Using ifcfg Files
For example, to configure an interface with static network settings using ifcfg
files, for an interface with the name enp1s0, create a file with the name ifcfg-enp1s0
in the /etc/sysconfig/network-scripts/
directory, that contains:
DEVICE=enp1s0 BOOTPROTO=none ONBOOT=yes PREFIX=24 IPADDR=10.0.1.27
Configuring an Interface with Dynamic Network Settings Using ifcfg Files
DEVICE=em1 BOOTPROTO=dhcp ONBOOT=yes