File and Directory Commands
File and directory commands are used to create, copy, rename, move, modify, delete, list files and directories, insert data into files, and manage permissions.
Creating Files
touch filename
: Creates an empty file.touch file1 file2
: Creates multiple empty files (e.g., file1 and file2).touch file{1..n}
: Creates a sequence of files up to n (e.g., file1, file2, …, filen).
Deleting Files
rm filename
: Deletes the specified file (asks for confirmation).rm -f filename
: Force deletes the specified file without confirmation.rm -f file1 file2
: Deletes multiple files (e.g., file1 and file2).rm -f file{1..n}
: Deletes a sequence of files (e.g., file1, file2, …, filen).rm -f *
: Deletes all files in the current directory.rm -f h*
: Deletes all files whose names start with “h” (replace “h” as needed).
Creating Directories
mkdir foldername
: Creates a folder.mkdir folder1 folder2
: Creates multiple folders (e.g., folder1 and folder2).mkdir folder{1..n}
: Creates a sequence of folders up to n (e.g., folder1, folder2, …, foldern).
Deleting Directories
rmdir folder
: Deletes an empty folder.rmdir folder1 folder2
: Deletes multiple empty folders.rmdir *
: Deletes all empty folders in the current directory.rmdir folder{1..n}
: Deletes a sequence of empty folders.rm -rf foldername
: Deletes a non-empty directory along with all its contents.rm -rf *
: Force deletes all files and folders in the current directory.
Listing Files and Directories
ls
: Lists the names of files and directories in the current directory.ll
: Provides a detailed list including permissions, owner, size, and modification date.ll -r
: Lists files and directories in reverse order.ll -a
: Includes hidden files (files starting with.
) in the listing.ll -t
: Lists files and directories sorted by modification time (newest first).
Navigating Directories
cd foldername
: Changes the current directory to the specified folder.pwd
: Displays the absolute path of the current working directory.cd path
: Moves to a specified directory using its full or relative path.cd -
: Switches back to the previous directory.cd ../
: Moves one level up to the parent directory.cd ../../
: Moves two levels up in the directory structure.
Copying and Moving Files
cp source destination
: Copies a file or folder from the source to the destination.mv source destination
: Moves a file or folder from the source to the destination.mv oldname newname
: Renames a file or folder.
Join Telegram
For more content like this, follow us on Telegram!