July 20, 2023

Commands and shortcuts I use the most 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 . -mtime 0

to print all files modified in the last 24 hours.

$ 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 accompanied with the names of files modified (i.e. log –oneline –name-only -1 HEAD).

$ apropos keyword

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.

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

$ fc -1

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

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

✍✍✍✍✍✍✍✍✍✍✍✍✍✍

I do self-funded research and I'm writing a book.

> What's the book about?

About technologies and agency.

Meaning, technologies can foster agency. No doubt. But I am also asking:

Can usage of technologies give us a sense of empowerment while in fact undermining our abilities?

I posted a summary of the prologue on the homepage: https://yctct.com/

✍✍✍✍✍✍✍✍✍✍✍✍✍✍


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