This guide contains key commands for managing files and directories in Linux, which will be useful for every DevOps specialist.
Working with Files and Directories
- ls -lah — Display a list of files with detailed information
- cd /path — Navigate to the specified directory
- pwd — Show the full path to the current directory
- mkdir new_dir — Create a new folder
- rm -rf file/dir — Completely delete a file or directory
- cp file1 file2 — Copy a file or folder
- mv file1 file2 — Move or rename a file
- touch file.txt — Create a new empty file
- cat file — Display the contents of a file in the terminal
- tail -f file — Show new lines of a file in real-time
Viewing and Editing Files
- less file — View a file page by page
- head -n 10 file — Display the first 10 lines of a file
- tail -n 10 file — Display the last 10 lines of a file
- nano file — Open a file in the Nano editor
- vim file — Open a file in the Vim editor
- grep "error" file — Find a line containing "error" in a file
Managing Permissions and Ownership
- chmod 755 file — Set file permissions (rwxr-xr-x)
- chown user:group file — Change file owner
- umask 022 — Set file creation mask
Archiving and Compression
- tar -cvf archive.tar folder/ — Create a tar archive
- tar -xvf archive.tar — Extract a tar archive
- tar -czvf archive.tar.gz folder/ — Create a compressed tar.gz archive
- tar -xzvf archive.tar.gz — Extract a tar.gz archive
- zip -r archive.zip folder/ — Create a zip archive
- unzip archive.zip — Extract a zip archive
Working with Symbolic Links
- ln -s /path/to/target link_name — Create a symbolic link
- ls -l link_name — Check the link
- readlink -f link_name — Find out where the link points
Disk Usage Monitoring
- df -h — Check available disk space
- du -sh file/ — Get the size of a file or folder
- du -h --max-depth=1 /path — Get the size of folders in the specified directory
Useful Tricks
- history | grep command — Find a command in history
- !! — Repeat the last command
- !n — Execute the nth command from history
- df -h | grep "/dev/sd" — Show only physical disks
- find /path -name "*.log" — Find files with the .log extension
FAQ
- Can deleted files be recovered after rm -rf?
In most cases, no. The rm -rf command removes files permanently without sending them to trash. To prevent accidental loss, you can use tools like trash-cli or configure aliases that move files to a "safe trash" directory instead of immediate deletion. - How do I copy a folder along with its contents?
Use:cp -r source_dir destination_dir
The -r (recursive) option ensures that all subdirectories and files are copied.
- How can I quickly find a file on the system?
Run:find / -name "filename"
This searches the entire system. Alternatively, if the locate utility is installed and its database is updated (updatedb), locate filename will return results much faster.
- What’s the difference between ls -l and ls -lah?
ls -l shows detailed file information (permissions, owner, size, date).
ls -lah adds human-readable file sizes (K, M, G) and shows hidden files. - How can I check disk space usage in Linux?
Use:df -h
for available disk space in human-readable format, and
du -sh folder/
to check the size of a specific folder.
- Which editor should I use: Nano or Vim?
Nano - simple and beginner-friendly, great for quick edits.
Vim - more powerful, widely used by sysadmins and DevOps, but has a steeper learning curve.
Conclusion
This Linux cheat sheet provides the most essential commands for working with files, directories, and disk space. Mastering these commands will make everyday tasks like copying, moving, searching, and archiving files much faster and more efficient.
For DevOps engineers, system administrators, and developers, these commands are a foundation of daily workflow. Whether you’re writing automation scripts, managing servers, or troubleshooting production issues, strong command-line skills will save you time and reduce errors.
Keep practicing these commands in real projects, combine them with pipes (|) and filters (grep, awk, sed), and you’ll quickly become fluent in Linux system management.