The terminal of UNIX based operating systems is insanely powerful, hence owning this power takes a lifetime. While learning it there are few tips and tricks that you can keep handy which will make you super productive. This document would be forever in Work in Progress mode and as I keep coming across any tips, I’ll be documenting them here.
- Sometimes we need super-user (
sudo) privilege to run a command, but we realize it only after executing it. Hence when we try to run the command again we either rewrite the entire command or use the up arrow key to get it again then edit it. But there is a simple way to do it. Use
sudo !!to run the previously executed command with
- How to list the last three newly created files in a directory?
ls -ltr | tail -3
- How to send last three newly created files in a directory to a server?
scp `ls -ltr | tail -3` username@<ip>:<location>
?variable stores the exit status code of last executed unix or linux shell command. If the value of
?is 0 then it means that the last command executed successfully, but it it’s non-zero, that means there was some error.
- Compress a directory:
tar -cv /path/to/dir | gzip --fast newFileName.tar.gz(fast compression)
tar -cv /path/to/dir | gzip --best newFileName.tar.gz(best compression)
pigzis a parallel implementation of
gzipis much faster when compressing multiple number of files:
tar -cv source-dir/ | pigz --best > target-file-name.tar.gz