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,
- Command to know the Available Memory on Linux System
- How to install curl on Alpine Linux
- How to backup a file in Linux/Unix
- Install Java Runtime Environment (Oracle or open JRE) on Ubuntu
- What is the Default Admin user and Password for Jenkins
- How to tar.gz a directory or folder Command
- Copy entire directory using Terminal Command [Linux, Mac, Bash]
- Fix: bash: ipconfig: command not found on Linux
- Command to check Last Login or Reboot History of Users and TTYs
- Linux: Create a New User and Password and Login Example
- ls command to list only directories
- bash: cls: command not found
- How to exit from nano command
- Installing and using unzip Command to unzip a zip file using Terminal
- What does apt-get update command does?
- ls command: sort files by name alphabetically A-Z or Z-A [Linux/Unix/macOS/Bash]
- How to remove or uninstall Java from Ubuntu using apt-get
- scp: ssh: connect to host xxxx port 22: Connection refused Error
- Sort ls command by last modified date and time
- Create Nested Directories using mkdir Command
- How to Exit a File in Terminal (Bash/Zsh)
- Command to know the installed Debian version?
- How to connect to SSH port other than default 22
- How to save a file in Nano Editor and Exit
- Install OpenSSL on Linux/Ubuntu
More Posts:
- WARNING: Python 2.7 is not recommended [macOS Big Sur] - MacOS
- How to know installed version of Homebrew - MacOS
- Python: Print Dictionary Line by Line Example - Python
- Java equals method - Tutorial - Java
- How to verify if java is installed on the computer and get version detail - Java
- How to List All Users in Linux - Linux
- You're not on Teams yet, but you can set it up for your organization. [Microsoft Teams Login Error] - Microsoft
- Fix Microsoft Windows Update Error 80072EFE - Microsoft