Tag Archives: Linux Tutorials

Linux Tutorials and Unix Similar multi-user operating systems based on the Linux kernel and essentially on GNU software. Like CentOS, Debian, Ubuntu Fedora.

list files and directory with dot or no extension in Linux

File management is one of the main tasks of Linux and includes list files and directory with or without dot, the creation, modification, permissions and maintenance of files and directories. There are various scenarios in which we may need to find specific files. In these situations, Linux provides versatile commands in the bash to efficiently find files and directories.

In this tutorial, you will learn how to find dot files and directories in the GNU Bash.

In this tutorial, you will learn how to find files and directories in the GNU Bash without using any additional utilities.

First one of the most used command to list files in a directory.

$ ls -al

or using the-A, --almost-alloption do not list implied . and ..

$ ls -Al
list files in directory be using ls -Al
list files in directory be using ls -Al

Advanced list find dot files and directory

Up to this point it was not a deep knowledge and most Linux users probably know to use list files, so let us expand the commands in bash.

For example, if you only want to list files that start with a (.) dot, in Linux these are hidden files and hidden directories, the common list command is like this.

$ ls -ld .?*

This also works with almost the same output with the next command.

$ ls -dl .[^.]*

Again to list directories themselves, but not their files contents.

$ ls -dl .!(|.)

This command work only in newer GNU bash version 5 and newer.

Next list command shown long listing format for files in any directory.

$ ls -l .*

These listing can be achieved using grep, to list files and directory starting with a dot.

$ ls -a | grep "^\."
.
..
.bashrc
.config
.java
.local
.profile
.viminfo

Search for files in a directory hierarchy using find

Another powerful and versatile command isfindto search for files in a directory hierarchy, here does list files and directories starting with a dot.

$ find . -maxdepth 1 -name ".*"
.
./.local
./.profile
./.config
./.bashrc
./.java
./.viminfo

Next find in the reverse order, list only files starting without dot recursively, no directory.

$ find . -type f ! -name '.*'
./README.txt

Show only directories without dot at the beginning recursively.

$ find . -type d ! -name '.*'
./docs

Thefindcommand also allows the output to be passed to another command. Using thexargsoption does only directories that start with a dot are set permission with run chmod 755 for one directory level.

$ find . -maxdepth 1 -type d -name ".*" | xargs chmod 755

Very useful using the find command for the following scenario, here to set permission for all directories recursively with run chmod 755.

$ find . -type d -print0 | xargs -0 chmod 0755

The same to set permission of all files while run chmod 644 recursively in all directories.

$ find . -type f -print0 | xargs -0 chmod 0644

This find command is also possible with theexecoption, as shown in the next example.

$ find . -type f -exec chmod 644 {} \;

find options

-namesearching name pattern.
-type fsearch relevant files.
-type dsearch relevant directories.
-print0print the full file name on the standard output w/o trailing (LF).
-exec
-xargs
This variant of the -exec action runs the specified command on the selected files. The command line is built in much the same way that xargs builds.
-maxdepthDescend at most levels (a non-negative integer) levels of directories below the starting-points.

Search content with pattern in files recursively

find is also useful for searching patterns in files, let’s say we searching for “Red Hot Chili Peppers“, starting from the current directory recursively in all subdirectories.

$ find . -type f -print0 | xargs -0 grep -n "Red Hot Chili Peppers"
./build/README.txt:16:Red Hot Chili Peppers
./docs/Credits:2:Red Hot Chili Peppers

The output shows the path and line number of the files where the search pattern is found, enabled by the grep option -n. Note. the option -i or --ignore-case due case distinctions in patterns, default is case sensitive.

list only files and directory with no extension

If only list files and directory should be that have no extension, i.e. without dot at the end such as .txt, ran this in the command-line.

$ ls -d !(*.*)
Credits  docs

This command work only in newer GNU bash version 5 and newer.

Sometime we need more detailed output be using the long list format.

$ ls -dl !(*.*)
list files and directory that have no dot extension

Verify the bash release which is available on your system, you can hit and ran this in your /bin/bash.

$ bash --version
GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Forgot MySQL root password, easy reset

Forgot the MySQL server root password?

After forgetting or losing the MySQL root password, there is no need to panic. In this tutorial I will show you how to reset the MySQL root password quickly and easily.

Forgot MySQL root password

Resetting the root password is a simple process. This tutorial shows the simplest method of several for resetting the MySQL root password.

The instructions apply only to the open source database MariaDB, the popular fork of the MySQL database server. Additional shell commands are used that are not available in MySQL.

MySQL Root Password Reset

The following few steps require shell access with a local user account on the system running MariaDB/MySQL, the user must provide sudo rights to execute commands in the terminal shell with elevated privileges.

Stop MySQL server

First stop the MariaDB/MySQL server and terminate the service.

$ sudo systemctl stop mysqld

Start MySQL server without password

Now start a temporary SQL Server instance as follows.

$ sudo -u mysql mysqld --skip-grant-tables &

When the MySQL server is started with the --skip-grant-tables option, the grant tables aren’t loaded, so no access control is applied. Users are able to access the MariaDB/MySQL server now without a password.

You can now log in to the MariaDB/MySQL server as root in a terminal shell without requiring a password.

$ mysql -u root

MySQL Root Password Reset

Next run the command to reset the current permissions.

FLUSH PRIVILEGES;

Now reset the MySQL root password with the following command.

ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassword';

Replace the placeholder “NewPassword” with the desired password.

Finally, re-read the permissions and exit MySQL.

FLUSH PRIVILEGES;
quit

The MySQL root password has now been changed, now the previously started temporary MySQL server is stopped. This can be achieved with the following shell command.

$ ps auxw | grep '\-\-skip-grant-tables' | tail -n 1 | awk '{ print $2 }' | sudo xargs kill

Restart MySQL server

Now restart the MariaDB server and log in with the new password.

$ sudo systemctl start mysqld
$ mysql -u root -p

The MariaDB/MySQL server is under full control again.

Forgot MySQL root password,
Forgot MySQL root password

sudo -u mysql mysqld --skip-grant-tables & after hit the command sometimes you have to press Enter or hit Ctrl+C

Forgot MySQL root password, easy reset
Forgot MySQL root password, easy reset

About MariaDB

MariaDB is a free, open source relational database management system that was created by a fork of MySQL. The project was initiated by MySQL’s former lead developer Michael Widenius, who also developed the storage engine Aria. The structure that MariaDB originally had includes the software layer, which contains the basic functionality of the database, i.e. creating, reading, modifying, deleting data.

Addition

Alternative command to change the MySQL root password.

UPDATE USER set password=PASSWORD('NewPassword') where User='root';
FLUSH PRIVILEGES;
quit

Conclusion

This tutorial shows how to reset the forgotten or losing MySQL server root password. The steps were performed in the GNU bash on an Ubuntu 22.04.3 LTS in WSL and on a virtual Debian 12 (Bookworm) GNU/Linux running MariaDB 10.6.18 database server.