TIL: Be a Doer of The Word

Today I learned

A new initiative to record what I have learned in an attempt to apply it in my life.

Linux Command Line

In studying for the lpic-1 I am learning lot's of little things that I didn't know...

help

Bash has a help function called help.

$ help while
while: while COMMANDS; do COMMANDS; done
    Execute commands as long as a test succeeds.

    Expand and execute COMMANDS as long as the final command in the
    `while' COMMANDS has an exit status of zero.

    Exit Status:
    Returns the status of the last command executed.

This will be very handy, wish I knew about years ago.

apropos

This is a program I had never heard of. You can use it to try and find a program that will do what you want.

$ apropos unzip
bunzip2 (1)          - a block-sorting file compressor, v1.0.8
funzip (1)           - filter for extracting from a ZIP archive in a pipe
gunzip (1)           - compress or expand files
preunzip (1)         - prefix delta compressor for Aspell
unzip (1)            - list, test and extract compressed files in a ZIP archive
unzipsfx (1)         - self-extracting stub for prepending to ZIP archives

file

This program will give you more info on a file.

$ file log.tar.gz 
log.tar.gz: gzip compressed data, last modified: Sun Feb 14 19:43:28 2016, from Unix, original size modulo 2^32 2129920

stat

Gives file or file system status.

$ stat log.tar.gz 
  File: log.tar.gz
  Size: 130340      Blocks: 256        IO Block: 4096   regular file
Device: fc03h/64515d    Inode: 135200      Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1000/     pat)   Gid: ( 1000/     pat)
Access: 2021-09-03 09:23:02.957218348 -0600
Modify: 2021-09-03 09:12:24.709826533 -0600
Change: 2021-09-03 09:12:24.709826533 -0600
 Birth: 2021-09-03 09:12:24.709826533 -0600

cd

cd -

This one was mind blowing and another one of those ones that would have been good to know 10 years ago. This one moves back and fourth between current and previous directory

pat@pat-Standard-PC-Q35-ICH9-2009:~/commandlinebasics/Exercise Files$ cd -
/home/pat
pat@pat-Standard-PC-Q35-ICH9-2009:~$ cd -
/home/pat/commandlinebasics/Exercise Files
pat@pat-Standard-PC-Q35-ICH9-2009:~/commandlinebasics/Exercise Files$

sudo

The sudo -k will invalidate any cached credentials, the means the password will need to be entered again on the next invocation. Wont use it often but good to know.

sort

Haven't used this one much (ever?). This example sorts on column 2, numerically.

$ sort -k2 -n simple_data.txt
Name    ID      Team
Scott   314     Purple
Anne    556     Green
Miguel  671     Green
Ananti  991     Orange
Wes     1337    Orange
Jian    3127    Purple

sort -u only prints unique lines

Grand Finale

ip

And to top it all off.

ip a

Shows the ip address for all the networking adapters on the system. I have been using ip addr show for years! So many wasted bits *smh.

So much left to learn

There is always so much to learn. Maybe I should dedicate 5-10 min a day to reading man pages. So many options that would have saved me so much typing over the years. It will be great to learn some of these "little" tricks from the pro training.