Mastering Linux commands can significantly improve your efficiency in the terminal. Whether you’re a beginner or an experienced user, these handy tips will help you navigate, manage files, and optimize your workflow.
1. Switch Back to the Last Directory
If you need to quickly return to the last directory you were in, use:
cd -
This command is a real time-saver when you’re frequently switching between two directories.
2. Go Back to the Home Directory
To quickly return to your home directory, you can use:
cd ~
Or simply:
cd
This is useful when you need to return to your starting point without typing the full path.
3. List Directory Contents in Human-Readable Format
For a more readable format that shows file sizes in human-readable units, use:
ls -lh
This command provides a detailed list of files and directories, including their sizes, making it easier to understand at a glance.
4. Create Parent Directories
When you need to create a directory along with its parent directories, use:
mkdir -p /path/to/directory
This ensures that all necessary parent directories are created, avoiding errors if they don’t already exist.
5. Find Recently Modified Files
To list files sorted by modification time, with the most recently modified files at the top, use:
ls -lt
This is particularly useful for quickly identifying the most recent changes in a directory.
6. Monitor Command Output
To run a command repeatedly and monitor its output, use:
watch -n 1 'command'
This command is great for keeping an eye on system metrics or any other output that changes over time.
7. Search Command History
Press Ctrl + r
and start typing to search through your command history.
This interactive search allows you to quickly find and reuse previous commands without having to retype them.
8. Extract Compressed Files
To extract files from a tar archive, use:
tar -xvf archive.tar
This command extracts the contents of the archive, making it easy to access the files within.
9. Check Disk Usage
To display the disk usage of files and directories in the current directory, use:
du -sh *
This provides a summary of disk usage, helping you identify which files and directories are taking up the most space.
10. Navigate Long Commands Efficiently
If you’re typing a lengthy command and realize you need to modify something at the start, use these shortcuts:
- Press
Ctrl + A
to jump to the beginning of the line. - Press
Ctrl + E
to jump to the end of the line.
These shortcuts save time compared to manually pressing the arrow keys repeatedly.
Conclusion
These Linux command tricks are designed to help you navigate and manage your system more effectively. Whether you’re switching directories, managing files, or optimizing workflows, these tips will save you time and effort.