Far from a comprehensive list.
Switching back and forth between directories using cd -
;
$ cd ~/Downloads
$ cd ~/Documents
$ cd -
Use
cd
to enter directoryDownloads
thenDocument
and then return to directoryDownloads
.
Basic globbing to ls multiple directories or cat multiple files;
$ ls -l ~/{Downloads,Documents}
$ cat /var/log/{example1,example2}.log
$ cat /var/log/example*
Verify contents of
Downloads
andDocuments
directories. Usecat
to print the contents ofexample1.log
andexample2.log
to console. Usecat
to print the contents of all files matching/var/log/example*
to console.
Repeat last command using !!
;
$ systemctl status httpd
$ sudo !!
Run a command, then realise you need
sudo
and repeat it appending the previous command to it.
Use last argument using !$
;
$ ls -l /var/log/example.log
$ vim !$
Confirm a file exists using
ls
, then usevim
to open the last argument of the previous command.
Using less to display colors;
$ less -r /var/log/syslog
$ less --raw-control-chars /var/log/syslog
Will, among others, display color instead of escaped control chars.
Using less to tail;
$ less +F /var/log/syslog
Roughly resembles
tail -f /var/log/syslog
but allows the user to start navigating/searching/.. at any time. UseF
to return to "watching" the file.