# Linux Productivity: 7 Commands to Save Hours
 
For years, Linux power-users have mastered the command line—but many still perform tasks the hard way. This entry covers seven powerful commands to enhance productivity and reduce repetitive keystrokes.
 
## 1. Repeating a Command with sudo
 
Forgot to add sudo? Instead of retyping your entire command, execute:
 
    sudo !!
 
This command repeats your last command, this time prefixed with sudo. It is a fast solution for permission errors.
 
## 2. Opening a Recently Created File in vim
 
After creating a file, open it immediately in vim without retyping its name:
 
    vim !$
 
Here, !$ represents the last word of the previous command (the filename), allowing for quick file editing.
 
## 3. Searching the Command History
 
When you can’t recall a previously used command, use the reverse search feature:
 
- Press **Ctrl + R**
- Begin typing part of the command
 
This interactive search scans the full shell history, facilitating efficient retrieval.
 
## 4. Correcting a Typo in a Long Command
 
If a lengthy command contains a typo, type:
 
    fc
 
This command opens the last command in your default editor. After making corrections, save and exit to re-execute.
 
## 5. Navigating Between Folders Efficiently
 
Use stack-based directory navigation to quickly switch between paths:
 
- To save the current location and change directories, use:
 
      pushd /some/path
 
- To return to the previous directory, use:
 
      popd
 
This avoids repeatedly typing long paths.
 
## 6. Displaying the Folder Structure
 
Visualize the directory structure with:
 
    tree -L 2
 
This command displays a tree representation of the directory up to two levels deep, offering a cleaner alternative to ls.
 
## 7. Returning to the Last Folder
 
To switch back to the previous directory, type:
 
    cd -
 
This command toggles to the last directory quickly and efficiently.
 
## Bonus: Simplifying grep with File Input
 
Avoid the inefficient pattern of piping file content to grep:
 
    cat file | grep something
 
Instead, use:
 
    grep something file
 
This approach is more direct and concise.
 
#tags: #Linux #ShellCommands #Productivity #CommandLine #TimeSaving

Linux-Blog-Overview