July 20, 2023

Commands and shortcuts I use the most in the Shell (the Terminal)

Scrolls past shortcuts to see the commands I use.

Shortcuts I use in the Shell (the Terminal)

I use the shortcut Ctrl + R to retrieve commands from history (i.e. commands I previously typed). For example instead of typing $ cd /home/user/mybook to go to the directory where I do my work, I press the keys Ctrl + R followed by the keystrokes m and y which is enough for cd /home/user/mybook to show up in the search result of the query, then I press return (“Enter”) to execute the command.

Same to edit my to-do list: instead of typing $ vi /home/user/todo.txt to open the file todo.txt, I press the keys Ctrl + R followed by the keystrokes t, o and d, then I press return, or instead of typing $ git ci --amend --no-edit to add changes to the last commit, I press the keys Ctrl + R followed by the keystrokes a, m and e, then I press return.

Not all commands I can reuse verbatim though. If I use the shortcut Ctrl + R to retrieve a command, but that I have to edit the command, I type Ctrl + U to paste the command from history to the command line and then use the following shortcuts to edit the command:

Ctrl + A  # move cursor at the beginning of the line
Ctrl + E  # move cursor at the end of the line
Ctrl + F  # move cursor forward one character
Ctrl + B  # move cursor backward one character
Alt  + F  # move cursor forward one word
Alt  + B  # move cursor backward one word
Alt  + D  # delete text from cursor to the end of the word
Ctrl + D  # delete character at the cursor location
Ctrl + K  # delete text from cursor to the end of the line
Ctrl + U  # delete text from cursor to the beginning of the line
Alt  + backspace # delete text from the cursor to the beginning of the current word, or previous word

(There are other existing shortcuts which I have not managed to adopt. See the list of all shortcuts you can use to edit on the command line).

Sometimes the command I want to retrieve is one I have just use. In that case, I don’t use Ctrl + R but use the shortcut Ctrl + P to circle through the last commands ran (Ctrl + N goes the other way around in case you circled back to fast and missed the one you sought).

Some other times, the command I seek is no longer in history, thus can’t be retrieved via Ctrl + R (or P). If that is a command that is difficult to memorise, I might create an alias.

Before we move onto seeing the commands I use in the shell, let me list some other shortcuts I use:

menu + b # with MATE
menu + t # with Xfce

to open a tab in the shell.

menu + l # with MATE

to close a tab in the shell.

shift + page up/down

to move up/down one screen in the shell.

Alt + Shift

to shift between keyboard layouts (that is a customized shortcut).

Commands I regularly use in the Shell (the Terminal)

Now, some of the commands I use:

$ time pandoc -o file.pdf --pdf-engine=xelatex --toc file.md --trace --lua-filter=count-para.lua  -V documentclass=article -V fontsize=12pt && atril file.pdf 

which I retrieve with the shortcut Ctrl + R to convert the Markdown file I am working on into a pdf, and open it straight away with a pdf viewier (more about pandoc).

$ pandoc file.md --lua-filter=wordcount.lua

to count words of a Markdown file ignoring Markdown syntax (more about counting words with a lua script). Otherwise:

$ sed -i 's/regex/replacement/g' file

to replace an expression through a file without opening it (more about sed).

$ sed -i 's/regex/replacement/g' *.md

to replace an expression through all Markdown files in the current directory, a repository for example.

$ find path/to/directory -iname regex -type f

to find a file in a given directory (more about find).

$ find . -mtime 0

to print all files modified in the last 24 hours.

$ git ci -S -am "Your commit message"

to add files and commit at once; ci is an alias for commit (more about git alias). -S signs commits with my GPG keypair (more about signing commits with GPG)

$ git last

an alias, to show the last commit accompanied with the names of files modified (i.e. log –oneline –name-only -1 HEAD).

$ apropos -a keyword1 keyword2

to look for and discover (new) utilities or programmes (more about apropos).

$ man nameofaprogramme

to display the manual of a programme to figure how to write up a command, for example.

$ grep pattern files

where pattern is a regex or simply a keyword which I am looking for through a bunch of files (more about grep).

$ command | grep pattern

to grep the output of various commands.

$ shutdown now

to shutdown my computer.

$ reboot

to reboot my computer.

$ ping www.yctct.com

to check whether I am connected to the internet.

$ !!:q > ~/wiki/new_wiki.md

to populate a newly created wiki file with the last command I ran.

$ TZ=Asia/Singapore date 

to display the time of a time zone, or:

$ tzselect

if I don’t know the TZ value of the time zone I need to display the time of (more about the utility date).

$ date --date='TZ="Asia/Singapore" 17:00 next Fri' 

to display (my) local time given the time and date of another time zone (to set up calls). I need to replace this command I can never remember with a function.

$ sudo apt upgrade && sudo apt update 

to update my distribution.

$ umount /media/user/usb_device_name

to unmount a USB device. I still have not figured how to power off the device from the command line; I do this from the GUI.

$ less file

to display and browse a file without opening it (more about less); also to pipe output through less.

$ cat file

to print content of a file in the shell (usually one of my short wiki I have locally).

$ backintime backup --profile-id 1

to back up ~/home/ (more about Back In Time).

$ backtime last-snapshot

to check that the last backup process went through.

$ history | less

to look for a command I previously ran.

$ fc -1

to edit and reuse the last command

$ fc -l

to find the number of the last command I want to reuse.

$ nvlc path/to/audio/file

to listen to radio programmes, also $ cvlc path/to/audio/file.

$ df -h 

to check how much space is left on my drive.

$ ncdu -x /

to check what takes space on /; see https://yctct.com/check-disk-space.

$ ende word
$ frde word
$ defr word
$ deen word
$ enfr word
$ fren word
$ de word
$ eng word
$ fr word
$ th word
$ ety word
etc..

to check for definition, translation, synonymes or the etymology of words with sdcv; see https://yctct.com/tagged/sdcv. All of the above commands are aliases.

$ queue -r # queue is an alias

to send emails queued while offline (see https://yctct.com/msmtp-queue)

$ mbsync -v email_account

to download new emails from my mail server for a specific email account.


Feedback are more than welcome at https://yctct.com/contact.


command-line interface (cli) gnu linux trisquel office applications personal computing text processing wiki shell literacy

No affiliate links, no analytics, no tracking, no cookies. This work © 2016-2024 by yctct is licensed under CC BY-ND 4.0 .   about me   contact me   all entries & tags   FAQ   GPG public key

GPG fingerprint: 2E0F FB60 7FEF 11D0 FB45 4DDC E979 E52A 7036 7A88