Linux Commands and File System Management
Essential Linux Commands and File Management
ULI101: Introduction to UNIX/Linux and the Internet – Week 1, Lesson 2
Basic Linux Command Structure
- Command Format:
command argument1 argument2 ...- Examples:
pwd: Display current directory.date: Show current date and time.ls: List files in the current directory.ls /etc: List files in/etcdirectory.ls -l: Detailed file listing in the current directory.ls -l /etc: Detailed file listing in/etcdirectory.
- Examples:
Getting Help with Commands
man command: View manual for any Linux command.- Example:
man ls
- Example:
- Search Help:
man -k <keyword>: Search for commands related to a keyword.- Example:
man -k copy
Man Command Navigation Shortcuts
- ENTER: Move down one line.
- SPACEBAR: Move one screen down.
- Ctrl + b: Move one screen up.
- /pattern: Search for a pattern.
- q: Quit the man page.
General Linux Commands
pwd: Display current directory.cd <dir-pathname>: Change directory.ls -l / -a / -R / -d<dir-pathname>: List directory contents.cal <month> <year>: Display calendar.date: Show date and time.who: List users logged in.whoami: Display your username.clear: Clear the screen.passwd <username>: Change password.
Command Line Editing Shortcuts
- Ctrl + l: Clear screen.
- Ctrl + u: Clear command line.
- Up/Down Arrow: Scroll through command history.
- Backspace: Delete character before the cursor.
- Ctrl + w: Delete word before the cursor.
- Ctrl + a: Move to the beginning of the command line.
- Ctrl + e: Move to the end of the command line.
- Alt + f / Alt + b: Move forward/backward one word.
ULI101: Introduction to UNIX/Linux and the Internet – Week 2, Lesson 1
Unix/Linux File Management Concepts
Purpose of Directories:
- Organize files (e.g., text, images, documents) within your account.
- Directories can contain sub-directories for better organization.
Unix/Linux File System:
- Hierarchical structure starting from the “root directory” (
/). - No drive letters like in Windows (e.g., C:, D:).
- Use the
treecommand to display the directory tree diagram.
- Hierarchical structure starting from the “root directory” (
Directory Pathnames:
- Pathnames specify the location of files within the file system.
- Use slash (
/) as the delimiting character. - Example:
/home/your-seneca-id
Common Unix/Linux Directories:
/: Root directory (ancestor to all directories)./home: Stores users’ home directories./home/username: Specific user’s home directory./bin,/usr/bin: Common system binaries (commands)./usr/sbin: Utilities for system administration./etc: System administration files (e.g.,passwd)./var: Dynamic files (logs, mail files)./tmp,/var/tmp: Temporary files./dev: Device driver files (terminals, printers).
Filename Rules:
- Case sensitive: Use lowercase letters.
- Consistent naming schemes.
- Use meaningful, short, and descriptive names.
- Avoid spaces in directory names; use periods, hyphens, or underscores.
- Avoid non-alphanumeric characters as they may have special meanings.
Managing Directories
Common Commands:
mkdir -p: Create directories (with parent directories if needed).rmdir: Remove empty directories.rm -r -i: Remove directories and their contents with confirmation.ls -l -d -R,tree: List directory contents or display directory structure.cp -R: Copy directory and its contents.mv: Move directory and its contents.
Determining File Types:
- Use
ls -lto list directory contents with details. - The first character indicates file type:
d: Directory-: Regular fileb,c: Device file
- Use
Hidden Files:
- Files starting with a period (
.) are hidden. lswithout arguments doesn’t show hidden files.ls -a: Show all files, including hidden files.ls -A: Show all files, excluding current (.) and parent (..) directories.
- Files starting with a period (
