One Minute Linux Tricks (1)

Switch From Vim Editor To Command Line

  • Save the file in Vim
  • Exit and troubleshooting
  • Reopen file file in Vim and continue
# Open file for editing
$ vim test.text
Press "CTRL+Z" in Vim[2]+ Stopped vim test.text
# Troubleshooting and kill the hot process
$ kill -9 5678

[1]- Killed bash sleep.sh
# Now type fg
$ fg
You should be back in Vim

Use htop Instead of top

  • You can scroll the process list vertically and horizontally to see all process and complete command line parameters.
  • CPU/MEM/SWAP are presented in a better visual way
  • It is faster
  • Easier way of killing a process, F9 key then select the process
  • Easier way of renicing a process
Snapshot of htop command

Recover Deleted Files With /proc File Descriptor

# I have a file open for reading in one terminal
(T1 /tmp) $ less test.txt
This is a test file, I will accidentally delete this file, but leave the file handler open,
and recover it
test.txt (END)
(T2 /tmp) $ rm test.txt(T2 /tmp) $ lsof -c less | grep test.txt
less 8411 root 4r REG 202,1 100 1450845 /tmp/test.txt (deleted)
$ ls -l /proc/8411/fd/
total 0
lrwx------ 1 root root 64 Apr 15 17:55 0 -> /dev/pts/1
lrwx------ 1 root root 64 Apr 15 17:55 1 -> /dev/pts/1
lrwx------ 1 root root 64 Apr 15 17:55 2 -> /dev/pts/1
lr-x------ 1 root root 64 Apr 15 17:55 3 -> /dev/tty
lr-x------ 1 root root 64 Apr 15 17:55 4 -> /tmp/test.txt (deleted)
$ cp /proc/8411/fd/4 /tmp/test.txt_recovered
$ cat /tmp/test.txt_recovered
This is a test file, I will accidentally delete this file, but leave the file handler open,
and recover it

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store