File System Commands
A cheatsheet for navigating and managing files and directories on a Linux system.
Navigation
Change directory
cd /path/to/directoryNavigates to the specified directory.
cd ..Navigates to the parent directory.
cdNavigates to the home directory of the current user while the home directory is stored in the environment variable `HOME`.
cd ~Also navigates to the home directory of the current user but uses special ~ notation which means "home" directory.
cd ~usernameNavigates to the home directory of the specified user if you have privileges.
cd -Switches to the previous directory you were in.
Show current directory
pwdPrints the full path of the current working directory.
Listing Files and Directories
List contents of a directory
lsLists the files and subdirectories in the current directory.
Detailed list with options
ls -l Shows a long listing with detailed information for each file or directory. The output columns typically represent:
`Permissions` | `Links` | `Owner` | `Group` | `Size` | `Modification Date` | `Name`
ls -aIncludes hidden files and directories (those that start with a dot `.`)
ls -ASimilar to `-a`, but does not show the `.` (current directory) and `..` (parent directory) entries.
ls -hWhen used with `-l`, it displays file sizes in a human-readable format (e.g., 1K, 234M, 2G).
ls -laA common combination to see a detailed list of all files, including hidden ones.
ls -1Lists all files, one per line
Creating and Removing
Create a directory
mkdir new_directory_nameCreates a new directory with the specified name.
Create an empty file
touch new_file_name.txtCreates a new, empty file or updates the timestamp of an existing file.
Remove a file
rm file_to_remove.txtDeletes a file. It may prompt you for confirmation depending on file permissions.
Remove a directory
rm -r directory_to_removeRecursively removes a directory and all of its contents.
Forcefully remove files/directories
rm -rf directory_to_removeThis is a powerful and dangerous command that **recursively** and **forcefully** removes a directory and its contents without any prompts. Use with extreme caution.