Linux File and Directory Management Commands
Overview
Linux provides a set of commands for managing files and directories in the filesystem. These commands allow you to create, delete, move, and manipulate files and directories. This document covers basic and commonly used file and directory management commands.
Display Current Directory
pwd
Prints the current working directory.
Example
List Files and Directories
ls
Lists files and directories in the current directory.
Example
ls -l
Lists files and directories with detailed information, including permissions, ownership, and size.
Example
ls -l
# Output:
# -rw-r--r-- 1 user user 1234 Aug 3 10:00 file1.txt
# drwxr-xr-x 2 user user 4096 Aug 3 10:00 directory1
ls -a
Lists all files, including hidden files (those starting with a dot).
Example
Change Directory
cd <directory>
Changes the current working directory to the specified directory.
Example
cd ..
Moves up one directory level.
Example
Create a Directory
mkdir <directory>
Creates a new directory.
Example
mkdir -p <path>
Creates a directory and any necessary parent directories.
Example
mkdir -p /home/user/new_directory/subdirectory
# Creates 'new_directory' and 'subdirectory' if they do not exist
Remove a Directory
rmdir <directory>
Removes an empty directory.
Example
rm -r <directory>
Removes a directory and its contents recursively.
Example
Create an Empty File
touch <file>
Creates an empty file or updates the timestamp of an existing file.
Example
Delete a File
rm <file>
Deletes a specified file.
Example
Move or Rename Files and Directories
mv <source> <destination>
Moves or renames a file or directory.
Example
mv oldname.txt newname.txt
Renames a file or directory.
Example
Copy Files and Directories
cp <source> <destination>
Copies a file or directory to the specified destination.
Example
cp -r <source> <destination>
Copies a directory and its contents recursively.
Example
cp -r directory1 /home/user/backup/
# Copies 'directory1' and all its contents to the 'backup' directory
View File Content
cat <file>
Displays the content of a file.
Example
less <file>
Allows you to view file content one page at a time.
Example
Summary
Linux provides powerful commands for managing files and directories, including creating, deleting, moving, and viewing files. Understanding these commands allows for efficient navigation and manipulation of the filesystem. For more detailed information on each command, refer to the Linux manual pages.