July 20, 2023

Commands and 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

to open a tab in the shell.

menu + l

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).

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.

$ films 

an alias, to display all films I have on my laptop (i.e. $ alias films=‘find /home/user/Downloads/ -name’'‘*[avi,mkv,mp4]’'’ -size +500M|less’).

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

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

$ find /home/user/Downloads/* -maxdepth 1 -mtime 0

to display all files downloaded in the last 24 hours (more about the option mtime).

$ git ci -am "Your commit message"

to add and commit at once; ci is an alias for commit (more about git alias).

$ git last

an alias, to show the last commit (i.e. log -1 HEAD).

$ git log --pretty=oneline

to show log of commits as one liners.

$ apropos keyword

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

$ whatis nameofaprogramme

to check what a programme I read about and don’t know of does.

$ man nameofaprogramme

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

$ keepassxc-cli clip path/to/my_password_database.kdbx password_entry_name

to copy an entry’s password to the clipboard.

$ 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).

$ ls -lt | head n -15

to display the last 15 (or else) modified files or directories in the current working directory.

$ shutdown now

to shutdown my computer.

$ reboot

to reboot my computer.

$ ping www.trisquel.info

to check whether I am connected to the internet.

$ touch /home/user/the_repository_of_this_website/drafts/name_of_a_draft.md

to create the file of a draft I will write later.

$ 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).

$ sudo apt upgrade && sudo apt update 

to update my distribution.

$ umount /media/user/usb_device_name

to unmount (“eject”) a USB device.

$ 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

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.

$ 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.

Feedback are more than welcome at yctct at domain name. I am curious to know which commands make your day easier.

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. © 2016-2023 yctct.com. Content is licensed under CC BY-NC-SA 4.0 .