Unlocking Linux CLI Mastery Essential Tips and Tricks
-
A single dash normally means a short name of the flag. E.g
ls -a -
A double dash is passed to express a long flag. Ex:
ls --all -
A single dash can also handle multiple short flags passed into it. Ex.
ls -alR -
Use the command
less <filename>to output less information of a file -
Use the command
more <filenameto output more information if a file -
Use key
Ctrl + Ato go to the beginning of any written text in bash -
Use key
ctrl+ Eto go to the end of any written text in bash that is currently present. -
Use key
ctrl +dto send a sign to terminate, use the commandkill -lto see all commands that can be used to kill, terminate, interrupt processes, and many more. -
When we press key
ctrl +rthen it will help us to go through history and find the matching last command. If we want to go through all matching command then keep pressingctrl +r -
tailhelps us to see the last 10 lines of content from the source and the head can show us the first 10 lines. Seeing 10 lines is configurable and we can see the-fflag to not let the command exit and just keep showing us the update. -
mkdir -p /nested/folder/can/be/createdmkdir is used to create a folder but if we try to create nested then we will see some error just pass-pflag to make a nested folder in a single line of command -
There’s a cli lib
trashwhich can help us to manage trash via CLI. For example:trash-put filename -
tar -cf pkg.tar package.json package-lock.jsonto archive filepkg.tarhere can be any desired output filename and the rest of the files after it is to be archived inside it. To compress it change flag-cfto-cfzand also change the extension of the output filename to.tar.gz. This will actually compress our file and we can see some difference in size. -
To unarchive any tar file just do this
tar -xzf filena.tar.gz destinationFolder.