In order to create a hidden file using a shell (Bash, Zsh, or sh) you can make use of the touch, nano, or vi commands by adding a . (dot) at the start of the file name,
Part 1: Create Hidden Files
Example: Create a hidden file using the touch command# touch .my-hidden-file.txt
# ls
# ls -ltrha
total 8.0K
drwxr-xr-x 1 root root 4.0K Apr 2 02:19 ..
-rw-r--r-- 1 root root 0 Apr 2 02:19 .my-hidden-file.txt
drwxr-xr-x 2 root root 4.0K Apr 2 02:19 .
As you can see I created a hidden file using the touch command touch .{file-name}, you can also add an extension to the file name.
Example: Create a hidden file using the nano command# nano .hidden-file.txt
To view the content of the hidden file you need to make sure you again use . (dot) at the start of your file name.
# cat .hidden-file.txt
This is my hidden file.
Part 2: Create Hidden Directories

You can make use of mkdir command with the directory name that starts with a dot just like files.
mkdir .my-hidden-directory
# ls -la
total 16
drwxr-xr-x 3 root root 4096 Apr 2 02:27 .
drwxr-xr-x 1 root root 4096 Apr 2 02:19 ..
-rw-r--r-- 1 root root 24 Apr 2 02:23 .hidden-file.txt
drwxr-xr-x 2 root root 4096 Apr 2 02:27 .my-hidden-directory
-rw-r--r-- 1 root root 0 Apr 2 02:19 .my-hidden-file.txt
- [Fix] Linux - bash: useradd: command not found
- Calculate days between dates using dateutils ddiff command
- pwd Command - Print Working Directory
- Rename a directory using Linux/Unix command
- How to go to the End of File in Nano Editor
- How to tar.gz a directory or folder Command
- How to remove/delete a directory in Linux/macOs
- How to Display content of a file in Terminal Screen?
- ls command sort by file size [Linix/UNIX/macOS/bash]
- How to Copy Entire Directory to another Directory in Linux
- 3 ways to clear screen on Linux Terminal
- Command to check Last Login or Reboot History of Users and TTYs
- How to check uptime of Linux/Unix/macOS system/server using console command?
- How to backup a file in Linux/Unix
- Command to know the installed Debian version?
- Check SSH/OpenSSH version Command
- 3 Commands to stop Nginx Server
- Linux: Create a New User and Password and Login Example
- How to install npm on Ubuntu
- How to List All Users in Linux
- How to Get the List of Shells on Linux
- Fix - ssh-copy-id no identities found error
- Installing and using unzip Command to unzip a zip file using Terminal
- scp: ssh: connect to host xxxx port 22: Connection refused Error
- zsh hello world example
- Set width and height for the label in tkinter - Python
- SharePoint Server 2016 setup error - A system restart from a previous installation or update is pending. Restart your computer and run setup to continue. - SharePoint
- Cant find System Preferences... under macOS Ventura Apple Menu? - MacOS
- Failed to load resource: net::ERR_CACHE_MISS PHP - PHP
- How to Center Align Image in Bootstrap - CSS
- [Tutorial] Write And Run Python Code In Notepad++ Editor - NotepadPlusPlus
- How to know current Ubuntu Linux version via terminal command - Ubuntu
- Read a file line by line in Python Program - Python