Skip to content

Instantly share code, notes, and snippets.

@tommyvdv
Last active June 26, 2018 10:36
Show Gist options
  • Save tommyvdv/9b576568815ba125fdd682b3848c46ee to your computer and use it in GitHub Desktop.
Save tommyvdv/9b576568815ba125fdd682b3848c46ee to your computer and use it in GitHub Desktop.
useful linux commands

Far from a comprehensive list.

Switching back and forth between directories using cd -;

$ cd ~/Downloads
$ cd ~/Documents
$ cd -

Use cd to enter directory Downloads then Document and then return to directory Downloads.

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 and Documents directories. Use cat to print the contents of example1.log and example2.log to console. Use cat 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 use vim 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. Use F to return to "watching" the file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment