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
More Posts related to Linux,
- Rename a directory using Linux/Unix command
- ls command to list only directories
- How to Restart or Reload Nginx Server Service on Linux
- 3 ways to clear screen on Linux Terminal
- ls command: sort files by name alphabetically A-Z or Z-A [Linux/Unix/macOS/Bash]
- Copy entire directory using Terminal Command [Linux, Mac, Bash]
- Fix: sudo: unable to open Read-only file system
- Create Hidden File or Directory using Shell Command
- Command to know the installed Debian version?
- The Date Command and its usage [Linux - Unix - macOS]
- Fix - bash: man: command not found
- How to tar.gz a directory or folder Command
- How to Display content of a file in Terminal Screen?
- How to change bash terminal prompt string and color
- Sort ls command by last modified date and time
- Execute .bin and .run file Ubuntu Linux
- zsh hello world example
- How to check uptime of Linux/Unix/macOS system/server using console command?
- [Fix] Linux - bash: useradd: command not found
- Command to check Last Login or Reboot History of Users and TTYs
- How to install and Configure sar sysstat tools in Ubuntu Linux
- How to use SCP Command to Copy Directory
- Linux Remove or Delete Files and Directories using Terminal Commands
- How to connect to SSH port other than default 22
- Install OpenSSL on Linux/Ubuntu
More Posts:
- Validate email address in Python using regular expression (regex) - Python
- How to the Install Official Android Emulator for Mac? - Android
- List of Programming Languages Supported by Notepad++ - NotepadPlusPlus
- Mac: How to Merge Cells in Excel - MacOS
- Enable Spellcheck in eclipse workspace - Eclipse
- zsh hello world example - Linux
- Keyboard shortcuts to format Source code in Microsoft Visual Studio Code IDE - Microsoft
- How to mute or disable Twitter Fleet in feeds - Twitter