SyntaxStudy
Sign Up
Linux / Bash File & Directory Management
Linux / Bash Beginner 10 min read

File & Directory Management

Linux provides powerful commands for creating, copying, moving, and deleting files and directories. Understanding these commands is fundamental to working on any Linux system.

Example
# Create directories
mkdir projects
mkdir -p projects/webapp/src  # create nested directories

# Create files
touch index.html
touch file1.txt file2.txt file3.txt  # create multiple

# Copy files
cp source.txt destination.txt
cp -r source_dir/ dest_dir/  # copy directory recursively

# Move/rename files
mv oldname.txt newname.txt
mv file.txt ~/Documents/

# Delete files
rm file.txt
rm -rf directory/   # remove directory and contents (CAREFUL!)
rm -i file.txt      # ask for confirmation

# View file contents
cat file.txt              # display entire file
head -n 20 file.txt      # first 20 lines
tail -f /var/log/app.log # follow log file in real-time
less file.txt            # paginated view (q to quit)

# Find files
find . -name "*.log"     # find by name
find /var -size +10M     # find files larger than 10MB
find . -newer file.txt   # find files newer than file.txt