Nifty Linux Commands


Some commands I wish I knew from back in the day. I thought I would share.

  1. Switch to the last directory: Suppose you end up in a long directory path and then you move to another directory in a totally different path. And then you realize that you have to go back to the previous directory you were in. In this case, all you need to do is to type this command: cd –
  2. Run a command that you had used in the past: Imagine a situation where you used a long command couple of minutes/hours ago and you have to use it again. Problem is that you cannot remember the exact command anymore. Reverse search is your saviour here. You can search for the command in the history using a search term. Just use the keys ctrl+r to initiate reverse search and type some part of the command. It will look up into the history and will show you the commands that match the search term
  3. Move to the beginning or end of a long command line: ctrl + a and ctrl + e
  4. Read long files without opening them: less path_to_file
  5. Reuse the argument from the previous command line: command (!$). Ex. :> mkdir test and :> cd !$
  6. Reuse the previous command in the current command (!!). Ex. :> pacman -Syu :> sudo !!
  7. Search and list a background process: ps -ef | grep vlc
  8. Kill a zombie thread or process that refuse to die: kill -9 vlc
  9. Empty a large file without deleting it: > filename
  10. Find files containing a particular text: grep -Pri searchTerm Path_to_directory
  11. View the history of commands typed earlier: history followed by !# where # is the index of the command you want to run. If you also would like to see a time stamp on the history command, add the following to your .bashrc file: export HISTTIMEFORMAT=”%d/%m/%y %T “.
  12. Find the right command: Use apropos like so :> apropos “text”. For example :> apropos “list directory”. on my Arch Linux, it always returns “nothing appropriate”. To fix this run sudo mandb

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Website Powered by WordPress.com.

Up ↑

%d bloggers like this: