File Forge
Sculpt Your Linux Landscape using touch, mkdir, rm, and more.

Growing in DevOps, together! π€ | Associate Software Engineer at Tech Mahindra | Enthusiastic about automation, cloud solutions, and efficient software delivery. | Let's connect, collaborate, and learn from each other!
File Operations in Linux
Linux provides several commands to create, manage, and delete files and directories efficiently. Below are some essential file operation commands:
Creating Files - touch
The touch command is used to create an empty file or update the timestamp of an existing file.
Creates an empty file.
touch <file-name>Create Multiple files
touch file1.txt file2.txt file3.txt touch file{1..10}.txt

Creating Directories β mkdir
The mkdir (Make Directory) command is used to create new directories (folders).
Creating a directory
mkdir my_folderCreates a nested directory structure. The -p option ensures that parent directories are created if they donβt exist.
mkdir -p my_folder/sub_folder
Removing Files & Directories β rm
The rm (Remove) command deletes files or directories permanently.
Removing a file
rm file.txt
Deleting a directory and all its contents.
-r stands for "recursive". When used with
rm, it means that if you're deleting a directory,rmwill also delete all the files and subdirectories inside that directory.rm -r my_folder
Removing empty directories - rmdir
If a directory contains any files or subdirectories, rmdir will not delete it and will produce an error message.
It is a safe way to remove directories as it won't delete the directory if it contains any content.
rmdir directory-name
Delete empty directories: find . -type d -empty -delete
Removing multiple files
Removing files starting with x : * β wildcard.
Delete empty files.
find . -type f -empty -delete
Copying Files & Directories β cp
The cp (Copy) command copies files or directories from one location to another.
To copy
file1.txttofile2.txt.cp file1.txt file2.txt
To copy a file to a directory.
cp file.txt /path/to/directoryCopies the entire
folder1(including its contents) tofolder2. The-rflag is required for copying directories.cp -r folder1 folder2
Moving & Renaming Files β mv
The mv (Move) command is used to move files or directories to a new location or rename them.
Renaming file or directory.
mv oldname.txt newname.txtMoving a file to a directory.
mv file.txt /home/user/Documents/
Redirection Operations
It allows you to control the flow of input and output between commands, files, and devices. It is useful for saving command outputs to files, reading from files, or combining multiple commands.
- Output Redirection (
>and>>) : Redirects command output to a file instead of displaying it on the terminal.
Usage:
Overwrite (
>): Saves the output oflsintofile.txt. Iffile.txtalready exists, it overwrites the content.ls > file.txt
Append (
>>): Appends the output oflstofile.txtwithout overwriting existing content.ls >> file.txt

Input Redirection (
<): Takes input from a file instead of typing manually in the terminal.Usage:
Sorts the contents of
file.txtand displays the sorted output.sort < file.txt




