WordPress.com jetpack

Thursday, July 11, 2019

Linux Trickery Shortcuts

Double pipe || between two commands - if the first command fails, then second will execute.

<command-1> || <command-2>

Double && between two commands - the second command would run only when first succeeds.

<command-1> && <command-2>


cd joininternet || mkdir joininternet && cd joininternet

The above command changes directory to join-internet, and suppose if does directory does not exists, then the command would fail, but as we have provided another after ||, then the second would execute and create the directory join-internet. After that, as change directory command is also given after &&, it would also get completed. Finally, we reach to directory join-internet.

Command History - If we press up arrow keyboard key, the lastest command executed in the history gets displayed.

Last command argument with !$

mkdir join-internet

cd !$  Here, i$ = join-internet

cd join-internet || mkdir !$ && cd !$

!v would look in the history for a command which starts with letter 'v'. Similarly, if we provide !?75, it would look for 75, anywhere as an argument or its part.

date --date "75 days ago"

No comments:

Post a Comment