Linux Basic Commands
Linux provides a set of powerful and commonly used commands to interact with the system efficiently. The cd command is used to change directories, while ls lists the contents of a directory. To clear the terminal screen, the clear command is used. The mkdir command helps create new folders, and pwd shows the current working directory. The rm command is used to remove files or directories, and touch is used to create empty files. To edit or view text files directly in the terminal, vi is a powerful editor. The / symbol represents the root directory, which is the top level of the Linux filesystem. To manage users, adduser is used to create a new user, and userdel is used to delete an existing one. The history command displays a list of previously executed commands, allowing users to track or reuse them easily. These commands form the foundation for working effectively in a Linux environment.
13. touch
touch Command in Linux
The touch command is used to:
-
Create an empty file.
-
Update the timestamp of an existing file (access and modification time).
📌 Syntax:
touch filename
🔹 1. Create a New Empty File
touch myfile.txt
🟢 This creates an empty file named myfile.txt in the current directory.
🔹 2. Create Multiple Files at Once
touch file1.txt file2.txt file3.txt
🟢 This creates all three files in one command.
🔹 3. Update Timestamp of Existing File
touch existingfile.txt
🟢 If existingfile.txt already exists, touch will not delete it — it simply updates the last modified time to the current time.
🔹 4. Change Timestamp to Specific Time
touch -t 202507011200 myfile.txt
🟢 This sets the time to 1st
July 2025, 12:00 PM.
🔹 5. Don’t Create New File (Only Update if Exists)
touch -c myfile.txt
🟢 If the file doesn’t exist, it does nothing.
✅ Summary Table
|
Command |
Description |
|---|---|
|
|
Create a new empty file |
|
|
Create multiple files |
|
|
Update modified time of existing file |
|
|
Set custom timestamp |
|
|
Update time only if file exists |
Try with Linux Practice