Unix Command Line

Going through this guide: GitHub - jlevy/the-art-of-command-line: Master the command line, in one page and going to take note on notable thing as I go.

Tips:

  1. Use curl cheat.sh/<command> for a cheat sheet on whatever command you’re not sure about.
  2. awk 202211260214 is extremely useful for programmatically processing / applying some sort of function to a file line by line.
  3. less 202211260215 is a pager, which makes is to that you don’t have to load a file completely into memory to read it (which is what Vim does). Most of Vim commands still apply, with ctrl-f to go one page forward and ctrl-b to go one page backward.
  4. Globbing is important. Reference link:
  5. Bash job management 202211260219
    • appending an & to a process will make it run while still allowing you to enter input into the console.
    • fg and bg will move the most recent process into the foreground or background respectively.
    • If you want to kill a job with a certain id (found in jobs, for example), then use kill %{job_id}.
    • Awk 202211260214
    • For a quick summary of disk usage: du -hs *
  6. Less 202211260215 follow-mode, to see how a file grows:
    • less +F <file>
  7. Regular expressions 202211260228 (grep / egrep):
    • Flags to be aware of:
      • -i: ignore case
      • -v: Invert match. Select lines that don’t match the specified patterns
      • -o: prints only the matching part of the line
      • -A, -B, -C, number of trailing lines of context before/after/before+after each match.
  8. Awk 202211260214 can be used with sed for text manipulation.
  9. Last one for today! What do the columns in ls -l mean?
    • file mode, number of links, owner name, group name, number of bytes in the file, abbreviated month, day-of-month file was last modified, hour file last modified, minute file last modified, and the pathname.
      • The file mode printed under the -l option consists of the entry type and the permissions. The entry type character describes the type of file, as follows:
         -     Regular file.
         b     Block special file.
         c     Character special file.
         d     Directory.
         l     Symbolic link.
         p     FIFO.
         s     Socket.
         w     Whiteout.
      • [Note: the section above isn’t super helpful. I don’t see a situation where this will be very useful, so I’m not going to view it for now.]
  10. Advantages vs. disadvantages of soft links (symlinks)
    • Create a soft link: ln -s file1 link1
    • While useful, there are some limitations to what hard links can do. For starters, they can only be created for regular files (not directories or special files). Also, a hard link cannot span multiple filesystems. They only work when the new hard link exists on the same filesystem as the original.
    • All of this sounds great, but there are some drawbacks to using a soft link. The biggest concern is data loss and data confusion. If the original file is deleted, the soft link is broken. This situation is referred to as a dangling soft link. If you were to create a new file with the same name as the original, your dangling soft link is no longer dangling at all. It points to the new file created, whether this was your intention or not, so be sure to keep this in mind.
  11. Things to look at in the future: chown, chmod
    • for filesystem management: df, mount, fdisk, mkfs, lsblk
  12. Keybindings in bash (and also zsh): These are all emacs keybindings!
    1. Ctrl-w to delete the last word
    2. Ctrl-u to delete content from cursor to start of the line. Ctrl-k to kill till end of line.
    3. Alt-b to move back one word, and alt-f to move forward.
    4. Ctrl-a to move cursor to beginning of line.
    5. Ctrl-e to move cursor to end of line.
    6. Ctrl-l to kill the screen.
  13. If you are halfway through typing a command but change your mind, hit alt-# to add a # at the beginning and enter it as a comment (or use ctrl-a, #, enter). You can then return to it later via command history.

  14. uid: 202211260212 tags: #software-engineering

Date
February 22, 2023